From 690c9d75fd47f5d37cc233af30b28afe96abbdcf Mon Sep 17 00:00:00 2001 From: mscherer Date: Thu, 7 Sep 2017 17:19:24 +0200 Subject: [PATCH 1/2] Add Trait metas, too. --- src/Generator/PhpstormGenerator.php | 5 ++-- src/Generator/Task/ModelTask.php | 16 ++++++++++- .../TestCase/Generator/Task/ModelTaskTest.php | 26 ++++++++--------- tests/test_files/meta/phpstorm/.meta.php | 28 +++++++++++++++++++ 4 files changed, 59 insertions(+), 16 deletions(-) diff --git a/src/Generator/PhpstormGenerator.php b/src/Generator/PhpstormGenerator.php index 2781f897..0c25adbb 100644 --- a/src/Generator/PhpstormGenerator.php +++ b/src/Generator/PhpstormGenerator.php @@ -33,11 +33,11 @@ public function generate() { * @return string */ protected function build(array $map) { - $overrides = ''; + $overrides = []; foreach ($map as $method => $array) { $mapDefinitions = $this->buildMapDefinitions($array); - $overrides .= << $map]; + $result = []; + foreach ($this->aliases as $alias) { + $result[$alias] = $map; + } + + return $result; } /** diff --git a/tests/TestCase/Generator/Task/ModelTaskTest.php b/tests/TestCase/Generator/Task/ModelTaskTest.php index 11c84064..4da86bac 100644 --- a/tests/TestCase/Generator/Task/ModelTaskTest.php +++ b/tests/TestCase/Generator/Task/ModelTaskTest.php @@ -27,20 +27,20 @@ public function setUp() { public function testCollect() { $result = $this->task->collect(); - $expected = [ - '\Cake\ORM\TableRegistry::get(0)' => [ - 'BarBars' => '\App\Model\Table\BarBarsTable::class', - 'Cars' => '\App\Model\Table\CarsTable::class', - 'Exceptions' => '\App\Model\Table\ExceptionsTable::class', - 'Foo' => '\App\Model\Table\FooTable::class', - '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' - ] + $this->assertCount(3, $result); + + $expectedMap = [ + 'BarBars' => '\App\Model\Table\BarBarsTable::class', + 'Cars' => '\App\Model\Table\CarsTable::class', + 'Exceptions' => '\App\Model\Table\ExceptionsTable::class', + 'Foo' => '\App\Model\Table\FooTable::class', + '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' ]; - - $this->assertSame($result, $expected); + $map = array_shift($result); + $this->assertSame($expectedMap, $map); } } diff --git a/tests/test_files/meta/phpstorm/.meta.php b/tests/test_files/meta/phpstorm/.meta.php index e3dfb056..c5d13181 100644 --- a/tests/test_files/meta/phpstorm/.meta.php +++ b/tests/test_files/meta/phpstorm/.meta.php @@ -16,4 +16,32 @@ ]) ); + override( + \Cake\ORM\Locator\LocatorInterface::get(0), + map([ + 'BarBars' => \App\Model\Table\BarBarsTable::class, + 'Cars' => \App\Model\Table\CarsTable::class, + 'Exceptions' => \App\Model\Table\ExceptionsTable::class, + 'Foo' => \App\Model\Table\FooTable::class, + '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, + ]) + ); + + override( + \Cake\Datasource\ModelAwareTrait::loadModel(0), + map([ + 'BarBars' => \App\Model\Table\BarBarsTable::class, + 'Cars' => \App\Model\Table\CarsTable::class, + 'Exceptions' => \App\Model\Table\ExceptionsTable::class, + 'Foo' => \App\Model\Table\FooTable::class, + '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, + ]) + ); + } From 52b6605570725275e04317cd228836eec2e7570f Mon Sep 17 00:00:00 2001 From: mscherer Date: Thu, 7 Sep 2017 19:29:11 +0200 Subject: [PATCH 2/2] Docs. --- docs/Generator.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/Generator.md b/docs/Generator.md index fdeffd22..84c4b79f 100644 --- a/docs/Generator.md +++ b/docs/Generator.md @@ -19,6 +19,8 @@ With the generated meta file this becomes not necessary anymore. It will automatically detect this static factory call in the map and hint `$users` as `\App\Model\Table\UsersTable`, making `doSomething()` available in the IDE for method argument checking and following. +This task also annotates the dynamic model factory calls (e.g. `$this->getTableLocator()->get('Users')`). + ### Adding your own tasks Just create your own Task class: ```php