您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit断言-assertFileEquals
发布时间:2021-10-02 19:10:51编辑:雪饮阅读()
assertFileEquals断言主要是断言预期与实际的文件引用的文件内容是否相同,相同则断言成功。
FileEqualsTest.php:
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class FileEqualsTest extends TestCase
{
public function testFailure(): void
{
$this->assertFileEquals('D:\phpstudy_pro\Extensions\php\php7.4.3nts\glib-2.dll', 'D:\phpstudy_pro\Extensions\php\php7.4.3nts\gmodule-2.dll');
}
public function testSuccess(): void
{
$this->assertFileEquals('D:\phpstudy_pro\Extensions\php\php7.4.3nts\glib-2.dll', 'D:\phpstudy_pro\Extensions\php\php7.4.3nts\glib-2.dll');
}
}
use PHPUnit\Framework\TestCase;
final class FileEqualsTest extends TestCase
{
public function testFailure(): void
{
$this->assertFileEquals('D:\phpstudy_pro\Extensions\php\php7.4.3nts\glib-2.dll', 'D:\phpstudy_pro\Extensions\php\php7.4.3nts\gmodule-2.dll');
}
public function testSuccess(): void
{
$this->assertFileEquals('D:\phpstudy_pro\Extensions\php\php7.4.3nts\glib-2.dll', 'D:\phpstudy_pro\Extensions\php\php7.4.3nts\glib-2.dll');
}
}
运行结果:
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\FileEqualsTest.php
由于输出过长不宜展示,这里仅显示部分最后几行的输出。
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\FileEqualsTest.php:8
FAILURES!
Tests: 2, Assertions: 6, Failures: 1.
关键字词:phpunit,assertFileEquals