Skip to content
Permalink
Browse files

update bakeTask

  • Loading branch information...
antograssiot committed Sep 23, 2014
1 parent 38b9abd commit 1d9dd2adc6f30fa027b3bef7c21eaf216941877c
@@ -40,7 +40,7 @@ protected function _controllerName($name) {
* @return string Singular model key
*/
protected function _fixtureName($name) {
return Inflector::underscore(Inflector::singularize($name));
return Inflector::underscore($name);
}
/**
@@ -194,7 +194,7 @@ public function bake($model, $useTable = false) {
*/
public function generateFixtureFile($model, array $otherVars) {
$defaults = [
'name' => Inflector::singularize($model),
'name' => $model,
'table' => null,
'schema' => null,
'records' => null,
@@ -101,7 +101,7 @@ public function testImportRecordsFromDatabaseWithConditionsPoo() {
$this->assertContains('namespace App\Test\Fixture;', $result);
$this->assertContains('use Cake\TestSuite\Fixture\TestFixture;', $result);
$this->assertContains('class ArticleFixture extends TestFixture', $result);
$this->assertContains('class ArticlesFixture extends TestFixture', $result);
$this->assertContains('public $records', $result);
$this->assertContains('public $import', $result);
$this->assertContains("'title' => 'First Article'", $result, 'Missing import data %s');
@@ -144,7 +144,7 @@ public function testImportRecordsNoEscaping() {
public function testMainWithTableOption() {
$this->Task->connection = 'test';
$this->Task->params = ['table' => 'comments'];
$filename = $this->_normalizePath(ROOT . '/tests/Fixture/ArticleFixture.php');
$filename = $this->_normalizePath(ROOT . '/tests/Fixture/ArticlesFixture.php');
$this->Task->expects($this->at(0))
->method('createFile')
@@ -160,13 +160,13 @@ public function testMainWithTableOption() {
*/
public function testMainWithPluginModel() {
$this->Task->connection = 'test';
$filename = $this->_normalizePath(TEST_APP . 'Plugin/TestPlugin/tests/Fixture/ArticleFixture.php');
$filename = $this->_normalizePath(TEST_APP . 'Plugin/TestPlugin/tests/Fixture/ArticlesFixture.php');
Plugin::load('TestPlugin');
$this->Task->expects($this->at(0))
->method('createFile')
->with($filename, $this->stringContains('class ArticleFixture'));
->with($filename, $this->stringContains('class ArticlesFixture'));
$this->Task->main('TestPlugin.Article');
}
@@ -182,15 +182,15 @@ public function testMainIntoAll() {
->method('listAll')
->will($this->returnValue(array('articles', 'comments')));
$filename = $this->_normalizePath(ROOT . '/tests/Fixture/ArticleFixture.php');
$filename = $this->_normalizePath(ROOT . '/tests/Fixture/ArticlesFixture.php');
$this->Task->expects($this->at(0))
->method('createFile')
->with($filename, $this->stringContains('class ArticleFixture'));
->with($filename, $this->stringContains('class ArticlesFixture'));
$filename = $this->_normalizePath(ROOT . '/tests/Fixture/CommentFixture.php');
$filename = $this->_normalizePath(ROOT . '/tests/Fixture/CommentsFixture.php');
$this->Task->expects($this->at(1))
->method('createFile')
->with($filename, $this->stringContains('class CommentFixture'));
->with($filename, $this->stringContains('class CommentsFixture'));
$this->Task->all();
}
@@ -207,12 +207,12 @@ public function testAllWithCountAndRecordsFlags() {
$this->Task->Model->expects($this->any())->method('listAll')
->will($this->returnValue(array('Articles', 'comments')));
$filename = $this->_normalizePath(ROOT . '/tests/Fixture/ArticleFixture.php');
$filename = $this->_normalizePath(ROOT . '/tests/Fixture/ArticlesFixture.php');
$this->Task->expects($this->at(0))
->method('createFile')
->with($filename, $this->stringContains("'title' => 'Third Article'"));
$filename = $this->_normalizePath(ROOT . '/tests/Fixture/CommentFixture.php');
$filename = $this->_normalizePath(ROOT . '/tests/Fixture/CommentsFixture.php');
$this->Task->expects($this->at(1))
->method('createFile')
->with($filename, $this->stringContains("'comment' => 'First Comment for First Article'"));
@@ -233,11 +233,11 @@ public function testAllWithSchemaImport() {
$this->Task->Model->expects($this->any())->method('listAll')
->will($this->returnValue(array('Articles', 'comments')));
$filename = $this->_normalizePath(ROOT . '/tests/Fixture/ArticleFixture.php');
$filename = $this->_normalizePath(ROOT . '/tests/Fixture/ArticlesFixture.php');
$this->Task->expects($this->at(0))->method('createFile')
->with($filename, $this->stringContains("public \$import = ['model' => 'Articles'"));
$filename = $this->_normalizePath(ROOT . '/tests/Fixture/CommentFixture.php');
$filename = $this->_normalizePath(ROOT . '/tests/Fixture/CommentsFixture.php');
$this->Task->expects($this->at(1))->method('createFile')
->with($filename, $this->stringContains("public \$import = ['model' => 'Comments'"));
$this->Task->expects($this->exactly(2))->method('createFile');
@@ -257,7 +257,7 @@ public function testMainNoArgs() {
->method('listAll')
->will($this->returnValue(['articles', 'comments']));
$filename = $this->_normalizePath(ROOT . '/tests/Fixture/ArticleFixture.php');
$filename = $this->_normalizePath(ROOT . '/tests/Fixture/ArticlesFixture.php');
$this->Task->expects($this->never())
->method('createFile');
@@ -275,7 +275,7 @@ public function testBake() {
$this->Task->expects($this->at(0))
->method('createFile')
->with($this->anything(), $this->logicalAnd(
$this->stringContains('class ArticleFixture extends TestFixture'),
$this->stringContains('class ArticlesFixture extends TestFixture'),
$this->stringContains('public $fields'),
$this->stringContains('public $records'),
$this->logicalNot($this->stringContains('public $import'))
@@ -347,13 +347,13 @@ public function testRecordGenerationForBinaryAndFloat() {
*/
public function testGenerateFixtureFile() {
$this->Task->connection = 'test';
$filename = $this->_normalizePath(ROOT . '/tests/Fixture/ArticleFixture.php');
$filename = $this->_normalizePath(ROOT . '/tests/Fixture/ArticlesFixture.php');
$this->Task->expects($this->at(0))
->method('createFile')
->with($filename, $this->stringContains('ArticleFixture'));
->with($filename, $this->stringContains('ArticlesFixture'));
$result = $this->Task->generateFixtureFile('Article', []);
$result = $this->Task->generateFixtureFile('Articles', []);
$this->assertContains('<?php', $result);
$this->assertContains('namespace App\Test\Fixture;', $result);
}
@@ -366,13 +366,13 @@ public function testGenerateFixtureFile() {
public function testGeneratePluginFixtureFile() {
$this->Task->connection = 'test';
$this->Task->plugin = 'TestPlugin';
$filename = $this->_normalizePath(TEST_APP . 'Plugin/TestPlugin/tests/Fixture/ArticleFixture.php');
$filename = $this->_normalizePath(TEST_APP . 'Plugin/TestPlugin/tests/Fixture/ArticlesFixture.php');
Plugin::load('TestPlugin');
$this->Task->expects($this->at(0))->method('createFile')
->with($filename, $this->stringContains('class Article'));
->with($filename, $this->stringContains('class Articles'));
$result = $this->Task->generateFixtureFile('Article', []);
$result = $this->Task->generateFixtureFile('Articles', []);
$this->assertContains('<?php', $result);
$this->assertContains('namespace TestPlugin\Test\Fixture;', $result);
}
@@ -41,12 +41,12 @@ public function setUp() {
*/
public function testFixturizeCore() {
$test = $this->getMock('Cake\TestSuite\TestCase');
$test->fixtures = ['core.article'];
$test->fixtures = ['core.articles'];
$this->manager->fixturize($test);
$fixtures = $this->manager->loaded();
$this->assertCount(1, $fixtures);
$this->assertArrayHasKey('core.article', $fixtures);
$this->assertInstanceOf('Cake\Test\Fixture\ArticleFixture', $fixtures['core.article']);
$this->assertArrayHasKey('core.articles', $fixtures);
$this->assertInstanceOf('Cake\Test\Fixture\ArticlesFixture', $fixtures['core.articles']);
}
/**
@@ -58,14 +58,14 @@ public function testFixturizePlugin() {
Plugin::load('TestPlugin');
$test = $this->getMock('Cake\TestSuite\TestCase');
$test->fixtures = ['plugin.test_plugin.article'];
$test->fixtures = ['plugin.test_plugin.articles'];
$this->manager->fixturize($test);
$fixtures = $this->manager->loaded();
$this->assertCount(1, $fixtures);
$this->assertArrayHasKey('plugin.test_plugin.article', $fixtures);
$this->assertArrayHasKey('plugin.test_plugin.articles', $fixtures);
$this->assertInstanceOf(
'TestPlugin\Test\Fixture\ArticleFixture',
$fixtures['plugin.test_plugin.article']
'TestPlugin\Test\Fixture\ArticlesFixture',
$fixtures['plugin.test_plugin.articles']
);
}

0 comments on commit 1d9dd2a

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