Skip to content

Support other OS on tests #1715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions tests/Console/GeneratorCommand/AbstractGeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,4 @@ protected function getPackageProviders($app)
{
return [IdeHelperServiceProvider::class];
}

protected function assertMatchesMockedSnapshot()
{
$this->assertMatchesSnapshot($this->mockFilesystemOutput, new SnapshotPhpDriver());
}
}
5 changes: 0 additions & 5 deletions tests/Console/ModelsCommand/AbstractModelsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
47 changes: 1 addition & 46 deletions tests/Console/ModelsCommand/ModelHooks/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, [
Expand All @@ -60,33 +42,6 @@ public function test(): void

$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();
}
}
Original file line number Diff line number Diff line change
@@ -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
{
}
4 changes: 2 additions & 2 deletions tests/SnapshotPhpDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
}
}
4 changes: 2 additions & 2 deletions tests/SnapshotTxtDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
}
}
6 changes: 6 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
Loading