您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit断言-assertIsResource
发布时间:2021-10-03 23:17:24编辑:雪饮阅读()
assertIsResource断言主要断言一个实际数据是否是资料类型resource。
ResourceTest.php:
<?php
use PHPUnit\Framework\TestCase;
class ResourceTest extends TestCase
{
public function testFailure()
{
$this->assertIsResource(null);
}
public function testSuccess()
{
$myfile = fopen(dirname(__FILE__)."/testfile.txt", "w");
$this->assertIsResource($myfile);
}
}
use PHPUnit\Framework\TestCase;
class ResourceTest extends TestCase
{
public function testFailure()
{
$this->assertIsResource(null);
}
public function testSuccess()
{
$myfile = fopen(dirname(__FILE__)."/testfile.txt", "w");
$this->assertIsResource($myfile);
}
}
运行结果:
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\ResourceTest.php
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
F. 2 / 2 (100%)
Time: 00:00.011, Memory: 6.00 MB
There was 1 failure:
1) ResourceTest::testFailure
Failed asserting that null is of type "resource".
C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\ResourceTest.php:7
FAILURES!
Tests: 2, Assertions: 2, Failures: 1.
关键字词:phpunit,assertIsResource