From 07d45d2d7a13f3e0345c37062c25103f222539dc Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Wed, 24 Jun 2020 11:11:35 +0200 Subject: [PATCH] switch tests to snapshot assertions (#958) * install spatie/phpunit-snapshot-assertions * switch GenerateBasicPhpdocFinal test to snapshot assertion * use v3 of spatie/phpunit-snapshot-assertions to be PHP7.2 compatible * add txt snapshot driver * fix EloquentCommandTest * replace all heredocs by snapshots * make test compatible with old/deprecated versions * Update composer.json * normalize composer.json * fix merge conflict * Allow older snapshot versions * normalize composer.json Co-authored-by: Barry vd. Heuvel Co-authored-by: barryvdh --- composer.json | 7 +- tests/Console/EloquentCommandTest.php | 20 +- .../ModelsCommand/CustomCollection/Test.php | 41 +--- .../__snapshots__/Test__test__1.php | 34 +++ .../Console/ModelsCommand/CustomDate/Test.php | 28 +-- .../__snapshots__/Test__test__1.php | 21 ++ .../GenerateBasicPhpdoc/Test.php | 170 +-------------- .../__snapshots__/Test__test__1.php | 163 ++++++++++++++ .../GenerateBasicPhpdocCamel/Test.php | 170 +-------------- .../__snapshots__/Test__test__1.php | 163 ++++++++++++++ .../GenerateBasicPhpdocFinal/Test.php | 172 +-------------- .../__snapshots__/Test__test__1.php | 163 ++++++++++++++ .../GeneratePhpdocWithFqn/Test.php | 201 +----------------- .../__snapshots__/Test__test__1.php | 194 +++++++++++++++++ tests/Console/ModelsCommand/Getter/Test.php | 141 +----------- .../Getter/__snapshots__/Test__test__1.php | 134 ++++++++++++ tests/Console/ModelsCommand/Ignored/Test.php | 24 +-- .../Ignored/__snapshots__/Test__test__1.php | 17 ++ .../Console/ModelsCommand/Interfaces/Test.php | 30 +-- .../__snapshots__/Test__test__1.php | 23 ++ .../ModelsCommand/LaravelCustomCasts/Test.php | 54 +---- ..._parses_casted_properties_correctly__1.php | 47 ++++ .../PHPStormNoInspection/Test.php | 54 +---- .../Test__testNoinspectionNotPresent__1.php | 19 ++ .../Test__testNoinspectionPresent__1.php | 21 ++ .../Console/ModelsCommand/Relations/Test.php | 121 +---------- .../Relations/__snapshots__/Test__test__1.php | 114 ++++++++++ .../ModelsCommand/ResetAndSmartReset/Test.php | 79 +------ .../__snapshots__/Test__testNoReset__1.php | 20 ++ .../__snapshots__/Test__testReset__1.php | 19 ++ .../__snapshots__/Test__testSmartReset__1.php | 19 ++ .../ModelsCommand/SoftDeletes/Test.php | 31 +-- .../__snapshots__/Test__test__1.php | 24 +++ .../EloquentCommandTest__testCommand__1.txt | 8 + tests/SnapshotPhpDriver.php | 24 +++ tests/SnapshotTxtDriver.php | 24 +++ tests/TestCase.php | 13 ++ 37 files changed, 1296 insertions(+), 1311 deletions(-) create mode 100644 tests/Console/ModelsCommand/CustomCollection/__snapshots__/Test__test__1.php create mode 100644 tests/Console/ModelsCommand/CustomDate/__snapshots__/Test__test__1.php create mode 100644 tests/Console/ModelsCommand/GenerateBasicPhpdoc/__snapshots__/Test__test__1.php create mode 100644 tests/Console/ModelsCommand/GenerateBasicPhpdocCamel/__snapshots__/Test__test__1.php create mode 100644 tests/Console/ModelsCommand/GenerateBasicPhpdocFinal/__snapshots__/Test__test__1.php create mode 100644 tests/Console/ModelsCommand/GeneratePhpdocWithFqn/__snapshots__/Test__test__1.php create mode 100644 tests/Console/ModelsCommand/Getter/__snapshots__/Test__test__1.php create mode 100644 tests/Console/ModelsCommand/Ignored/__snapshots__/Test__test__1.php create mode 100644 tests/Console/ModelsCommand/Interfaces/__snapshots__/Test__test__1.php create mode 100644 tests/Console/ModelsCommand/LaravelCustomCasts/__snapshots__/Test__test_it_parses_casted_properties_correctly__1.php create mode 100644 tests/Console/ModelsCommand/PHPStormNoInspection/__snapshots__/Test__testNoinspectionNotPresent__1.php create mode 100644 tests/Console/ModelsCommand/PHPStormNoInspection/__snapshots__/Test__testNoinspectionPresent__1.php create mode 100644 tests/Console/ModelsCommand/Relations/__snapshots__/Test__test__1.php create mode 100644 tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testNoReset__1.php create mode 100644 tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testReset__1.php create mode 100644 tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testSmartReset__1.php create mode 100644 tests/Console/ModelsCommand/SoftDeletes/__snapshots__/Test__test__1.php create mode 100644 tests/Console/__snapshots__/EloquentCommandTest__testCommand__1.txt create mode 100644 tests/SnapshotPhpDriver.php create mode 100644 tests/SnapshotTxtDriver.php diff --git a/composer.json b/composer.json index f338af2..7548c69 100644 --- a/composer.json +++ b/composer.json @@ -35,9 +35,13 @@ "mockery/mockery": "^1.3", "orchestra/testbench": "^3 || ^4 || ^5", "phpro/grumphp": "^0.19.0", + "spatie/phpunit-snapshot-assertions": "^1.4 || ^2.2 || ^3", "squizlabs/php_codesniffer": "^3.5", "vimeo/psalm": "^3.12" }, + "config": { + "sort-packages": true + }, "extra": { "branch-alias": { "dev-master": "2.6-dev" @@ -62,6 +66,7 @@ "analyze": "psalm", "check-style": "phpcs -p --standard=PSR12 src/", "fix-style": "phpcbf -p --standard=PSR12 src/", - "test": "phpunit" + "test": "phpunit", + "test-regenerate": "phpunit -d --update-snapshots" } } diff --git a/tests/Console/EloquentCommandTest.php b/tests/Console/EloquentCommandTest.php index 7baa5a9..63774dc 100644 --- a/tests/Console/EloquentCommandTest.php +++ b/tests/Console/EloquentCommandTest.php @@ -40,19 +40,17 @@ class EloquentCommandTest extends TestCase $tester = $this->runCommand($command); - $expectedContent = '/** - * - * - * @mixin \Eloquent - * @mixin \Illuminate\Database\Eloquent\Builder - * @mixin \Illuminate\Database\Query\Builder - */ -abstract class Model implements'; - $this->assertSame($expectedContent, $actualContent); + $this->assertMatchesTxtSnapshot($actualContent); $display = $tester->getDisplay(); - $this->assertRegExp(';Unexpected no document on Illuminate\\\Database\\\Eloquent\\\Model;', $display); - $this->assertRegExp(';Wrote expected docblock to .*/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php;', $display); + $this->assertRegExp( + ';Unexpected no document on Illuminate\\\Database\\\Eloquent\\\Model;', + $display + ); + $this->assertRegExp( + ';Wrote expected docblock to .*/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php;', + $display + ); } private function getVendorModelFilename(): string diff --git a/tests/Console/ModelsCommand/CustomCollection/Test.php b/tests/Console/ModelsCommand/CustomCollection/Test.php index d67e75c..aa81547 100644 --- a/tests/Console/ModelsCommand/CustomCollection/Test.php +++ b/tests/Console/ModelsCommand/CustomCollection/Test.php @@ -50,45 +50,6 @@ class Test extends AbstractModelsCommand $this->assertSame(0, $tester->getStatusCode()); $this->assertEmpty($tester->getDisplay()); - - $expectedContent = <<<'PHP' -hasMany(Simple::class); - } -} - -PHP; - - $this->assertSame($expectedContent, $actualContent); + $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/CustomCollection/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/CustomCollection/__snapshots__/Test__test__1.php new file mode 100644 index 0000000..c730904 --- /dev/null +++ b/tests/Console/ModelsCommand/CustomCollection/__snapshots__/Test__test__1.php @@ -0,0 +1,34 @@ +hasMany(Simple::class); + } +} diff --git a/tests/Console/ModelsCommand/CustomDate/Test.php b/tests/Console/ModelsCommand/CustomDate/Test.php index 370a445..bc89104 100644 --- a/tests/Console/ModelsCommand/CustomDate/Test.php +++ b/tests/Console/ModelsCommand/CustomDate/Test.php @@ -66,32 +66,6 @@ class Test extends AbstractModelsCommand $this->assertSame(0, $tester->getStatusCode()); $this->assertEmpty($tester->getDisplay()); - - $expectedContent = <<<'PHP' -assertSame($expectedContent, $actualContent); + $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/CustomDate/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/CustomDate/__snapshots__/Test__test__1.php new file mode 100644 index 0000000..900849e --- /dev/null +++ b/tests/Console/ModelsCommand/CustomDate/__snapshots__/Test__test__1.php @@ -0,0 +1,21 @@ +assertSame(0, $tester->getStatusCode()); $this->assertEmpty($tester->getDisplay()); - - $expectedContent = <<<'PHP' -assertSame($expectedContent, $actualContent); + $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/GenerateBasicPhpdoc/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/GenerateBasicPhpdoc/__snapshots__/Test__test__1.php new file mode 100644 index 0000000..7ea6080 --- /dev/null +++ b/tests/Console/ModelsCommand/GenerateBasicPhpdoc/__snapshots__/Test__test__1.php @@ -0,0 +1,163 @@ +assertSame(0, $tester->getStatusCode()); $this->assertEmpty($tester->getDisplay()); - - $expectedContent = <<<'PHP' -assertSame($expectedContent, $actualContent); + $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/GenerateBasicPhpdocCamel/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/GenerateBasicPhpdocCamel/__snapshots__/Test__test__1.php new file mode 100644 index 0000000..ddc0852 --- /dev/null +++ b/tests/Console/ModelsCommand/GenerateBasicPhpdocCamel/__snapshots__/Test__test__1.php @@ -0,0 +1,163 @@ +assertSame(0, $tester->getStatusCode()); $this->assertEmpty($tester->getDisplay()); - - $expectedContent = <<<'PHP' -assertSame($expectedContent, $actualContent); + $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/GenerateBasicPhpdocFinal/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/GenerateBasicPhpdocFinal/__snapshots__/Test__test__1.php new file mode 100644 index 0000000..5b225f8 --- /dev/null +++ b/tests/Console/ModelsCommand/GenerateBasicPhpdocFinal/__snapshots__/Test__test__1.php @@ -0,0 +1,163 @@ +assertSame(0, $tester->getStatusCode()); $this->assertEmpty($tester->getDisplay()); - - $expectedContent = <<<'PHP' - CastType::class, - ]; - - public function posts(): HasMany - { - return $this->hasMany(Post::class); - } - - public function scopeNull($query, string $unusedParam) - { - return $query; - } -} - -PHP; - - $this->assertSame($expectedContent, $actualContent); + $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/GeneratePhpdocWithFqn/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/GeneratePhpdocWithFqn/__snapshots__/Test__test__1.php new file mode 100644 index 0000000..baf3d5e --- /dev/null +++ b/tests/Console/ModelsCommand/GeneratePhpdocWithFqn/__snapshots__/Test__test__1.php @@ -0,0 +1,194 @@ + CastType::class, + ]; + + public function posts(): HasMany + { + return $this->hasMany(Post::class); + } + + public function scopeNull($query, string $unusedParam) + { + return $query; + } +} diff --git a/tests/Console/ModelsCommand/Getter/Test.php b/tests/Console/ModelsCommand/Getter/Test.php index a4553ac..888ac8e 100644 --- a/tests/Console/ModelsCommand/Getter/Test.php +++ b/tests/Console/ModelsCommand/Getter/Test.php @@ -49,145 +49,6 @@ class Test extends AbstractModelsCommand $this->assertSame(0, $tester->getStatusCode()); $this->assertEmpty($tester->getDisplay()); - - $expectedContent = <<<'PHP' -assertSame($expectedContent, $actualContent); + $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/Getter/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/Getter/__snapshots__/Test__test__1.php new file mode 100644 index 0000000..49fd7d4 --- /dev/null +++ b/tests/Console/ModelsCommand/Getter/__snapshots__/Test__test__1.php @@ -0,0 +1,134 @@ +assertSame(0, $tester->getStatusCode()); $this->assertEmpty($tester->getDisplay()); - - $expectedContent = <<<'PHP' -assertSame($expectedContent, $actualContent); + $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/Ignored/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/Ignored/__snapshots__/Test__test__1.php new file mode 100644 index 0000000..6445b4f --- /dev/null +++ b/tests/Console/ModelsCommand/Ignored/__snapshots__/Test__test__1.php @@ -0,0 +1,17 @@ +assertSame(0, $tester->getStatusCode()); $this->assertEmpty($tester->getDisplay()); - - $expectedContent = <<<'PHP' - - */ - - -namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Interfaces\Models{ -/** - * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Interfaces\Models\User - * - * @method static \Illuminate\Database\Eloquent\Builder|User newModelQuery() - * @method static \Illuminate\Database\Eloquent\Builder|User newQuery() - * @method static \Illuminate\Database\Eloquent\Builder|User query() - */ - class User extends \Eloquent implements \Illuminate\Contracts\Auth\Authenticatable {} -} - - -PHP; - - $this->assertSame($expectedContent, $actualContent); + $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/Interfaces/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/Interfaces/__snapshots__/Test__test__1.php new file mode 100644 index 0000000..c802ced --- /dev/null +++ b/tests/Console/ModelsCommand/Interfaces/__snapshots__/Test__test__1.php @@ -0,0 +1,23 @@ + + */ + + +namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Interfaces\Models{ +/** + * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Interfaces\Models\User + * + * @method static \Illuminate\Database\Eloquent\Builder|User newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|User newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|User query() + */ + class User extends \Eloquent implements \Illuminate\Contracts\Auth\Authenticatable {} +} + diff --git a/tests/Console/ModelsCommand/LaravelCustomCasts/Test.php b/tests/Console/ModelsCommand/LaravelCustomCasts/Test.php index 002d578..61a5c0d 100644 --- a/tests/Console/ModelsCommand/LaravelCustomCasts/Test.php +++ b/tests/Console/ModelsCommand/LaravelCustomCasts/Test.php @@ -60,58 +60,6 @@ class Test extends AbstractModelsCommand $this->assertSame(0, $tester->getStatusCode()); $this->assertEmpty($tester->getDisplay()); - - $expectedContent = <<<'PHP' - CustomCasterWithReturnType::class, - 'casted_property_with_return_docblock' => CustomCasterWithDocblockReturn::class, - 'casted_property_with_return_docblock_fqn' => CustomCasterWithDocblockReturnFqn::class, - 'casted_property_with_return_primitive' => CustomCasterWithPrimitiveReturn::class, - 'casted_property_with_return_primitive_docblock' => CustomCasterWithPrimitiveDocblockReturn::class, - 'casted_property_with_return_nullable_primitive' => CustomCasterWithNullablePrimitiveReturn::class, - 'casted_property_without_return' => CustomCasterWithoutReturnType::class, - ]; -} - -PHP; - - $this->assertSame($expectedContent, $actualContent); + $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/LaravelCustomCasts/__snapshots__/Test__test_it_parses_casted_properties_correctly__1.php b/tests/Console/ModelsCommand/LaravelCustomCasts/__snapshots__/Test__test_it_parses_casted_properties_correctly__1.php new file mode 100644 index 0000000..ec49d7b --- /dev/null +++ b/tests/Console/ModelsCommand/LaravelCustomCasts/__snapshots__/Test__test_it_parses_casted_properties_correctly__1.php @@ -0,0 +1,47 @@ + CustomCasterWithReturnType::class, + 'casted_property_with_return_docblock' => CustomCasterWithDocblockReturn::class, + 'casted_property_with_return_docblock_fqn' => CustomCasterWithDocblockReturnFqn::class, + 'casted_property_with_return_primitive' => CustomCasterWithPrimitiveReturn::class, + 'casted_property_with_return_primitive_docblock' => CustomCasterWithPrimitiveDocblockReturn::class, + 'casted_property_with_return_nullable_primitive' => CustomCasterWithNullablePrimitiveReturn::class, + 'casted_property_without_return' => CustomCasterWithoutReturnType::class, + ]; +} diff --git a/tests/Console/ModelsCommand/PHPStormNoInspection/Test.php b/tests/Console/ModelsCommand/PHPStormNoInspection/Test.php index 06eb817..c549705 100644 --- a/tests/Console/ModelsCommand/PHPStormNoInspection/Test.php +++ b/tests/Console/ModelsCommand/PHPStormNoInspection/Test.php @@ -50,31 +50,7 @@ class Test extends AbstractModelsCommand $this->assertSame(0, $tester->getStatusCode()); $this->assertEmpty($tester->getDisplay()); - - $expectedContent = <<<'PHP' -assertSame($expectedContent, $actualContent); + $this->assertMatchesPhpSnapshot($actualContent); } public function testNoinspectionPresent(): void @@ -105,32 +81,6 @@ PHP; $this->assertSame(0, $tester->getStatusCode()); $this->assertEmpty($tester->getDisplay()); - - $expectedContent = <<<'PHP' -assertSame($expectedContent, $actualContent); + $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/PHPStormNoInspection/__snapshots__/Test__testNoinspectionNotPresent__1.php b/tests/Console/ModelsCommand/PHPStormNoInspection/__snapshots__/Test__testNoinspectionNotPresent__1.php new file mode 100644 index 0000000..2a86e11 --- /dev/null +++ b/tests/Console/ModelsCommand/PHPStormNoInspection/__snapshots__/Test__testNoinspectionNotPresent__1.php @@ -0,0 +1,19 @@ +assertSame(0, $tester->getStatusCode()); $this->assertEmpty($tester->getDisplay()); - - $expectedContent = <<<'PHP' -hasMany(Simple::class); - } - - public function relationHasOne(): HasOne - { - return $this->hasOne(Simple::class); - } - - public function relationHasOneWithDefault(): HasOne - { - return $this->hasOne(Simple::class)->withDefault(); - } - - public function relationBelongsTo(): BelongsTo - { - return $this->belongsTo(Simple::class); - } - - public function relationBelongsToMany(): BelongsToMany - { - return $this->belongsToMany(Simple::class); - } - - public function relationBelongsToManyWithSub(): BelongsToMany - { - return $this->belongsToMany(Simple::class)->where('foo', 'bar'); - } - - public function relationBelongsToManyWithSubAnother(): BelongsToMany - { - return $this->relationBelongsToManyWithSub()->where('foo', 'bar'); - } - - public function relationMorphTo(): MorphTo - { - return $this->morphTo(); - } - - public function relationMorphOne(): MorphOne - { - return $this->morphOne(Simple::class, 'relationMorphTo'); - } - - public function relationMorphMany(): MorphMany - { - return $this->morphMany(Simple::class, 'relationMorphTo'); - } - - public function relationMorphedByMany(): MorphToMany - { - return $this->morphedByMany(Simple::class, 'foo'); - } - - // Custom relations - - public function relationBelongsToInAnotherNamespace(): BelongsTo - { - return $this->belongsTo(AnotherModel::class); - } - - public function relationBelongsToSameNameAsColumn(): BelongsTo - { - return $this->belongsTo(AnotherModel::class, __FUNCTION__); - } -} - -PHP; - - $this->assertSame($expectedContent, $actualContent); + $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/Relations/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/Relations/__snapshots__/Test__test__1.php new file mode 100644 index 0000000..4fbdba2 --- /dev/null +++ b/tests/Console/ModelsCommand/Relations/__snapshots__/Test__test__1.php @@ -0,0 +1,114 @@ +hasMany(Simple::class); + } + + public function relationHasOne(): HasOne + { + return $this->hasOne(Simple::class); + } + + public function relationHasOneWithDefault(): HasOne + { + return $this->hasOne(Simple::class)->withDefault(); + } + + public function relationBelongsTo(): BelongsTo + { + return $this->belongsTo(Simple::class); + } + + public function relationBelongsToMany(): BelongsToMany + { + return $this->belongsToMany(Simple::class); + } + + public function relationBelongsToManyWithSub(): BelongsToMany + { + return $this->belongsToMany(Simple::class)->where('foo', 'bar'); + } + + public function relationBelongsToManyWithSubAnother(): BelongsToMany + { + return $this->relationBelongsToManyWithSub()->where('foo', 'bar'); + } + + public function relationMorphTo(): MorphTo + { + return $this->morphTo(); + } + + public function relationMorphOne(): MorphOne + { + return $this->morphOne(Simple::class, 'relationMorphTo'); + } + + public function relationMorphMany(): MorphMany + { + return $this->morphMany(Simple::class, 'relationMorphTo'); + } + + public function relationMorphedByMany(): MorphToMany + { + return $this->morphedByMany(Simple::class, 'foo'); + } + + // Custom relations + + public function relationBelongsToInAnotherNamespace(): BelongsTo + { + return $this->belongsTo(AnotherModel::class); + } + + public function relationBelongsToSameNameAsColumn(): BelongsTo + { + return $this->belongsTo(AnotherModel::class, __FUNCTION__); + } +} diff --git a/tests/Console/ModelsCommand/ResetAndSmartReset/Test.php b/tests/Console/ModelsCommand/ResetAndSmartReset/Test.php index da3bd55..f8c86dc 100644 --- a/tests/Console/ModelsCommand/ResetAndSmartReset/Test.php +++ b/tests/Console/ModelsCommand/ResetAndSmartReset/Test.php @@ -49,32 +49,7 @@ class Test extends AbstractModelsCommand $this->assertSame(0, $tester->getStatusCode()); $this->assertEmpty($tester->getDisplay()); - - $expectedContent = <<<'PHP' -assertSame($expectedContent, $actualContent); + $this->assertMatchesPhpSnapshot($actualContent); } public function testReset(): void @@ -105,31 +80,7 @@ PHP; $this->assertSame(0, $tester->getStatusCode()); $this->assertEmpty($tester->getDisplay()); - - $expectedContent = <<<'PHP' -assertSame($expectedContent, $actualContent); + $this->assertMatchesPhpSnapshot($actualContent); } public function testSmartReset(): void @@ -160,30 +111,6 @@ PHP; $this->assertSame(0, $tester->getStatusCode()); $this->assertEmpty($tester->getDisplay()); - - $expectedContent = <<<'PHP' -assertSame($expectedContent, $actualContent); + $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testNoReset__1.php b/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testNoReset__1.php new file mode 100644 index 0000000..c6c1e7f --- /dev/null +++ b/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testNoReset__1.php @@ -0,0 +1,20 @@ +assertSame(0, $tester->getStatusCode()); $this->assertEmpty($tester->getDisplay()); - - $expectedContent = <<<'PHP' -assertSame($expectedContent, $actualContent); + $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/SoftDeletes/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/SoftDeletes/__snapshots__/Test__test__1.php new file mode 100644 index 0000000..cc93e30 --- /dev/null +++ b/tests/Console/ModelsCommand/SoftDeletes/__snapshots__/Test__test__1.php @@ -0,0 +1,24 @@ +serialize($actual)); + } +} diff --git a/tests/SnapshotTxtDriver.php b/tests/SnapshotTxtDriver.php new file mode 100644 index 0000000..5cabc00 --- /dev/null +++ b/tests/SnapshotTxtDriver.php @@ -0,0 +1,24 @@ +serialize($actual)); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index ae07f5e..0c7f82a 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -4,10 +4,13 @@ namespace Barryvdh\LaravelIdeHelper\Tests; use Illuminate\Console\Command; use Orchestra\Testbench\TestCase as BaseTestCase; +use Spatie\Snapshots\MatchesSnapshots; use Symfony\Component\Console\Tester\CommandTester; abstract class TestCase extends BaseTestCase { + use MatchesSnapshots; + /** * The `CommandTester` is directly returned, use methods like * `->getDisplay()` or `->getStatusCode()` on it. @@ -33,4 +36,14 @@ abstract class TestCase extends BaseTestCase return $tester; } + + protected function assertMatchesPhpSnapshot(?string $actualContent) + { + $this->assertMatchesSnapshot($actualContent, new SnapshotPhpDriver()); + } + + protected function assertMatchesTxtSnapshot(?string $actualContent) + { + $this->assertMatchesSnapshot($actualContent, new SnapshotTxtDriver()); + } }