Browse Source

Merge pull request #5258 from AD7six/3.0-bake-test-fixes

3.0 bake test fixes
Mark Story 11 years ago
parent
commit
93a5d919e1

+ 11 - 11
src/Shell/Task/TestTask.php

@@ -424,28 +424,28 @@ class TestTask extends BakeTask {
 		$pre = $construct = $post = '';
 		if ($type === 'table') {
 			$className = str_replace('Table', '', $className);
-			$pre = "\$config = TableRegistry::exists('{$className}') ? [] : ['className' => '{$fullClassName}'];\n";
-			$construct = "TableRegistry::get('{$className}', \$config);\n";
+			$pre = "\$config = TableRegistry::exists('{$className}') ? [] : ['className' => '{$fullClassName}'];";
+			$construct = "TableRegistry::get('{$className}', \$config);";
 		}
 		if ($type === 'behavior' || $type === 'entity') {
-			$construct = "new {$className}();\n";
+			$construct = "new {$className}();";
 		}
 		if ($type === 'helper') {
-			$pre = "\$view = new View();\n";
-			$construct = "new {$className}(\$view);\n";
+			$pre = "\$view = new View();";
+			$construct = "new {$className}(\$view);";
 		}
 		if ($type === 'component') {
-			$pre = "\$registry = new ComponentRegistry();\n";
-			$construct = "new {$className}(\$registry);\n";
+			$pre = "\$registry = new ComponentRegistry();";
+			$construct = "new {$className}(\$registry);";
 		}
 		if ($type === 'shell') {
-			$pre = "\$this->io = \$this->getMock('Cake\Console\ConsoleIo');\n";
-			$construct = "new {$className}(\$this->io);\n";
+			$pre = "\$this->io = \$this->getMock('Cake\Console\ConsoleIo');";
+			$construct = "new {$className}(\$this->io);";
 		}
 		if ($type === 'cell') {
 			$pre = "\$this->request = \$this->getMock('Cake\Network\Request');\n";
-			$pre .= "\t\t\$this->response = \$this->getMock('Cake\Network\Response');\n";
-			$construct = "new {$className}(\$this->request, \$this->response);\n";
+			$pre .= "\t\t\$this->response = \$this->getMock('Cake\Network\Response');";
+			$construct = "new {$className}(\$this->request, \$this->response);";
 		}
 		return [$pre, $construct, $post];
 	}

+ 2 - 2
src/Template/Bake/Model/entity.ctp

@@ -22,8 +22,8 @@ use Cake\ORM\Entity;
  * <%= $name %> Entity.
  */
 class <%= $name %> extends Entity {
-
 <% if (!empty($fields)): %>
+
 /**
  * Fields that can be mass assigned using newEntity() or patchEntity().
  *
@@ -34,7 +34,6 @@ class <%= $name %> extends Entity {
 		'<%= $field %>' => true,
 <% endforeach; %>
 	];
-
 <% endif %>
 <% if (!empty($hidden)): %>
 
@@ -45,4 +44,5 @@ class <%= $name %> extends Entity {
  */
 	protected $_hidden = [<%= $this->Bake->stringifyList($hidden) %>];
 <% endif %>
+
 }

+ 2 - 2
src/Template/Bake/Model/table.ctp

@@ -55,12 +55,12 @@ class <%= $name %>Table extends Table {
 <% endforeach %>
 <% endforeach %>
 	}
-
 <% if (!empty($validation)): %>
