您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit断言-assertIsCallable
发布时间:2021-10-03 15:36:46编辑:雪饮阅读()
assertIsCallable断言用来断言一个字符串(做为如方法名)是否可以调用。
类型是 callable。
CallableTest.php:
<?php
use PHPUnit\Framework\TestCase;
function my_callback_function() {
echo 'hello world!';
}
class CallableTest extends TestCase
{
public function testFailure()
{
$this->assertIsCallable(null);
}
public function testSuccess()
{
$this->assertIsCallable('my_callback_function');
}
}
use PHPUnit\Framework\TestCase;
function my_callback_function() {
echo 'hello world!';
}
class CallableTest extends TestCase
{
public function testFailure()
{
$this->assertIsCallable(null);
}
public function testSuccess()
{
$this->assertIsCallable('my_callback_function');
}
}
运行结果如:
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\CallableTest.php
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
F. 2 / 2 (100%)
Time: 00:00.008, Memory: 6.00 MB
There was 1 failure:
1) CallableTest::testFailure
Failed asserting that null is of type "callable".
C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\CallableTest.php:10
FAILURES!
Tests: 2, Assertions: 2, Failures: 1.
关键字词:phpunit,assertIsCallable