From 64aeb844e191cf33672617e2c3e370f8acbc9455 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 24 Feb 2014 14:33:03 -0800 Subject: [PATCH] HR-216 - CiviReportTestCase - Add more output for diagnosing errors --- tests/phpunit/CiviTest/CiviReportTestCase.php | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) 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; + } } -- 2.25.1