From: Tim Otten Date: Mon, 24 Feb 2014 22:33:03 +0000 (-0800) Subject: HR-216 - CiviReportTestCase - Add more output for diagnosing errors X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=64aeb844e191cf33672617e2c3e370f8acbc9455;p=civicrm-core.git HR-216 - CiviReportTestCase - Add more output for diagnosing errors --- diff --git a/tests/phpunit/CiviTest/CiviReportTestCase.php b/tests/phpunit/CiviTest/CiviReportTestCase.php index f43dc77ab8..33759743d3 100644 --- a/tests/phpunit/CiviTest/CiviReportTestCase.php +++ b/tests/phpunit/CiviTest/CiviReportTestCase.php @@ -106,20 +106,37 @@ class CiviReportTestCase extends CiviUnitTestCase { public function assertCsvArraysEqual($expectedCsvArray, $actualCsvArray) { // TODO provide better debug output + $flatData = "\n===== EXPECTED DATA ====\n" + . $this->flattenCsvArray($expectedCsvArray) + . "\n===== ACTUAL DATA ====\n" + . $this->flattenCsvArray($actualCsvArray); + $this->assertEquals( count($actualCsvArray), count($expectedCsvArray), - 'Arrays have different number of rows; in line ' . __LINE__ + 'Arrays have different number of rows; in line ' . __LINE__ . '; data: ' . $flatData ); foreach ($actualCsvArray as $intKey => $strVal) { + $rowData = var_export(array( + 'expected' => $expectedCsvArray[$intKey], + 'actual' => $actualCsvArray[$intKey], + ), TRUE); $this->assertNotNull($expectedCsvArray[$intKey], 'In line ' . __LINE__); $this->assertEquals( count($actualCsvArray[$intKey]), count($expectedCsvArray[$intKey]), - 'Arrays have different number of columns at row ' . $intKey . '; in line ' . __LINE__ + 'Arrays have different number of columns at row ' . $intKey . '; in line ' . __LINE__. '; data: ' . $rowData ); $this->assertEquals($expectedCsvArray[$intKey], $strVal); } } + + public function flattenCsvArray($rows) { + $result = ''; + foreach ($rows as $row) { + $result .= implode(',', $row) . "\n"; + } + return $result; + } }