mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-17 17:47:13 +00:00
Support other OS on tests (#1715)
This commit is contained in:
@@ -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
|
||||
{
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user