2

我通过 CakePHP v2.3 使用 PHPUnit 3.7.10 并运行以下命令:

$this->assertEquals(array('a', 'b', 'c'), array('a', 'c', 'd'));

我得到的只是:

Failed asserting that two arrays are equal.

为什么我没有得到这里概述的差异?http://www.phpunit.de/manual/current/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.assertions.assertEquals.example5

Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
     0 => 'a'
-    1 => 'b'
-    2 => 'c'
+    1 => 'c'
+    2 => 'd'
 )

我错过了什么?

更新。通过 test.php?case=Cache/Engine/PhpUnit&debug=1 调用的测试文件

<?php

class PhpUnitTest extends CakeTestCase {
    public function testDiff() {
        $this->assertEquals(array('a', 'b', 'c'), array('a', 'c', 'd'));
    }
}
4

3 回答 3

0

为我工作:

<?php
class SoTest extends PHPUnit_Framework_TestCase
{
    public function testIt()
    {
        $this->assertEquals(array('a', 'b', 'c'), array('a', 'c', 'd'));
    }
}
?>

输出:

$  phpunit SoTest.php 
PHPUnit 3.7.10 by Sebastian Bergmann.

F

Time: 0 seconds, Memory: 3.00Mb

There was 1 failure:

1) SoTest::testIt
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
     0 => 'a'
-    1 => 'b'
-    2 => 'c'
+    1 => 'c'
+    2 => 'd'
 )

/home/cweiske/SoTest.php:6

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
于 2012-12-30T20:21:40.837 回答
0

您正在浏览器上运行单元测试。--debug当您在 CLI 上使用修饰符运行它时,您将看到预期的结果。您也可以&debug=1在使用 Web 浏览器运行测试时尝试在 url 的末尾添加,但这对我来说并没有奏效很多次。

于 2012-12-30T20:30:03.597 回答
0

这是 CakePHP 2.3 中的一个回归错误。在https://github.com/cakephp/cakephp/commit/659715664d648d9a599002b5a7c3b55505efdcde中修复

对于参考这里是我打开的勾选: http: //cakephp.lighthouseapp.com/projects/42648/tickets/3503-23-suppresses-phpunit-diff-output

于 2013-01-02T15:39:02.560 回答