Skip to content

Commit

Permalink
Creation of a method to parse fixture path
Browse files Browse the repository at this point in the history
Creation of `_parseFixturePath`
  • Loading branch information
tonybonucci committed Mar 11, 2014
1 parent 9078f35 commit e4c47f8
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions lib/Cake/TestSuite/Fixture/CakeFixtureManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,24 @@ protected function _initDb() {
$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
*
Expand All @@ -115,27 +133,19 @@ protected function _loadFixtures($fixtures) {
$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(
Expand Down

0 comments on commit e4c47f8

Please sign in to comment.