From 27b876ce7cf340d3230fbc8c2151b9a53e4fd713 Mon Sep 17 00:00:00 2001 From: Sergio Date: Mon, 20 Jan 2020 13:17:48 +0100 Subject: [PATCH 1/2] Fix camelCase duplicated properties generator. --- src/Console/ModelsCommand.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index 2b0622bf0..c23075886 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -674,6 +674,11 @@ protected function createPhpDocs($class) foreach ($this->properties as $name => $property) { $name = "\$$name"; + + if ($this->hasCamelCaseModelProperties()) { + $name = Str::camel($name); + } + if (in_array($name, $properties)) { continue; } @@ -685,10 +690,6 @@ protected function createPhpDocs($class) $attr = 'property-read'; } - if ($this->hasCamelCaseModelProperties()) { - $name = Str::camel($name); - } - $tagLine = trim("@{$attr} {$property['type']} {$name} {$property['comment']}"); $tag = Tag::createInstance($tagLine, $phpdoc); $phpdoc->appendTag($tag); From 7ba047c1dfff90588c2e907198f5d968c5780e9c Mon Sep 17 00:00:00 2001 From: Sergio Date: Tue, 21 Jan 2020 16:08:37 +0100 Subject: [PATCH 2/2] Add basic tests for camel case --- .../GenerateBasicPhpdocCamel/Models/Post.php | 9 + .../GenerateBasicPhpdocCamel/Test.php | 224 ++++++++++++++++++ 2 files changed, 233 insertions(+) create mode 100644 tests/Console/ModelsCommand/GenerateBasicPhpdocCamel/Models/Post.php create mode 100644 tests/Console/ModelsCommand/GenerateBasicPhpdocCamel/Test.php diff --git a/tests/Console/ModelsCommand/GenerateBasicPhpdocCamel/Models/Post.php b/tests/Console/ModelsCommand/GenerateBasicPhpdocCamel/Models/Post.php new file mode 100644 index 000000000..23d219451 --- /dev/null +++ b/tests/Console/ModelsCommand/GenerateBasicPhpdocCamel/Models/Post.php @@ -0,0 +1,9 @@ +set('ide-helper', [ + 'model_locations' => [ + // This is calculated from the base_path() which points to + // vendor/orchestra/testbench-core/laravel + '/../../../../tests/Console/ModelsCommand/GenerateBasicPhpdocCamel/Models', + ], + // Activate the camel_case mode + 'model_camel_case_properties' => true, + ]); + } + + public function test(): void + { + $actualContent = null; + $mockFilesystem = Mockery::mock(Filesystem::class); + $mockFilesystem + ->shouldReceive('get') + ->andReturn(file_get_contents(__DIR__ . '/Models/Post.php')) + ->once(); + $mockFilesystem + ->shouldReceive('put') + ->with( + Mockery::any(), + Mockery::capture($actualContent) + ) + ->andReturn(1) // Simulate we wrote _something_ to the file + ->once(); + + $this->instance(Filesystem::class, $mockFilesystem); + + $command = $this->app->make(ModelsCommand::class); + + $tester = $this->runCommand($command, [ + '--write' => true, + ]); + + $this->assertSame(0, $tester->getStatusCode()); + $this->assertEmpty($tester->getDisplay()); + + $expectedContent = <<<'PHP' +assertSame($expectedContent, $actualContent); + } +}