Skip to content
Permalink
Browse files

Improve fixture generation to include namespaces.

  • Loading branch information...
markstory committed Oct 7, 2012
1 parent a7b9510 commit 0b5728ea22e64aca48e73790082de33fb7e97ed4
@@ -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.
*
@@ -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;
@@ -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();
@@ -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): ?>
/**
@@ -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)
*
@@ -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)
*/
@@ -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');
@@ -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);
@@ -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);

0 comments on commit 0b5728e

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