From f21133d3469a3461e9628a5f5543021d40afaa5f Mon Sep 17 00:00:00 2001 From: erikn69 Date: Tue, 20 May 2025 12:55:45 -0500 Subject: [PATCH] Support other OS on tests --- .../AbstractGeneratorCommand.php | 5 -- .../ModelsCommand/AbstractModelsCommand.php | 5 -- .../Console/ModelsCommand/ModelHooks/Test.php | 47 +------------------ .../__snapshots__/Test__test__1.php | 22 +++++++++ tests/SnapshotPhpDriver.php | 4 +- tests/SnapshotTxtDriver.php | 4 +- tests/TestCase.php | 6 +++ 7 files changed, 33 insertions(+), 60 deletions(-) create mode 100644 tests/Console/ModelsCommand/ModelHooks/__snapshots__/Test__test__1.php diff --git a/tests/Console/GeneratorCommand/AbstractGeneratorCommand.php b/tests/Console/GeneratorCommand/AbstractGeneratorCommand.php index b5dabd68d..b0cb449db 100644 --- a/tests/Console/GeneratorCommand/AbstractGeneratorCommand.php +++ b/tests/Console/GeneratorCommand/AbstractGeneratorCommand.php @@ -27,9 +27,4 @@ protected function getPackageProviders($app) { return [IdeHelperServiceProvider::class]; } - - protected function assertMatchesMockedSnapshot() - { - $this->assertMatchesSnapshot($this->mockFilesystemOutput, new SnapshotPhpDriver()); - } } diff --git a/tests/Console/ModelsCommand/AbstractModelsCommand.php b/tests/Console/ModelsCommand/AbstractModelsCommand.php index e52c9e680..a678b8329 100644 --- a/tests/Console/ModelsCommand/AbstractModelsCommand.php +++ b/tests/Console/ModelsCommand/AbstractModelsCommand.php @@ -52,9 +52,4 @@ protected function getEnvironmentSetUp($app) // Don't override integer -> int for tests $config->set('ide-helper.type_overrides', []); } - - protected function assertMatchesMockedSnapshot() - { - $this->assertMatchesSnapshot($this->mockFilesystemOutput, new SnapshotPhpDriver()); - } } diff --git a/tests/Console/ModelsCommand/ModelHooks/Test.php b/tests/Console/ModelsCommand/ModelHooks/Test.php index 1167ba508..a845e4718 100644 --- a/tests/Console/ModelsCommand/ModelHooks/Test.php +++ b/tests/Console/ModelsCommand/ModelHooks/Test.php @@ -34,24 +34,6 @@ protected function getEnvironmentSetUp($app) public function test(): void { - $actualContent = null; - - $mockFilesystem = Mockery::mock(Filesystem::class)->makePartial(); - $mockFilesystem - ->shouldReceive('get') - ->andReturn(file_get_contents(__DIR__ . '/Models/Simple.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, [ @@ -60,33 +42,6 @@ public function test(): void $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); - - $expectedContent = <<<'PHP' -|Simple custom($custom) - * @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 - */ -class Simple extends Model -{ -} - -PHP; - - $this->assertSame($expectedContent, $actualContent); + $this->assertMatchesMockedSnapshot(); } } diff --git a/tests/Console/ModelsCommand/ModelHooks/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/ModelHooks/__snapshots__/Test__test__1.php new file mode 100644 index 000000000..e3e55d2cc --- /dev/null +++ b/tests/Console/ModelsCommand/ModelHooks/__snapshots__/Test__test__1.php @@ -0,0 +1,22 @@ +|Simple custom($custom) + * @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 + */ +class Simple extends Model +{ +} diff --git a/tests/SnapshotPhpDriver.php b/tests/SnapshotPhpDriver.php index 2e69aab15..2be393e17 100644 --- a/tests/SnapshotPhpDriver.php +++ b/tests/SnapshotPhpDriver.php @@ -11,7 +11,7 @@ class SnapshotPhpDriver implements Driver { public function serialize($data): string { - return (string) $data; + return str_replace(["\r\n", "\r"], "\n", (string) $data); } public function extension(): string @@ -21,6 +21,6 @@ public function extension(): string public function match($expected, $actual) { - Assert::assertSame($expected, $this->serialize($actual)); + Assert::assertSame(str_replace(["\r\n", "\r"], "\n", $expected), $this->serialize($actual)); } } diff --git a/tests/SnapshotTxtDriver.php b/tests/SnapshotTxtDriver.php index 1bb194833..6d3a64468 100644 --- a/tests/SnapshotTxtDriver.php +++ b/tests/SnapshotTxtDriver.php @@ -11,7 +11,7 @@ class SnapshotTxtDriver implements Driver { public function serialize($data): string { - return (string) $data; + return str_replace(["\r\n", "\r"], "\n", (string) $data); } public function extension(): string @@ -21,6 +21,6 @@ public function extension(): string public function match($expected, $actual) { - Assert::assertSame($expected, $this->serialize($actual)); + Assert::assertSame(str_replace(["\r\n", "\r"], "\n", $expected), $this->serialize($actual)); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 554610d13..6a62d5c2d 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -55,6 +55,11 @@ protected function assertMatchesTxtSnapshot(?string $actualContent) $this->assertMatchesSnapshot($actualContent, new SnapshotTxtDriver()); } + protected function assertMatchesMockedSnapshot() + { + $this->assertMatchesSnapshot($this->mockFilesystemOutput, new SnapshotPhpDriver()); + } + protected function mockFilesystem() { $mockFilesystem = Mockery::mock(Filesystem::class)->makePartial(); @@ -66,6 +71,7 @@ protected function mockFilesystem() Mockery::any() ) ->andReturnUsing(function ($path, $contents) { + $contents = str_replace(["\r\n", "\r"], "\n", $contents); $this->mockFilesystemOutput .= $contents; return strlen($contents);