From e4c47f87ddc146b728ed8de2df250f916a377ab9 Mon Sep 17 00:00:00 2001 From: Tounu Date: Tue, 11 Mar 2014 20:55:46 +0100 Subject: [PATCH] Creation of a method to parse fixture path Creation of `_parseFixturePath` --- .../TestSuite/Fixture/CakeFixtureManager.php | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/lib/Cake/TestSuite/Fixture/CakeFixtureManager.php b/lib/Cake/TestSuite/Fixture/CakeFixtureManager.php index 52649ed6f..8816baa0b 100644 --- a/lib/Cake/TestSuite/Fixture/CakeFixtureManager.php +++ b/lib/Cake/TestSuite/Fixture/CakeFixtureManager.php @@ -95,6 +95,24 @@ class CakeFixtureManager { $this->_initialized = true; } +/** + * Parse the fixture path included in test cases, to get the fixture class name, and the + * real fixture path including sub-directories + * + * @param string $fixturePath the fixture path to parse + * @return array containing fixture class name and optional additional path + */ + protected function _parseFixturePath($fixturePath) { + $pathTokenArray = explode('/', $fixturePath); + $fixture = array_pop($pathTokenArray); + $additionalPath = ''; + foreach ($pathTokenArray as $pathToken) { + $additionalPath .= DS . $pathToken; + } + + return array('fixture' => $fixture, 'additionalPath' => $additionalPath); + } + /** * Looks for fixture files and instantiates the classes accordingly * @@ -115,27 +133,19 @@ class CakeFixtureManager { $fixturePaths[] = CAKE . 'Test' . DS . 'Fixture'; } elseif (strpos($fixture, 'app.') === 0) { $fixturePrefixLess = substr($fixture, strlen('app.')); - $pathTokenArray = explode('/', $fixturePrefixLess); - $fixture = array_pop($pathTokenArray); - $additionalPath = ''; - foreach ($pathTokenArray as $pathToken) { - $additionalPath .= DS . $pathToken; - } + $fixtureParsedPath = $this->_parseFixturePath($fixturePrefixLess); + $fixture = $fixtureParsedPath['fixture']; $fixturePaths = array( - TESTS . 'Fixture' . $additionalPath + TESTS . 'Fixture' . $fixtureParsedPath['additionalPath'] ); } elseif (strpos($fixture, 'plugin.') === 0) { - $explodedFixture = explode('.', $fixturePrefixLess,3); + $explodedFixture = explode('.', $fixture, 3); $pluginName = $explodedFixture[1]; - $pathTokenArray = explode('/', $explodedFixture[2]); - $fixture = array_pop($pathTokenArray); - $additionalPath = ''; - foreach ($pathTokenArray as $pathToken) { - $additionalPath .= DS . $pathToken; - } + $fixtureParsedPath = $this->_parseFixturePath($explodedFixture[2]); + $fixture = $fixtureParsedPath['fixture']; $fixturePaths = array( - CakePlugin::path(Inflector::camelize($pluginName)) . 'Test' . DS . 'Fixture' . $additionalPath, - TESTS . 'Fixture' . $additionalPath + CakePlugin::path(Inflector::camelize($pluginName)) . 'Test' . DS . 'Fixture' . $fixtureParsedPath['additionalPath'], + TESTS . 'Fixture' . $fixtureParsedPath['additionalPath'] ); } else { $fixturePaths = array(