Skip to content

Commit

Permalink
Fix a few more failing tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Mar 18, 2014
1 parent c26df78 commit 9e41ec8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 60 deletions.
4 changes: 2 additions & 2 deletions src/Console/Command/Task/ModelTask.php
Expand Up @@ -105,7 +105,7 @@ public function execute() {
return $this->all();
}

$this->generate($this->args[0]);
$this->generate($this->_modelName($this->args[0]));
}

/**
Expand All @@ -128,8 +128,8 @@ public function generate($name) {
$data = compact(
'associations', 'primaryKey', 'displayField',
'table', 'fields', 'validation', 'behaviors');
$this->bakeEntity($model, $data);
$this->bakeTable($model, $data);
$this->bakeEntity($model, $data);
$this->bakeFixture($model, $table);
$this->bakeTest($model);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Console/Shell.php
Expand Up @@ -729,13 +729,13 @@ protected function _controllerName($name) {
}

/**
* Creates the proper model camelized name (singularized) for the specified name
* Creates the proper model camelized name (plural) for the specified name
*
* @param string $name Name
* @return string Camelized and singularized model name
* @return string Camelized and plural model name
*/
protected function _modelName($name) {
return Inflector::camelize($name);
return Inflector::pluralize(Inflector::camelize($name));
}

/**
Expand All @@ -755,8 +755,8 @@ protected function _modelKey($name) {
* @return string Model name
*/
protected function _modelNameFromKey($key) {
$class = Inflector::camelize(str_replace('_id', '', $key));
return Inflector::pluralize($class);
$key = str_replace('_id', '', $key);
return $this->_modelName($key);
}

/**
Expand Down
67 changes: 14 additions & 53 deletions tests/TestCase/Console/Command/Task/ModelTaskTest.php
Expand Up @@ -620,20 +620,21 @@ public function testBakeEntityWithPlugin() {
* @return void
*/
public function testExecuteWithNamedModel() {
$this->markTestIncomplete('Not done here yet');
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$this->Task->args = array('BakeArticle');
$filename = '/my/path/BakeArticle.php';
$this->Task->args = ['BakeArticles'];

$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(1));
$this->Task->expects($this->once())->method('createFile')
->with($filename, $this->stringContains('class BakeArticle extends AppModel'));
$tableFile = '/my/path/Table/BakeArticlesTable.php';
$this->Task->expects($this->at(0))
->method('createFile')
->with($tableFile, $this->stringContains('class BakeArticlesTable extends Table'));

$this->Task->execute();
$entityFile = '/my/path/Entity/BakeArticle.php';
$this->Task->expects($this->at(1))
->method('createFile')
->with($entityFile, $this->stringContains('class BakeArticle extends Entity'));

$this->assertEquals(count(ClassRegistry::keys()), 0);
$this->assertEquals(count(ClassRegistry::mapKeys()), 0);
$this->Task->execute();
}

/**
Expand All @@ -654,35 +655,15 @@ public static function nameVariations() {
* @return void
*/
public function testExecuteWithNamedModelVariations($name) {
$this->markTestIncomplete('Not done here yet');
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(1));

$this->Task->args = array($name);
$filename = '/my/path/BakeArticle.php';

$this->Task->expects($this->at(0))->method('createFile')
->with($filename, $this->stringContains('class BakeArticle extends AppModel'));
$this->Task->execute();
}

/**
* test that execute with a model name picks up hasMany associations.
*
* @return void
*/
public function testExecuteWithNamedModelHasManyCreated() {
$this->markTestIncomplete('Not done here yet');
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$this->Task->args = array('BakeArticle');
$filename = '/my/path/BakeArticle.php';

$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(1));
$this->Task->expects($this->at(0))->method('createFile')
->with($filename, $this->stringContains("'BakeComment' => array("));
$filename = '/my/path/Table/BakeArticlesTable.php';

$this->Task->expects($this->at(0))
->method('createFile')
->with($filename, $this->stringContains('class BakeArticlesTable extends Table {'));
$this->Task->execute();
}

Expand Down Expand Up @@ -894,26 +875,6 @@ public function testSkipTablesAndAll() {
$this->Task->execute();
}

/**
* test using bake interactively with a table that does not exist.
*
* @return void
*/
public function testExecuteWithNonExistantTableName() {
$this->markTestIncomplete('Not done here yet');
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';

$this->Task->expects($this->any())->method('in')
->will($this->onConsecutiveCalls(
'Foobar', // Or type in the name of the model
'y', // Do you want to use this table
'n' // Doesn't exist, continue anyway?
));

$this->Task->execute();
}

/**
* test using bake interactively with a table that does not exist.
*
Expand Down

0 comments on commit 9e41ec8

Please sign in to comment.