Add test for plugin controller annotations
MODIFY
tests/TestCase/Annotator/ControllerAnnotatorTest.php
tests/TestCase/Annotator/ControllerAnnotatorTest.php
@@ -127,4 +127,51 @@ class ControllerAnnotatorTest extends TestCase {
return $this->getMockBuilder(ControllerAnnotator::class)->setMethods(['_storeFile'])->setConstructorArgs([$this->io, $params])->getMock();
}
+ /**
+ * @return void
+ */
+ public function testAnnotateWithPluginController()
+ {
+ $annotator = $this->_getAnnotatorMock([]);
+
+ $expectedContent = str_replace("\r\n", "\n", file_get_contents(TEST_FILES . 'Controller/HousesController.php'));
+ $callback = function ($value) use ($expectedContent) {
+ $value = str_replace(["\r\n", "\r"], "\n", $value);
+ if ($value !== $expectedContent) {
+ $this->_displayDiff($expectedContent, $value);
+ }
+
+ return $value === $expectedContent;
+ };
+ $annotator->expects($this->once())
+ ->method('_storeFile')
+ ->with($this->anything(), $this->callback($callback));
+
+ $path = TEST_ROOT . '/plugins/Controllers/src/Controller/HousesController.php';
+ $annotator->setConfig(ControllerAnnotator::CONFIG_PLUGIN, 'Controllers');
+ $annotator->annotate($path);
+
+ $output = (string)$this->out->output();
+
+ $this->assertTextContains(' -> 1 annotation added.', $output);
+ }
+
+ /**
+ * @return void
+ */
+ public function testAnnotateWithPluginControllerNoModel()
+ {
+ $annotator = $this->_getAnnotatorMock([]);
+
+ $annotator->expects($this->never())
+ ->method('_storeFile');
+
+ $path = TEST_ROOT . '/plugins/Controllers/src/Controller/GenericController.php';
+ $annotator->setConfig(ControllerAnnotator::CONFIG_PLUGIN, 'Awesome');
+ $annotator->annotate($path);
+
+ $output = (string)$this->out->output();
+
+ $this->assertTextNotContains(' -> 1 annotation added.', $output);
+ }
}

MODIFY
tests/TestCase/Generator/Task/ModelTaskTest.php
tests/TestCase/Generator/Task/ModelTaskTest.php
@@ -40,7 +40,8 @@ class ModelTaskTest extends TestCase {
'WheelsExtra' => '\App\Model\Table\WheelsExtraTable::class',
'Wheels' => '\App\Model\Table\WheelsTable::class',
'Awesome.Houses' => '\Awesome\Model\Table\HousesTable::class',
- 'Awesome.Windows' => '\Awesome\Model\Table\WindowsTable::class'
+ 'Awesome.Windows' => '\Awesome\Model\Table\WindowsTable::class',
+ 'Controllers.Houses' => '\Controllers\Model\Table\HousesTable::class',
];
$map = array_shift($result);
$this->assertSame($expectedMap, $map);

MODIFY
tests/TestCase/Generator/Task/TableAssociationTaskTest.php
tests/TestCase/Generator/Task/TableAssociationTaskTest.php
@@ -41,6 +41,7 @@ class TableAssociationTaskTest extends TestCase {
'Wheels' => '\Cake\ORM\Association\BelongsTo::class',
'Awesome.Houses' => '\Cake\ORM\Association\BelongsTo::class',
'Awesome.Windows' => '\Cake\ORM\Association\BelongsTo::class',
+ 'Controllers.Houses' => '\Cake\ORM\Association\BelongsTo::class',
];
$map = array_shift($result);
$this->assertSame($expectedMap, $map);

MODIFY
tests/bootstrap.php
tests/bootstrap.php
@@ -76,6 +76,7 @@ Type::build('timestamp')
Plugin::load('IdeHelper', ['path' => ROOT . DS, 'autoload' => true]);
Plugin::load('Shim', ['path' => ROOT . DS . 'vendor/dereuromark/cakephp-shim/', 'autoload' => true]);
Plugin::load('Awesome', ['path' => TEST_ROOT . 'plugins/Awesome/', 'autoload' => true]);
+Plugin::load('Controllers', ['path' => TEST_ROOT . 'plugins/Controllers/', 'autoload' => true]);
Plugin::load('MyBehavior/MyPlugin', ['path' => TEST_ROOT . 'plugins/MyBehavior/MyPlugin/', 'autoload' => true]);
DispatcherFactory::add('Routing');

