Skip to content

Commit

Permalink
Improve fixture generation to include namespaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Oct 7, 2012
1 parent a7b9510 commit 0b5728e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
18 changes: 13 additions & 5 deletions lib/Cake/Console/Command/Task/FixtureTask.php
@@ -1,9 +1,5 @@
<?php
/**
* The FixtureTask handles creating and updating fixture files.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc.
*
Expand All @@ -16,6 +12,8 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Cake\Console\Command\Task;

use Cake\Core\Configure;
use Cake\Console\Shell;
use Cake\Model\Model;
use Cake\Model\Schema;
Expand Down Expand Up @@ -244,7 +242,17 @@ public function bake($model, $useTable = false, $importOptions = array()) {
* @return string Content saved into fixture file.
*/
public function generateFixtureFile($model, $otherVars) {
$defaults = array('table' => null, 'schema' => null, 'records' => null, 'import' => null, 'fields' => null);
$defaults = [
'table' => null,
'schema' => null,
'records' => null,
'import' => null,
'fields' => null,
'namespace' => Configure::read('App.namespace')
];
if ($this->plugin) {
$defaults['namespace'] = $this->plugin;
}
$vars = array_merge($defaults, $otherVars);

$path = $this->getPath();
Expand Down
6 changes: 5 additions & 1 deletion lib/Cake/Console/Templates/default/classes/fixture.ctp
Expand Up @@ -20,11 +20,15 @@
*/
?>
<?php echo '<?php' . "\n"; ?>
namespace <?php echo $namespace; ?>\Test\Fixture;

use Cake\TestSuite\Fixture\TestFixture;

/**
* <?php echo $model; ?>Fixture
*
*/
class <?php echo $model; ?>Fixture extends \Cake\TestSuite\Fixture\TestFixture {
class <?php echo $model; ?>Fixture extends TestFixture {

<?php if ($table): ?>
/**
Expand Down
13 changes: 5 additions & 8 deletions lib/Cake/Test/TestCase/Console/Command/Task/FixtureTaskTest.php
@@ -1,9 +1,5 @@
<?php
/**
* FixtureTask Test case
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
Expand All @@ -12,7 +8,6 @@
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case.Console.Command.Task
* @since CakePHP(tm) v 1.3
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
Expand Down Expand Up @@ -152,7 +147,9 @@ public function testImportRecordsFromDatabaseWithConditionsPoo() {
'fromTable' => true, 'schema' => 'Article', 'records' => false
));

$this->assertContains('class ArticleFixture extends CakeTestFixture', $result);
$this->assertContains('namespace App\Test\Fixture;', $result);
$this->assertContains('use Cake\TestSuite\Fixture\TestFixture;', $result);
$this->assertContains('class ArticleFixture 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 @@ -302,13 +299,13 @@ public function testBake() {
$this->Task->path = '/my/path/';

$result = $this->Task->bake('Article');
$this->assertContains('class ArticleFixture extends CakeTestFixture', $result);
$this->assertContains('class ArticleFixture extends TestFixture', $result);
$this->assertContains('public $fields', $result);
$this->assertContains('public $records', $result);
$this->assertNotContains('public $import', $result);

$result = $this->Task->bake('Article', 'comments');
$this->assertContains('class ArticleFixture extends CakeTestFixture', $result);
$this->assertContains('class ArticleFixture extends TestFixture', $result);
$this->assertContains('public $table = \'comments\';', $result);
$this->assertContains('public $fields = array(', $result);

Expand Down
Expand Up @@ -156,7 +156,8 @@ public function testGenerateWithTemplateFallbacks() {
'table' => 'articles',
'import' => false,
'records' => false,
'schema' => ''
'schema' => '',
'namespace' => ''
));
$result = $this->Task->generate('classes', 'fixture');
$this->assertRegExp('/ArticleFixture extends .*TestFixture/', $result);
Expand Down

0 comments on commit 0b5728e

Please sign in to comment.