Skip to content
Permalink
Browse files

Change to allow the class name in the setting of the fixture

  • Loading branch information...
slywalker committed Sep 26, 2016
1 parent 85ed1aa commit f2109399444447990ccd919c2c4950ab4dd980b2
Showing with 49 additions and 24 deletions.
  1. +30 −24 src/TestSuite/Fixture/FixtureManager.php
  2. +19 −0 tests/TestCase/TestSuite/FixtureManagerTest.php
@@ -174,32 +174,38 @@ protected function _loadFixtures($test)
continue;
}
list($type, $pathName) = explode('.', $fixture, 2);
$path = explode('/', $pathName);
$name = array_pop($path);
$additionalPath = implode('\\', $path);
if ($type === 'core') {
$baseNamespace = 'Cake';
} elseif ($type === 'app') {
$baseNamespace = Configure::read('App.namespace');
} elseif ($type === 'plugin') {
list($plugin, $name) = explode('.', $pathName);
$path = implode('\\', explode('/', $plugin));
$baseNamespace = Inflector::camelize(str_replace('\\', '\ ', $path));
$additionalPath = null;
if (strpos($fixture, '.')) {
list($type, $pathName) = explode('.', $fixture, 2);
$path = explode('/', $pathName);
$name = array_pop($path);
$additionalPath = implode('\\', $path);
if ($type === 'core') {
$baseNamespace = 'Cake';
} elseif ($type === 'app') {
$baseNamespace = Configure::read('App.namespace');
} elseif ($type === 'plugin') {
list($plugin, $name) = explode('.', $pathName);
$path = implode('\\', explode('/', $plugin));
$baseNamespace = Inflector::camelize(str_replace('\\', '\ ', $path));
$additionalPath = null;
} else {
$baseNamespace = '';
$name = $fixture;
}
$name = Inflector::camelize($name);
$nameSegments = [
$baseNamespace,
'Test\Fixture',
$additionalPath,
$name . 'Fixture'
];
$className = implode('\\', array_filter($nameSegments));
} else {
$baseNamespace = '';
$name = $fixture;
$className = $fixture;
$name = preg_replace('/Fixture\z/', '', substr(strrchr($fixture, '\\'), 1));
}
$name = Inflector::camelize($name);
$nameSegments = [
$baseNamespace,
'Test\Fixture',
$additionalPath,
$name . 'Fixture'
];
$className = implode('\\', array_filter($nameSegments));
if (class_exists($className)) {
$this->_loaded[$fixture] = new $className();
@@ -222,6 +222,25 @@ public function testFixturizeCustom()
);
}
/**
* Test loading app fixtures.
*
* @return void
*/
public function testFixturizeClassName()
{
$test = $this->getMockBuilder('Cake\TestSuite\TestCase')->getMock();
$test->fixtures = ['Company\TestPluginThree\Test\Fixture\ArticlesFixture'];
$this->manager->fixturize($test);
$fixtures = $this->manager->loaded();
$this->assertCount(1, $fixtures);
$this->assertArrayHasKey('Company\TestPluginThree\Test\Fixture\ArticlesFixture', $fixtures);
$this->assertInstanceOf(
'Company\TestPluginThree\Test\Fixture\ArticlesFixture',
$fixtures['Company\TestPluginThree\Test\Fixture\ArticlesFixture']
);
}
/**
* Test that unknown types are handled gracefully.
*

0 comments on commit f210939

Please sign in to comment.
You can’t perform that action at this time.