From ee7b0cf6bd7b6ecb7e6dbcbd14e45f1d76da8c81 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Mar 2026 10:22:21 +0000 Subject: [PATCH] Add tests for PHP class attribute placement and fix whitespace in regex Co-authored-by: barryvdh <973269+barryvdh@users.noreply.github.com> --- .gitignore | 1 + src/Console/ModelsCommand.php | 2 +- .../Models/Simple.php | 12 ++++++++++ .../PhpAttributesBeforeClass/Test.php | 24 +++++++++++++++++++ .../__snapshots__/Test__test__1.php | 20 ++++++++++++++++ 5 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 tests/Console/ModelsCommand/PhpAttributesBeforeClass/Models/Simple.php create mode 100644 tests/Console/ModelsCommand/PhpAttributesBeforeClass/Test.php create mode 100644 tests/Console/ModelsCommand/PhpAttributesBeforeClass/__snapshots__/Test__test__1.php diff --git a/.gitignore b/.gitignore index 0cdbc31..71de373 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .phpunit.result.cache +/auth.json /build /.idea /.php-cs-fixer.cache diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index 757c3d7..9c65627 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -1206,7 +1206,7 @@ class ModelsCommand extends Command // declaration, insert the docblock before the first attribute so that // the resulting order is: docblock → attributes → class. $before = substr($contents, 0, $pos); - if (preg_match('/(\s*(?:#\[.+?\]\s*)+)$/s', $before, $matches)) { + if (preg_match('/((?:#\[.+?\]\s*)+)$/s', $before, $matches)) { $pos -= strlen($matches[1]); $replace = "{$modelDocComment}\n"; } diff --git a/tests/Console/ModelsCommand/PhpAttributesBeforeClass/Models/Simple.php b/tests/Console/ModelsCommand/PhpAttributesBeforeClass/Models/Simple.php new file mode 100644 index 0000000..9412ace --- /dev/null +++ b/tests/Console/ModelsCommand/PhpAttributesBeforeClass/Models/Simple.php @@ -0,0 +1,12 @@ +app->make(ModelsCommand::class); + + $tester = $this->runCommand($command, [ + '--write' => true, + ]); + + $this->assertSame(0, $tester->getStatusCode()); + $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); + $this->assertMatchesMockedSnapshot(); + } +} diff --git a/tests/Console/ModelsCommand/PhpAttributesBeforeClass/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/PhpAttributesBeforeClass/__snapshots__/Test__test__1.php new file mode 100644 index 0000000..d8870f4 --- /dev/null +++ b/tests/Console/ModelsCommand/PhpAttributesBeforeClass/__snapshots__/Test__test__1.php @@ -0,0 +1,20 @@ +|Simple newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|Simple query() + * @method static \Illuminate\Database\Eloquent\Builder|Simple whereId($value) + * @mixin \Eloquent + */ +#[\AllowDynamicProperties] +class Simple extends Model +{ +}