mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 11:06:15 +00:00
Merge pull request #3 from Tounu/patch-4
Creation of a method to parse fixture path
This commit is contained in:
commit
91e52ff31a
1 changed files with 26 additions and 16 deletions
|
@ -95,6 +95,24 @@ class CakeFixtureManager {
|
||||||
$this->_initialized = true;
|
$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
|
* Looks for fixture files and instantiates the classes accordingly
|
||||||
*
|
*
|
||||||
|
@ -115,27 +133,19 @@ class CakeFixtureManager {
|
||||||
$fixturePaths[] = CAKE . 'Test' . DS . 'Fixture';
|
$fixturePaths[] = CAKE . 'Test' . DS . 'Fixture';
|
||||||
} elseif (strpos($fixture, 'app.') === 0) {
|
} elseif (strpos($fixture, 'app.') === 0) {
|
||||||
$fixturePrefixLess = substr($fixture, strlen('app.'));
|
$fixturePrefixLess = substr($fixture, strlen('app.'));
|
||||||
$pathTokenArray = explode('/', $fixturePrefixLess);
|
$fixtureParsedPath = $this->_parseFixturePath($fixturePrefixLess);
|
||||||
$fixture = array_pop($pathTokenArray);
|
$fixture = $fixtureParsedPath['fixture'];
|
||||||
$additionalPath = '';
|
|
||||||
foreach ($pathTokenArray as $pathToken) {
|
|
||||||
$additionalPath .= DS . $pathToken;
|
|
||||||
}
|
|
||||||
$fixturePaths = array(
|
$fixturePaths = array(
|
||||||
TESTS . 'Fixture' . $additionalPath
|
TESTS . 'Fixture' . $fixtureParsedPath['additionalPath']
|
||||||
);
|
);
|
||||||
} elseif (strpos($fixture, 'plugin.') === 0) {
|
} elseif (strpos($fixture, 'plugin.') === 0) {
|
||||||
$explodedFixture = explode('.', $fixturePrefixLess,3);
|
$explodedFixture = explode('.', $fixture, 3);
|
||||||
$pluginName = $explodedFixture[1];
|
$pluginName = $explodedFixture[1];
|
||||||
$pathTokenArray = explode('/', $explodedFixture[2]);
|
$fixtureParsedPath = $this->_parseFixturePath($explodedFixture[2]);
|
||||||
$fixture = array_pop($pathTokenArray);
|
$fixture = $fixtureParsedPath['fixture'];
|
||||||
$additionalPath = '';
|
|
||||||
foreach ($pathTokenArray as $pathToken) {
|
|
||||||
$additionalPath .= DS . $pathToken;
|
|
||||||
}
|
|
||||||
$fixturePaths = array(
|
$fixturePaths = array(
|
||||||
CakePlugin::path(Inflector::camelize($pluginName)) . 'Test' . DS . 'Fixture' . $additionalPath,
|
CakePlugin::path(Inflector::camelize($pluginName)) . 'Test' . DS . 'Fixture' . $fixtureParsedPath['additionalPath'],
|
||||||
TESTS . 'Fixture' . $additionalPath
|
TESTS . 'Fixture' . $fixtureParsedPath['additionalPath']
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$fixturePaths = array(
|
$fixturePaths = array(
|
||||||
|
|
Loading…
Add table
Reference in a new issue