Refactoring FixtureTask so it generates correct file names

This commit is contained in:
Jose Lorenzo Rodriguez 2011-04-10 20:56:06 -04:30
parent d561460fda
commit 662abd6419
2 changed files with 13 additions and 13 deletions

View file

@ -57,7 +57,7 @@ class FixtureTask extends BakeTask {
*/ */
public function __construct($stdout = null, $stderr = null, $stdin = null) { public function __construct($stdout = null, $stderr = null, $stdin = null) {
parent::__construct($stdout, $stderr, $stdin); parent::__construct($stdout, $stderr, $stdin);
$this->path = APP . 'tests' . DS . 'fixtures' . DS; $this->path = APP . 'tests' . DS . 'Fixture' . DS;
} }
/** /**
@ -249,7 +249,7 @@ class FixtureTask extends BakeTask {
$vars = array_merge($defaults, $otherVars); $vars = array_merge($defaults, $otherVars);
$path = $this->getPath(); $path = $this->getPath();
$filename = Inflector::underscore($model) . '_fixture.php'; $filename = Inflector::camelize($model) . 'Fixture.php';
$this->Template->set('model', $model); $this->Template->set('model', $model);
$this->Template->set($vars); $this->Template->set($vars);
@ -268,7 +268,7 @@ class FixtureTask extends BakeTask {
public function getPath() { public function getPath() {
$path = $this->path; $path = $this->path;
if (isset($this->plugin)) { if (isset($this->plugin)) {
$path = $this->_pluginPath($this->plugin) . 'tests' . DS . 'fixtures' . DS; $path = $this->_pluginPath($this->plugin) . 'tests' . DS . 'Fixture' . DS;
} }
return $path; return $path;
} }

View file

@ -83,7 +83,7 @@ class FixtureTaskTest extends CakeTestCase {
$in = $this->getMock('ConsoleInput', array(), array(), '', false); $in = $this->getMock('ConsoleInput', array(), array(), '', false);
$Task = new FixtureTask($out, $out, $in); $Task = new FixtureTask($out, $out, $in);
$this->assertEqual($Task->path, APP . 'tests' . DS . 'fixtures' . DS); $this->assertEqual($Task->path, APP . 'tests' . DS . 'Fixture' . DS);
} }
/** /**
@ -174,7 +174,7 @@ class FixtureTaskTest extends CakeTestCase {
$this->Task->connection = 'test'; $this->Task->connection = 'test';
$this->Task->path = '/my/path/'; $this->Task->path = '/my/path/';
$this->Task->args = array('article'); $this->Task->args = array('article');
$filename = '/my/path/article_fixture.php'; $filename = '/my/path/ArticleFixture.php';
$this->Task->expects($this->at(0))->method('createFile') $this->Task->expects($this->at(0))->method('createFile')
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class ArticleFixture/')); ->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class ArticleFixture/'));
@ -204,7 +204,7 @@ class FixtureTaskTest extends CakeTestCase {
$this->Task->path = '/my/path/'; $this->Task->path = '/my/path/';
$this->Task->args = array($modelName); $this->Task->args = array($modelName);
$filename = '/my/path/article_fixture.php'; $filename = '/my/path/ArticleFixture.php';
$this->Task->expects($this->once())->method('createFile') $this->Task->expects($this->once())->method('createFile')
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class ArticleFixture/')); ->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class ArticleFixture/'));
@ -223,11 +223,11 @@ class FixtureTaskTest extends CakeTestCase {
$this->Task->Model->expects($this->any())->method('listAll') $this->Task->Model->expects($this->any())->method('listAll')
->will($this->returnValue(array('articles', 'comments'))); ->will($this->returnValue(array('articles', 'comments')));
$filename = '/my/path/article_fixture.php'; $filename = '/my/path/ArticleFixture.php';
$this->Task->expects($this->at(0))->method('createFile') $this->Task->expects($this->at(0))->method('createFile')
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class ArticleFixture/')); ->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class ArticleFixture/'));
$filename = '/my/path/comment_fixture.php'; $filename = '/my/path/CommentFixture.php';
$this->Task->expects($this->at(1))->method('createFile') $this->Task->expects($this->at(1))->method('createFile')
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class CommentFixture/')); ->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class CommentFixture/'));
@ -248,11 +248,11 @@ class FixtureTaskTest extends CakeTestCase {
$this->Task->Model->expects($this->any())->method('listAll') $this->Task->Model->expects($this->any())->method('listAll')
->will($this->returnValue(array('articles', 'comments'))); ->will($this->returnValue(array('articles', 'comments')));
$filename = '/my/path/article_fixture.php'; $filename = '/my/path/ArticleFixture.php';
$this->Task->expects($this->at(0))->method('createFile') $this->Task->expects($this->at(0))->method('createFile')
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/title\' => \'Third Article\'/')); ->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/title\' => \'Third Article\'/'));
$filename = '/my/path/comment_fixture.php'; $filename = '/my/path/CommentFixture.php';
$this->Task->expects($this->at(1))->method('createFile') $this->Task->expects($this->at(1))->method('createFile')
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/comment\' => \'First Comment for First Article/')); ->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/comment\' => \'First Comment for First Article/'));
$this->Task->expects($this->exactly(2))->method('createFile'); $this->Task->expects($this->exactly(2))->method('createFile');
@ -275,7 +275,7 @@ class FixtureTaskTest extends CakeTestCase {
->with('Article') ->with('Article')
->will($this->returnValue('articles')); ->will($this->returnValue('articles'));
$filename = '/my/path/article_fixture.php'; $filename = '/my/path/ArticleFixture.php';
$this->Task->expects($this->once())->method('createFile') $this->Task->expects($this->once())->method('createFile')
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class ArticleFixture/')); ->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class ArticleFixture/'));
@ -340,7 +340,7 @@ class FixtureTaskTest extends CakeTestCase {
public function testGenerateFixtureFile() { public function testGenerateFixtureFile() {
$this->Task->connection = 'test'; $this->Task->connection = 'test';
$this->Task->path = '/my/path/'; $this->Task->path = '/my/path/';
$filename = '/my/path/article_fixture.php'; $filename = '/my/path/ArticleFixture.php';
$this->Task->expects($this->at(0))->method('createFile') $this->Task->expects($this->at(0))->method('createFile')
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/ArticleFixture/')); ->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/ArticleFixture/'));
@ -362,7 +362,7 @@ class FixtureTaskTest extends CakeTestCase {
$this->Task->connection = 'test'; $this->Task->connection = 'test';
$this->Task->path = '/my/path/'; $this->Task->path = '/my/path/';
$this->Task->plugin = 'TestFixture'; $this->Task->plugin = 'TestFixture';
$filename = APP . 'plugins' . DS . 'test_fixture' . DS . 'tests' . DS . 'fixtures' . DS . 'article_fixture.php'; $filename = APP . 'plugins' . DS . 'test_fixture' . DS . 'tests' . DS . 'Fixture' . DS . 'ArticleFixture.php';
$this->Task->expects($this->at(0))->method('createFile') $this->Task->expects($this->at(0))->method('createFile')
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/Article/')); ->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/Article/'));