DELETE
tests/test_app/plugins/Awesome/src/Controller/HousesController.php
-<?php
-
-/**
- * Class HousesController
- */
-class HousesController
-{
-
-}

ADD
tests/test_app/plugins/Controllers/src/Controller/GenericController.php
+<?php
+namespace Controllers\Controller;
+
+use \Cake\Controller\Controller;
+
+class GenericController extends Controller
+{
+ public $modelClass = false;
+}

ADD
tests/test_app/plugins/Controllers/src/Controller/HousesController.php
+<?php
+namespace Controllers\Controller;
+
+use \Cake\Controller\Controller;
+
+class HousesController extends Controller
+{
+}

ADD
tests/test_app/plugins/Controllers/src/Model/Table/HousesTable.php
+<?php
+namespace Controllers\Model\Table;
+
+use Cake\ORM\Table;
+
+class HousesTable extends Table {
+}

ADD
tests/test_files/Controller/HousesController.php
+<?php
+namespace Controllers\Controller;
+
+use \Cake\Controller\Controller;
+
+/**
+ * @property \Controllers\Model\Table\HousesTable $Houses
+ */
+class HousesController extends Controller
+{
+}

MODIFY
tests/test_files/meta/phpstorm/.meta.php
tests/test_files/meta/phpstorm/.meta.php
@@ -65,6 +65,7 @@ namespace PHPSTORM_META {
'Wheels' => \App\Model\Table\WheelsTable::class,
'Awesome.Houses' => \Awesome\Model\Table\HousesTable::class,
'Awesome.Windows' => \Awesome\Model\Table\WindowsTable::class,
+ 'Controllers.Houses' => \Controllers\Model\Table\HousesTable::class,
])
);
@@ -100,6 +101,7 @@ namespace PHPSTORM_META {
'Wheels' => \App\Model\Table\WheelsTable::class,
'Awesome.Houses' => \Awesome\Model\Table\HousesTable::class,
'Awesome.Windows' => \Awesome\Model\Table\WindowsTable::class,
+ 'Controllers.Houses' => \Controllers\Model\Table\HousesTable::class,
])
);
@@ -128,6 +130,7 @@ namespace PHPSTORM_META {
'Wheels' => \Cake\ORM\Association\BelongsToMany::class,
'Awesome.Houses' => \Cake\ORM\Association\BelongsToMany::class,
'Awesome.Windows' => \Cake\ORM\Association\BelongsToMany::class,
+ 'Controllers.Houses' => \Cake\ORM\Association\BelongsToMany::class,
])
);
@@ -145,6 +148,7 @@ namespace PHPSTORM_META {
'Wheels' => \Cake\ORM\Association\BelongsTo::class,
'Awesome.Houses' => \Cake\ORM\Association\BelongsTo::class,
'Awesome.Windows' => \Cake\ORM\Association\BelongsTo::class,
+ 'Controllers.Houses' => \Cake\ORM\Association\BelongsTo::class,
])
);
@@ -171,6 +175,7 @@ namespace PHPSTORM_META {
'Wheels' => \Cake\ORM\Association\HasMany::class,
'Awesome.Houses' => \Cake\ORM\Association\HasMany::class,
'Awesome.Windows' => \Cake\ORM\Association\HasMany::class,
+ 'Controllers.Houses' => \Cake\ORM\Association\HasMany::class,
])
);
@@ -188,6 +193,7 @@ namespace PHPSTORM_META {
'Wheels' => \Cake\ORM\Association\HasOne::class,
'Awesome.Houses' => \Cake\ORM\Association\HasOne::class,
'Awesome.Windows' => \Cake\ORM\Association\HasOne::class,
+ 'Controllers.Houses' => \Cake\ORM\Association\HasOne::class,
])
);
@@ -205,6 +211,7 @@ namespace PHPSTORM_META {
'Wheels' => \App\Model\Table\WheelsTable::class,
'Awesome.Houses' => \Awesome\Model\Table\HousesTable::class,
'Awesome.Windows' => \Awesome\Model\Table\WindowsTable::class,
+ 'Controllers.Houses' => \Controllers\Model\Table\HousesTable::class,
])
);

Add test for plugin controller annotations