您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit断言-assertContainsOnly
发布时间:2021-10-01 19:15:34编辑:雪饮阅读()
assertContainsOnly断言也是断言包含的,但是它断言的是包含某个类型而不是包含某个值,并且是仅仅包含某个类型,不能有其它类型时候才算是断言成功。
ContainsOnlyTest.php:
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class ContainsOnlyTest extends TestCase
{
public function testFailure(): void
{
$this->assertContainsOnly('string', ['1', '2', 3]);
}
public function testSuccess(): void
{
$this->assertContainsOnly('string', ['1', '2', '3']);
}
}
use PHPUnit\Framework\TestCase;
final class ContainsOnlyTest extends TestCase
{
public function testFailure(): void
{
$this->assertContainsOnly('string', ['1', '2', 3]);
}
public function testSuccess(): void
{
$this->assertContainsOnly('string', ['1', '2', '3']);
}
}
运行结果:
C:\Users\Administrator>D:\phpstudy_pro\Extensions\php\php7.3.4nts\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\ContainsOnlyTest.php
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
F. 2 / 2 (100%)
Time: 00:00.011, Memory: 4.00 MB
There was 1 failure:
1) ContainsOnlyTest::testFailure
Failed asserting that Array &0 (
0 => '1'
1 => '2'
2 => 3
) contains only values of type "string".
C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\ContainsOnlyTest.php:8
FAILURES!
Tests: 2, Assertions: 2, Failures: 1.
关键字词:phpunit,assertContainsOnly
相关文章
- phpunit断言assertStringContainsStringIgnoringCase
- phpunit断言-assertStringContainsString
- phpunit断言-assertContains
- phpunit断言assertClassHasStaticAttribute
- phpunit断言assertClassHasAttribute
- phpunit断言-assertArrayHasKey
- phpunit指明应当不覆盖任何方法的测试-@coversNothing
- phpunit平面数据格式flat的多表模式及多表状态断言
- phpunit断言单表状态(单表数据与单一数据集的一致性断
- phpunit数据库状态断言(数据是否一致)