Browse Source

phpcs fixes to test templates

And related code changes to make bake match the bake_compare files
AD7six 11 years ago
parent
commit
ae019e4242

+ 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; %>
 	}
 
 /**

+ 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);
 	}
 

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

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

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

@@ -18,7 +18,6 @@ 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);
 	}
 

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

@@ -18,7 +18,6 @@ class AppleComponentTest extends TestCase {
 	public function setUp() {
 		parent::setUp();
 		$registry = new ComponentRegistry();
-
 		$this->Apple = new AppleComponent($registry);
 	}
 

+ 0 - 1
tests/bake_compare/Test/testBakeFixturesParam.php

@@ -29,7 +29,6 @@ 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();
 });