+
 /**
  * Default validation rules.
  *
- * @param \Cake\Validation\Validator $validator
+ * @param \Cake\Validation\Validator $validator instance
  * @return \Cake\Validation\Validator
  */
 	public function validationDefault(Validator $validator) {

+ 1 - 1
src/Template/Bake/config/routes.ctp

@@ -16,6 +16,6 @@
 <?php
 use Cake\Routing\Router;
 
-Router::plugin('<%= $plugin %>', function($routes) {
+Router::plugin('<%= $plugin %>', function ($routes) {
 	$routes->fallbacks();
 });

+ 13 - 7
src/Template/Bake/tests/test_case.ctp

@@ -17,6 +17,13 @@
 use Cake\Utility\Inflector;
 
 $isController = strtolower($type) === 'controller';
+
+if ($isController) {
+	$uses[] = 'Cake\TestSuite\IntegrationTestCase';
+} else {
+	$uses[] = 'Cake\TestSuite\TestCase';
+}
+sort($uses);
 %>
 <?php
 namespace <%= $baseNamespace; %>\Test\TestCase\<%= $subNamespace %>;
@@ -24,11 +31,6 @@ namespace <%= $baseNamespace; %>\Test\TestCase\<%= $subNamespace %>;
 <% foreach ($uses as $dependency): %>
 use <%= $dependency; %>;
 <% endforeach; %>
-<% if ($isController): %>
-use Cake\TestSuite\IntegrationTestCase;
-<% else: %>
-use Cake\TestSuite\TestCase;
-<% endif; %>
 
 /**
  * <%= $fullClassName %> Test Case
@@ -56,9 +58,13 @@ class <%= $className %>Test extends TestCase {
  */
 	public function setUp() {
 		parent::setUp();
-<%= $preConstruct ? "\t\t" . $preConstruct : '' %>
+	<%- if ($preConstruct): %>
+		<%= $preConstruct %>
+	<%- endif; %>
 		$this-><%= $subject . ' = ' . $construction %>
-<%= $postConstruct ? "\t\t" . $postConstruct : '' %>
+	<%- if ($postConstruct): %>
+		<%= $postConstruct %>
+	<%- endif; %>
 	}
 
 /**

+ 1 - 0
src/View/Helper/BakeHelper.php

@@ -68,6 +68,7 @@ class BakeHelper extends Helper {
 		$start = $end = '';
 		$join = ', ';
 		if ($options['indent']) {
+			$join = ',';
 			$start = "\n" . str_repeat("\t", $options['indent']);
 			$join .= $start;
 			$end = "\n" . str_repeat("\t", $options['indent'] - 1);

+ 1 - 1
tests/TestCase/Shell/Task/PluginTaskTest.php

@@ -145,7 +145,7 @@ class PluginTaskTest extends TestCase {
 
 		$file = $path . DS . 'config' . DS . 'routes.php';
 		$this->Task->expects($this->at(2))->method('createFile')
-			->with($file, $this->stringContains("Router::plugin('BakeTestPlugin', function(\$routes)"));
+			->with($file, $this->stringContains("Router::plugin('BakeTestPlugin', function (\$routes)"));
 
 		$file = $path . DS . 'phpunit.xml';
 		$this->Task->expects($this->at(3))->method('createFile')

+ 4 - 4
tests/TestCase/Shell/Task/TestTaskTest.php

@@ -456,18 +456,18 @@ class TestTaskTest extends TestCase {
 
 		$result = $this->Task->generateConstructor('table', 'App\Model\\Table\PostsTable');
 		$expected = [
-			"\$config = TableRegistry::exists('Posts') ? [] : ['className' => 'App\Model\\Table\PostsTable'];\n",
-			"TableRegistry::get('Posts', \$config);\n",
+			"\$config = TableRegistry::exists('Posts') ? [] : ['className' => 'App\Model\\Table\PostsTable'];",
+			"TableRegistry::get('Posts', \$config);",
 			''
 		];
 		$this->assertEquals($expected, $result);
 
 		$result = $this->Task->generateConstructor('helper', 'FormHelper');
-		$expected = ["\$view = new View();\n", "new FormHelper(\$view);\n", ''];
+		$expected = ["\$view = new View();", "new FormHelper(\$view);", ''];
 		$this->assertEquals($expected, $result);
 
 		$result = $this->Task->generateConstructor('entity', 'TestPlugin\Model\Entity\Article');
-		$expected = ["", "new Article();\n", ''];
+		$expected = ["", "new Article();", ''];
 		$this->assertEquals($expected, $result);
 	}
 

+ 1 - 1
tests/bake_compare/Model/testBakeEntityHidden.php

@@ -8,7 +8,6 @@ use Cake\ORM\Entity;
  */
 class BakeUser extends Entity {
 
-
 /**
  * Fields that are excluded from JSON an array versions of the entity.
  *
@@ -17,4 +16,5 @@ class BakeUser extends Entity {
 	protected $_hidden = [
 		'password'
 	];
+
 }

+ 0 - 1
tests/bake_compare/Model/testBakeTableConfig.php

@@ -23,5 +23,4 @@ class BakeArticlesTable extends Table {
 		$this->addBehavior('Timestamp');
 	}
 
-
 }

+ 6 - 7
tests/bake_compare/Model/testBakeTableRelations.php

@@ -19,24 +19,23 @@ class BakeArticlesTable extends Table {
 	public function initialize(array $config) {
 		$this->primaryKey('id');
 		$this->belongsTo('SomethingElse', [
-			'alias' => 'SomethingElse', 
+			'alias' => 'SomethingElse',
 			'foreignKey' => 'something_else_id'
 		]);
 		$this->belongsTo('BakeUser', [
-			'alias' => 'BakeUser', 
+			'alias' => 'BakeUser',
 			'foreignKey' => 'bake_user_id'
 		]);
 		$this->hasMany('BakeComment', [
-			'alias' => 'BakeComment', 
+			'alias' => 'BakeComment',
 			'foreignKey' => 'parent_id'
 		]);
 		$this->belongsToMany('BakeTag', [
-			'alias' => 'BakeTag', 
-			'foreignKey' => 'bake_article_id', 
-			'joinTable' => 'bake_articles_bake_tags', 
+			'alias' => 'BakeTag',
+			'foreignKey' => 'bake_article_id',
+			'joinTable' => 'bake_articles_bake_tags',
 			'targetForeignKey' => 'bake_tag_id'
 		]);
 	}
 
-
 }

+ 1 - 1
tests/bake_compare/Model/testBakeTableValidation.php

@@ -23,7 +23,7 @@ class BakeArticlesTable extends Table {
 /**
  * Default validation rules.
  *
- * @param \Cake\Validation\Validator $validator
+ * @param \Cake\Validation\Validator $validator instance
  * @return \Cake\Validation\Validator
  */
 	public function validationDefault(Validator $validator) {

+ 0 - 1
tests/bake_compare/Model/testBakeTableWithPlugin.php

@@ -20,5 +20,4 @@ class BakeArticlesTable extends Table {
 		$this->primaryKey('id');
 	}
 
-
 }

+ 1 - 1
tests/bake_compare/Template/testGenerateWithTemplateOverride.ctp

@@ -4,6 +4,6 @@
  */
 use Cake\Routing\Router;
 
-Router::plugin('Special', function($routes) {
+Router::plugin('Special', function ($routes) {
 	$routes->fallbacks();
 });

+ 0 - 2
tests/bake_compare/Test/testBakeBehaviorTest.php

@@ -16,9 +16,7 @@ class ExampleBehaviorTest extends TestCase {
  */
 	public function setUp() {
 		parent::setUp();
-
 		$this->Example = new ExampleBehavior();
-
 	}
 
 /**

+ 0 - 2
tests/bake_compare/Test/testBakeCellTest.php

@@ -18,9 +18,7 @@ class ArticlesCellTest extends TestCase {
 		parent::setUp();
 		$this->request = $this->getMock('Cake\Network\Request');
 		$this->response = $this->getMock('Cake\Network\Response');
-
 		$this->Articles = new ArticlesCell($this->request, $this->response);
-
 	}
 
 /**

+ 1 - 3
tests/bake_compare/Test/testBakeComponentTest.php

@@ -2,8 +2,8 @@
 namespace TestApp\Test\TestCase\Controller\Component;
 
 use Cake\Controller\ComponentRegistry;
-use TestApp\Controller\Component\AppleComponent;
 use Cake\TestSuite\TestCase;
+use TestApp\Controller\Component\AppleComponent;
 
 /**
  * TestApp\Controller\Component\AppleComponent Test Case
@@ -18,9 +18,7 @@ class AppleComponentTest extends TestCase {
 	public function setUp() {
 		parent::setUp();
 		$registry = new ComponentRegistry();
-
 		$this->Apple = new AppleComponent($registry);
-
 	}
 
 /**

+ 1 - 1
tests/bake_compare/Test/testBakeControllerTest.php

@@ -1,8 +1,8 @@
 <?php
 namespace TestApp\Test\TestCase\Controller;
 
-use TestApp\Controller\PostsController;
 use Cake\TestSuite\IntegrationTestCase;
+use TestApp\Controller\PostsController;
 
 /**
  * TestApp\Controller\PostsController Test Case

+ 3 - 5
tests/bake_compare/Test/testBakeFixturesParam.php

@@ -1,8 +1,8 @@
 <?php
 namespace App\Test\TestCase\Model\Table;
 
-use Cake\ORM\TableRegistry;
 use App\Model\Table\ArticlesTable;
+use Cake\ORM\TableRegistry;
 use Cake\TestSuite\TestCase;
 
 /**
@@ -16,8 +16,8 @@ class ArticlesTableTest extends TestCase {
  * @var array
  */
 	public $fixtures = [
-		'app.posts', 
-		'app.comments', 
+		'app.posts',
+		'app.comments',
 		'app.users'
 	];
 
@@ -29,9 +29,7 @@ class ArticlesTableTest extends TestCase {
 	public function setUp() {
 		parent::setUp();
 		$config = TableRegistry::exists('Articles') ? [] : ['className' => 'App\Model\Table\ArticlesTable'];
-
 		$this->Articles = TableRegistry::get('Articles', $config);
-
 	}
 
 /**

+ 1 - 3
tests/bake_compare/Test/testBakeHelperTest.php

@@ -1,9 +1,9 @@
 <?php
 namespace App\Test\TestCase\View\Helper;
 
-use Cake\View\View;
 use App\View\Helper\ExampleHelper;
 use Cake\TestSuite\TestCase;
+use Cake\View\View;
 
 /**
  * App\View\Helper\ExampleHelper Test Case
@@ -18,9 +18,7 @@ class ExampleHelperTest extends TestCase {
 	public function setUp() {
 		parent::setUp();
 		$view = new View();
-
 		$this->Example = new ExampleHelper($view);
-
 	}
 
 /**

+ 1 - 3
tests/bake_compare/Test/testBakeModelTest.php

@@ -1,8 +1,8 @@
 <?php
 namespace App\Test\TestCase\Model\Table;
 
-use Cake\ORM\TableRegistry;
 use App\Model\Table\ArticlesTable;
+use Cake\ORM\TableRegistry;
 use Cake\TestSuite\TestCase;
 
 /**
@@ -18,9 +18,7 @@ class ArticlesTableTest extends TestCase {
 	public function setUp() {
 		parent::setUp();
 		$config = TableRegistry::exists('Articles') ? [] : ['className' => 'App\Model\Table\ArticlesTable'];
-
 		$this->Articles = TableRegistry::get('Articles', $config);
-
 	}
 
 /**

+ 1 - 1
tests/bake_compare/Test/testBakePrefixControllerTest.php

@@ -1,8 +1,8 @@
 <?php
 namespace TestApp\Test\TestCase\Controller\Admin;
 
-use TestApp\Controller\Admin\PostsController;
 use Cake\TestSuite\IntegrationTestCase;
+use TestApp\Controller\Admin\PostsController;
 
 /**
  * TestApp\Controller\Admin\PostsController Test Case

+ 0 - 2
tests/bake_compare/Test/testBakeShellTest.php

@@ -17,9 +17,7 @@ class ArticlesShellTest extends TestCase {
 	public function setUp() {
 		parent::setUp();
 		$this->io = $this->getMock('Cake\Console\ConsoleIo');
-
 		$this->Articles = new ArticlesShell($this->io);
-
 	}
 
 /**

+ 1 - 1
tests/test_app/Plugin/TestBakeTheme/src/Template/Bake/config/routes.ctp

@@ -4,6 +4,6 @@
  */
 use Cake\Routing\Router;
 
-Router::plugin('<%= $plugin %>', function($routes) {
+Router::plugin('<%= $plugin %>', function ($routes) {
 	$routes->fallbacks();
 });