From 9bdf699c77db6e90c20fb4dfcd5b8bdfc9a3389f Mon Sep 17 00:00:00 2001 From: mattab <matthieu.aubry@gmail.com> Date: Fri, 8 Nov 2013 11:08:15 +1300 Subject: [PATCH] Late static binding needed for plugin tests to override path to expected test output files --- tests/PHPUnit/IntegrationTestCase.php | 54 +++++++++++++-------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/tests/PHPUnit/IntegrationTestCase.php b/tests/PHPUnit/IntegrationTestCase.php index 52372e615a..7e118a95a8 100755 --- a/tests/PHPUnit/IntegrationTestCase.php +++ b/tests/PHPUnit/IntegrationTestCase.php @@ -76,10 +76,10 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase public static function setUpBeforeClass() { - self::_setUpBeforeClass(); + static::_setUpBeforeClass(); if (isset(static::$fixture)) { - self::setupFixture(static::$fixture); + static::setupFixture(static::$fixture); } } @@ -122,14 +122,14 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase try { $fixture->setUp(); } catch (Exception $e) { - self::fail("Failed to setup fixture: " . $e->getMessage() . "\n" . $e->getTraceAsString()); + static::fail("Failed to setup fixture: " . $e->getMessage() . "\n" . $e->getTraceAsString()); } } protected static function teardownFixture($fixture) { if (isset(static::$fixture)) { - self::tearDownFixture(static::$fixture); + static::tearDownFixture(static::$fixture); } $fixture->tearDown(); @@ -153,7 +153,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase $dbName = Config::getInstance()->database['dbname']; } - self::connectWithoutDatabase(); + static::connectWithoutDatabase(); if ($createEmptyDatabase) { DbHelper::dropDatabase(); } @@ -168,7 +168,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase \Piwik\Plugin\Manager::getInstance()->loadPlugins(array()); } catch (Exception $e) { - self::fail("TEST INITIALIZATION FAILED: " . $e->getMessage() . "\n" . $e->getTraceAsString()); + static::fail("TEST INITIALIZATION FAILED: " . $e->getMessage() . "\n" . $e->getTraceAsString()); } include "DataFiles/SearchEngines.php"; @@ -185,7 +185,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase Cache::deleteTrackerCache(); if ($installPlugins === null) $installPlugins = $createEmptyDatabase; - self::installAndLoadPlugins( $installPlugins); + static::installAndLoadPlugins( $installPlugins); $_GET = $_REQUEST = array(); @@ -197,8 +197,8 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase // List of Modules, or Module.Method that should not be called as part of the XML output compare // Usually these modules either return random changing data, or are already tested in specific unit tests. - self::setApiNotToCall(self::$defaultApiNotToCall); - self::setApiToCall(array()); + static::setApiNotToCall(static::$defaultApiNotToCall); + static::setApiToCall(array()); FakeAccess::$superUserLogin = 'superUserLogin'; @@ -208,7 +208,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase public static function tearDownAfterClass() { - self::_tearDownAfterClass(); + static::_tearDownAfterClass(); } public static function _tearDownAfterClass($dropDatabase = true) @@ -289,7 +289,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase if (!is_array($apiToCall)) { $apiToCall = array($apiToCall); } - self::$apiToCall = $apiToCall; + static::$apiToCall = $apiToCall; } /** @@ -304,7 +304,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase if (!is_array($apiNotToCall)) { $apiNotToCall = array($apiNotToCall); } - self::$apiNotToCall = $apiNotToCall; + static::$apiNotToCall = $apiNotToCall; } protected function alertWhenImagesExcludedFromTests() @@ -486,9 +486,9 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase $apiId = $moduleName . '.' . $methodName; // If Api to test were set, we only test these - if (!empty(self::$apiToCall) - && in_array($moduleName, self::$apiToCall) === false - && in_array($apiId, self::$apiToCall) === false + if (!empty(static::$apiToCall) + && in_array($moduleName, static::$apiToCall) === false + && in_array($apiId, static::$apiToCall) === false ) { // echo "Skipped $apiId... \n"; $skipped[] = $apiId; @@ -496,8 +496,8 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase } // Excluded modules from test elseif ( ((strpos($methodName, 'get') !== 0 && $methodName != 'generateReport') - || in_array($moduleName, self::$apiNotToCall) === true - || in_array($apiId, self::$apiNotToCall) === true + || in_array($moduleName, static::$apiNotToCall) === true + || in_array($apiId, static::$apiNotToCall) === true || $methodName == 'getLogoUrl' || $methodName == 'getSVGLogoUrl' || $methodName == 'hasSVGLogo' @@ -619,7 +619,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase $abandonedCarts = false, $idGoal = false, $apiModule = false, $apiAction = false, $otherRequestParameters = array(), $supertableApi = false, $fileExtension = false) { - list($pathProcessed, $pathExpected) = self::getProcessedAndExpectedDirs(); + list($pathProcessed, $pathExpected) = static::getProcessedAndExpectedDirs(); if ($periods === false) { $periods = 'day'; @@ -684,12 +684,12 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase protected function checkEnoughUrlsAreTested($requestUrls) { $countUrls = count($requestUrls); - $approximateCountApiToCall = count(self::$apiToCall); + $approximateCountApiToCall = count(static::$apiToCall); if (empty($requestUrls) || $approximateCountApiToCall > $countUrls ) { throw new Exception("Only generated $countUrls API calls to test but was expecting more for this test.\n" . - "Want to test APIs: " . implode(", ", self::$apiToCall) . ")\n" . + "Want to test APIs: " . implode(", ", static::$apiToCall) . ")\n" . "But only generated these URLs: \n" . implode("\n", $requestUrls) . ")\n" ); } @@ -864,7 +864,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase protected static function getProcessedAndExpectedDirs() { - $path = self::getPathToTestDirectory(); + $path = static::getPathToTestDirectory(); return array($path . '/processed/', $path . '/expected/'); } @@ -878,7 +878,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase $processedFilename = $testName . $filenameSuffix; $expectedFilename = ($compareAgainst ?: $testName) . $filenameSuffix; - list($processedDir, $expectedDir) = self::getProcessedAndExpectedDirs(); + list($processedDir, $expectedDir) = static::getProcessedAndExpectedDirs(); return array($processedDir . $processedFilename, $expectedDir . $expectedFilename); } @@ -948,22 +948,22 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase protected function _setCallableApi($api) { if ($api == 'all') { - self::setApiToCall(array()); - self::setApiNotToCall(static::$defaultApiNotToCall); + static::setApiToCall(array()); + static::setApiNotToCall(static::$defaultApiNotToCall); } else { if (!is_array($api)) { $api = array($api); } - self::setApiToCall($api); + static::setApiToCall($api); if (!in_array('UserCountry.getLocationFromIP', $api)) { - self::setApiNotToCall(array( + static::setApiNotToCall(array( 'API.getPiwikVersion', 'UserCountry.getLocationFromIP' )); } else { - self::setApiNotToCall(array()); + static::setApiNotToCall(array()); } } } -- GitLab