您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit长数组的数组比较失败时的错误输出
发布时间:2021-09-14 16:19:04编辑:雪饮阅读()
当生成的输出很长而难以阅读时,PHPUnit 将对其进行分割,并在每个差异附近提供少数几行上下文信息。
LongArrayDiffTest.php:
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class LongArrayDiffTest extends TestCase
{
public function testEquality(): void
{
$this->assertSame(
[0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 1, 2, 3, 4, 5, 6],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 33, 4, 5, 6]
);
}
}
use PHPUnit\Framework\TestCase;
final class LongArrayDiffTest extends TestCase
{
public function testEquality(): void
{
$this->assertSame(
[0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 1, 2, 3, 4, 5, 6],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 33, 4, 5, 6]
);
}
}
运行结果如:
C:\Users\Administrator>D:\phpstudy_pro\Extensions\php\php7.3.4nts\php.exe D:\phpstudy_pro\Extensions\php\php7.3.4nts\phpunit-9.5.8.phar C:\Users\Administrator\PhpstormProjects\untitled\LongArrayDiffTest.php
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
F 1 / 1 (100%)
Time: 00:00.004, Memory: 20.00 MB
There was 1 failure:
1) LongArrayDiffTest::testEquality
Failed asserting that two arrays are identical.
--- Expected
+++ Actual
@@ @@
5 => 0
6 => 0
7 => 0
- 8 => 7
+ 8 => 0
9 => 0
10 => 0
11 => 0
12 => 1
13 => 2
- 14 => 3
+ 14 => 33
15 => 4
16 => 5
17 => 6
)
C:\Users\Administrator\PhpstormProjects\untitled\LongArrayDiffTest.php:10
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
这里数组比较虽然只是一个断言,但是差异有两处,所以两个差异的地方都有被上下文标注出来的。
关键字词:phpunit,长数组,差异