您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit断言assertCount
发布时间:2021-10-01 21:31:17编辑:雪饮阅读()
assertCount主要是断言一个堆如数组的元素数量为某个值,若不是该值,则断言失败。
CountTest.php:
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class CountTest extends TestCase
{
public function testFailure(): void
{
$this->assertCount(0, ['foo']);
}
public function testSuccess(): void
{
$this->assertCount(1, ['foo']);
}
}
use PHPUnit\Framework\TestCase;
final class CountTest extends TestCase
{
public function testFailure(): void
{
$this->assertCount(0, ['foo']);
}
public function testSuccess(): void
{
$this->assertCount(1, ['foo']);
}
}
运行结果:
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\CountTest.php
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
F. 2 / 2 (100%)
Time: 00:00.009, Memory: 4.00 MB
There was 1 failure:
1) CountTest::testFailure
Failed asserting that actual size 1 matches expected size 0.
C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\CountTest.php:8
FAILURES!
Tests: 2, Assertions: 2, Failures: 1.
关键字词:phpunit,assertCount
相关文章
- phpunit断言assertContainsOnlyInstancesOf
- phpunit断言-assertContainsOnly
- phpunit断言assertStringContainsStringIgnoringCase
- phpunit断言-assertStringContainsString
- phpunit断言-assertContains
- phpunit断言assertClassHasStaticAttribute
- phpunit断言assertClassHasAttribute
- phpunit断言-assertArrayHasKey
- phpunit指明应当不覆盖任何方法的测试-@coversNothing
- phpunit平面数据格式flat的多表模式及多表状态断言