phpUnit中assertEquals
assertEquals
assertEquals(mixed $expected, mixed $actual[, string $message = ''])
<?php
require_once dirname(dirname(__FILE__)) . '\vendor\autoload.php';
use PHPUnit\Framework\TestCase;
class MyClassTest extends TestCase{
/**
* @test
*/
public function one()
{
$this->assertTrue(true, '当条件为不为真报这条错误信息');
return $one ='one';
}
/**
* @test
*/
public function two()
{
$this->assertTrue(true, '当条件为不为真报这条错误信息');
return $two ='two';
}
/**
* @test
* @depends one
* @depends two
*/
public function three($one, $two)
{
$arr_expected_1 = ['one', 'two'];
$arr_expected_2 = ['one'];
$arr_actual = [$one, $two];
$this->assertEquals($arr_expected_1, $arr_actual, '当期望的数组和实际的数组不相等时报这条信息');
$this->assertEquals($arr_expected_2, $arr_actual, '当期望的数组和实际的数组不相等时报这条信息');
}
}
PHPUnit 6.5.3 by Sebastian Bergmann and contributors.
Runtime: PHP 7.2.1 with Xdebug 2.7.0
..F 3 / 3 (100%)
Time: 608 ms, Memory: 8.00MB
There was 1 failure:
1) MyClassTest::three
当期望的数组和实际的数组不相等时报这条信息
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
Array (
0 => 'one'
+ 1 => 'two'
D:\yanjing\workspace\study_test\php\MyClass.php:39
FAILURES!
Tests: 3, Assertions: 4, Failures: 1.
这是我的签名