Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Creation of a method to parse fixture path

Creation of `_parseFixturePath`
  • Loading branch information...
commit e4c47f87ddc146b728ed8de2df250f916a377ab9 1 parent 9078f35
@Tounu Tounu authored
Showing with 26 additions and 16 deletions.
  1. +26 −16 lib/Cake/TestSuite/Fixture/CakeFixtureManager.php
View
42 lib/Cake/TestSuite/Fixture/CakeFixtureManager.php
@@ -96,6 +96,24 @@ protected function _initDb() {
}
/**
+ * 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
*
* @param array $fixtures the fixture names to load using the notation {type}.{name}
@@ -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(
Please sign in to comment.
Something went wrong with that request. Please try again.