Skip to content

Commit

Permalink
update bakeTask
Browse files Browse the repository at this point in the history
  • Loading branch information
antograssiot committed Sep 23, 2014
1 parent 38b9abd commit 1d9dd2a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/Core/ConventionsTrait.php
Expand Up @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Shell/Task/FixtureTask.php
Expand Up @@ -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,
Expand Down
40 changes: 20 additions & 20 deletions tests/TestCase/Shell/Task/FixtureTaskTest.php
Expand Up @@ -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');
Expand Down Expand Up @@ -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')
Expand All @@ -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');
}
Expand All @@ -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();
}
Expand 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'"));
Expand All @@ -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');
Expand All @@ -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');

Expand All @@ -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'))
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
14 changes: 7 additions & 7 deletions tests/TestCase/TestSuite/FixtureManagerTest.php
Expand Up @@ -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']);
}

/**
Expand All @@ -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']
);
}

Expand Down

0 comments on commit 1d9dd2a

Please sign in to comment.