Support other OS on tests (#1715)

This commit is contained in:
erikn69
2025-07-17 07:52:32 +02:00
committed by GitHub
parent cff244b9b5
commit 6d96f0bd1a
7 changed files with 33 additions and 60 deletions
@@ -27,9 +27,4 @@ abstract class AbstractGeneratorCommand extends TestCase
{
return [IdeHelperServiceProvider::class];
}
protected function assertMatchesMockedSnapshot()
{
$this->assertMatchesSnapshot($this->mockFilesystemOutput, new SnapshotPhpDriver());
}
}
@@ -52,9 +52,4 @@ abstract class AbstractModelsCommand extends TestCase
// Don't override integer -> int for tests
$config->set('ide-helper.type_overrides', []);
}
protected function assertMatchesMockedSnapshot()
{
$this->assertMatchesSnapshot($this->mockFilesystemOutput, new SnapshotPhpDriver());
}
}
@@ -34,24 +34,6 @@ class Test extends AbstractModelsCommand
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 @@ class Test extends AbstractModelsCommand
$this->assertSame(0, $tester->getStatusCode());
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
$expectedContent = <<<'PHP'
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ModelHooks\Models;
use Illuminate\Database\Eloquent\Model;
/**
*
*
* @property int $id
* @property-read string $custom
* @method static \Illuminate\Database\Eloquent\Builder<static>|Simple custom($custom)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Simple newQuery()
* @method static \Illuminate\Database\Eloquent\Builder<static>|Simple query()
* @method static \Illuminate\Database\Eloquent\Builder<static>|Simple whereId($value)
* @mixin \Eloquent
*/
class Simple extends Model
{
}
PHP;
$this->assertSame($expectedContent, $actualContent);
$this->assertMatchesMockedSnapshot();
}
}
@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ModelHooks\Models;
use Illuminate\Database\Eloquent\Model;
/**
*
*
* @property int $id
* @property-read string $custom
* @method static \Illuminate\Database\Eloquent\Builder<static>|Simple custom($custom)
* @method static \Illuminate\Database\Eloquent\Builder<static>|Simple newQuery()
* @method static \Illuminate\Database\Eloquent\Builder<static>|Simple query()
* @method static \Illuminate\Database\Eloquent\Builder<static>|Simple whereId($value)
* @mixin \Eloquent
*/
class Simple extends Model
{
}
+2 -2
View File
@@ -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 @@ class SnapshotPhpDriver implements Driver
public function match($expected, $actual)
{
Assert::assertSame($expected, $this->serialize($actual));
Assert::assertSame(str_replace(["\r\n", "\r"], "\n", $expected), $this->serialize($actual));
}
}
+2 -2
View File
@@ -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 @@ class SnapshotTxtDriver implements Driver
public function match($expected, $actual)
{
Assert::assertSame($expected, $this->serialize($actual));
Assert::assertSame(str_replace(["\r\n", "\r"], "\n", $expected), $this->serialize($actual));
}
}
+6
View File
@@ -55,6 +55,11 @@ abstract class TestCase extends BaseTestCase
$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 @@ abstract class TestCase extends BaseTestCase
Mockery::any()
)
->andReturnUsing(function ($path, $contents) {
$contents = str_replace(["\r\n", "\r"], "\n", $contents);
$this->mockFilesystemOutput .= $contents;
return strlen($contents);