您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit断言-assertIsString
发布时间:2021-10-04 15:20:57编辑:雪饮阅读()
assertIsString断言是为了断言一个实际值的数据类型是否是string字符串类型。
StringTest.php:
<?php
use PHPUnit\Framework\TestCase;
class StringTest extends TestCase
{
public function testFailure()
{
$this->assertIsString(null);
}
public function testOne()
{
$this->assertIsString(1633314632300);
}
public function testTwo()
{
$this->assertIsString("http://localhost/1633314632300/.local.index.m3u8");
}
public function testThree()
{
$this->assertIsString("1633314632300");
}
}
use PHPUnit\Framework\TestCase;
class StringTest extends TestCase
{
public function testFailure()
{
$this->assertIsString(null);
}
public function testOne()
{
$this->assertIsString(1633314632300);
}
public function testTwo()
{
$this->assertIsString("http://localhost/1633314632300/.local.index.m3u8");
}
public function testThree()
{
$this->assertIsString("1633314632300");
}
}
运行结果:
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\StringTest.php
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
FF.. 4 / 4 (100%)
Time: 00:00.007, Memory: 6.00 MB
There were 2 failures:
1) StringTest::testFailure
Failed asserting that null is of type "string".
C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\StringTest.php:8
2) StringTest::testOne
Failed asserting that 1633314632300 is of type "string".
C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\StringTest.php:12
FAILURES!
Tests: 4, Assertions: 4, Failures: 2.
关键字词:phpunit,assertIsString