您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit断言-assertStringMatchesFormatFile
发布时间:2021-10-05 17:59:32编辑:雪饮阅读()
assertStringMatchesFormatFile断言同上篇的assertStringMatchesFormat断言,不同的是这里是将format的来源从文件中。
将要用来测试的文件:
C:\Users\Administrator>type D:\software\FormatFactory_5.3.0_PortableSoft\FormatFactoryPortable\Data\1.txt
%i
实例:
StringMatchesFormatFileTest.php:
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class StringMatchesFormatFileTest extends TestCase
{
public function testFailure(): void
{
$this->assertStringMatchesFormatFile('/path/to/expected.txt', 'foo');
}
public function testTwo(): void
{
$this->assertStringMatchesFormatFile('D:\software\FormatFactory_5.3.0_PortableSoft\FormatFactoryPortable\Data\1.txt', '1');
}
public function testThree(): void
{
$this->assertStringMatchesFormatFile('D:\software\FormatFactory_5.3.0_PortableSoft\FormatFactoryPortable\Data\1.txt', 'foo');
}
}
use PHPUnit\Framework\TestCase;
final class StringMatchesFormatFileTest extends TestCase
{
public function testFailure(): void
{
$this->assertStringMatchesFormatFile('/path/to/expected.txt', 'foo');
}
public function testTwo(): void
{
$this->assertStringMatchesFormatFile('D:\software\FormatFactory_5.3.0_PortableSoft\FormatFactoryPortable\Data\1.txt', '1');
}
public function testThree(): void
{
$this->assertStringMatchesFormatFile('D:\software\FormatFactory_5.3.0_PortableSoft\FormatFactoryPortable\Data\1.txt', 'foo');
}
}
运行结果:
C:\Users\Administrator>D:\phpstudy_pro\Extensions\php\php7.4.3nts\php.exe C:\Users\Administrator\PhpstormProjects\untitled\vendor\phpunit\phpunit\phpunit -c C:\Users\Administrator\PhpstormProjects\untitled\organizing\phpunit.xml C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\StringMatchesFormatFileTest.php
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
F.F 3 / 3 (100%)
Time: 00:00.010, Memory: 6.00 MB
There were 2 failures:
1) StringMatchesFormatFileTest::testFailure
Failed asserting that file "/path/to/expected.txt" exists.
C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\StringMatchesFormatFileTest.php:8
2) StringMatchesFormatFileTest::testThree
Failed asserting that string matches format description.
--- Expected
+++ Actual
@@ @@
-%i
+foo
C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\StringMatchesFormatFileTest.php:16
FAILURES!
Tests: 3, Assertions: 5, Failures: 2.
关键字词:phpunit,assertStringMatchesFormatFile
相关文章
- phpunit断言-assertStringMatchesFormat
- phpunit断言-assertMatchesRegularExpression
- phpunit断言-assertObjectHasAttribute
- phpunit断言-assertNull
- phpunit断言-assertNan
- phpunit断言-assertLessThanOrEqual
- phpunit断言-assertLessThan
- phpunit断言-assertJsonStringEqualsJsonString
- phpunit断言-assertJsonStringEqualsJsonFile
- phpunit断言-assertJsonFileEqualsJsonFile