Skip to content

Commit 6d96f0b

Browse files
authored
Support other OS on tests (#1715)
1 parent cff244b commit 6d96f0b

File tree

7 files changed

+33
-60
lines changed

7 files changed

+33
-60
lines changed

tests/Console/GeneratorCommand/AbstractGeneratorCommand.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,4 @@ protected function getPackageProviders($app)
2727
{
2828
return [IdeHelperServiceProvider::class];
2929
}
30-
31-
protected function assertMatchesMockedSnapshot()
32-
{
33-
$this->assertMatchesSnapshot($this->mockFilesystemOutput, new SnapshotPhpDriver());
34-
}
3530
}

tests/Console/ModelsCommand/AbstractModelsCommand.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,4 @@ protected function getEnvironmentSetUp($app)
5252
// Don't override integer -> int for tests
5353
$config->set('ide-helper.type_overrides', []);
5454
}
55-
56-
protected function assertMatchesMockedSnapshot()
57-
{
58-
$this->assertMatchesSnapshot($this->mockFilesystemOutput, new SnapshotPhpDriver());
59-
}
6055
}

tests/Console/ModelsCommand/ModelHooks/Test.php

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,6 @@ protected function getEnvironmentSetUp($app)
3434

3535
public function test(): void
3636
{
37-
$actualContent = null;
38-
39-
$mockFilesystem = Mockery::mock(Filesystem::class)->makePartial();
40-
$mockFilesystem
41-
->shouldReceive('get')
42-
->andReturn(file_get_contents(__DIR__ . '/Models/Simple.php'))
43-
->once();
44-
$mockFilesystem
45-
->shouldReceive('put')
46-
->with(
47-
Mockery::any(),
48-
Mockery::capture($actualContent)
49-
)
50-
->andReturn(1) // Simulate we wrote _something_ to the file
51-
->once();
52-
53-
$this->instance(Filesystem::class, $mockFilesystem);
54-
5537
$command = $this->app->make(ModelsCommand::class);
5638

5739
$tester = $this->runCommand($command, [
@@ -60,33 +42,6 @@ public function test(): void
6042

6143
$this->assertSame(0, $tester->getStatusCode());
6244
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
63-
64-
$expectedContent = <<<'PHP'
65-
<?php
66-
67-
declare(strict_types=1);
68-
69-
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ModelHooks\Models;
70-
71-
use Illuminate\Database\Eloquent\Model;
72-
73-
/**
74-
*
75-
*
76-
* @property int $id
77-
* @property-read string $custom
78-
* @method static \Illuminate\Database\Eloquent\Builder<static>|Simple custom($custom)
79-
* @method static \Illuminate\Database\Eloquent\Builder<static>|Simple newQuery()
80-
* @method static \Illuminate\Database\Eloquent\Builder<static>|Simple query()
81-
* @method static \Illuminate\Database\Eloquent\Builder<static>|Simple whereId($value)
82-
* @mixin \Eloquent
83-
*/
84-
class Simple extends Model
85-
{
86-
}
87-
88-
PHP;
89-
90-
$this->assertSame($expectedContent, $actualContent);
45+
$this->assertMatchesMockedSnapshot();
9146
}
9247
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ModelHooks\Models;
6+
7+
use Illuminate\Database\Eloquent\Model;
8+
9+
/**
10+
*
11+
*
12+
* @property int $id
13+
* @property-read string $custom
14+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Simple custom($custom)
15+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Simple newQuery()
16+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Simple query()
17+
* @method static \Illuminate\Database\Eloquent\Builder<static>|Simple whereId($value)
18+
* @mixin \Eloquent
19+
*/
20+
class Simple extends Model
21+
{
22+
}

tests/SnapshotPhpDriver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class SnapshotPhpDriver implements Driver
1111
{
1212
public function serialize($data): string
1313
{
14-
return (string) $data;
14+
return str_replace(["\r\n", "\r"], "\n", (string) $data);
1515
}
1616

1717
public function extension(): string
@@ -21,6 +21,6 @@ public function extension(): string
2121

2222
public function match($expected, $actual)
2323
{
24-
Assert::assertSame($expected, $this->serialize($actual));
24+
Assert::assertSame(str_replace(["\r\n", "\r"], "\n", $expected), $this->serialize($actual));
2525
}
2626
}

tests/SnapshotTxtDriver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class SnapshotTxtDriver implements Driver
1111
{
1212
public function serialize($data): string
1313
{
14-
return (string) $data;
14+
return str_replace(["\r\n", "\r"], "\n", (string) $data);
1515
}
1616

1717
public function extension(): string
@@ -21,6 +21,6 @@ public function extension(): string
2121

2222
public function match($expected, $actual)
2323
{
24-
Assert::assertSame($expected, $this->serialize($actual));
24+
Assert::assertSame(str_replace(["\r\n", "\r"], "\n", $expected), $this->serialize($actual));
2525
}
2626
}

tests/TestCase.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ protected function assertMatchesTxtSnapshot(?string $actualContent)
5555
$this->assertMatchesSnapshot($actualContent, new SnapshotTxtDriver());
5656
}
5757

58+
protected function assertMatchesMockedSnapshot()
59+
{
60+
$this->assertMatchesSnapshot($this->mockFilesystemOutput, new SnapshotPhpDriver());
61+
}
62+
5863
protected function mockFilesystem()
5964
{
6065
$mockFilesystem = Mockery::mock(Filesystem::class)->makePartial();
@@ -66,6 +71,7 @@ protected function mockFilesystem()
6671
Mockery::any()
6772
)
6873
->andReturnUsing(function ($path, $contents) {
74+
$contents = str_replace(["\r\n", "\r"], "\n", $contents);
6975
$this->mockFilesystemOutput .= $contents;
7076

7177
return strlen($contents);

0 commit comments

Comments
 (0)