From ac6fbffac395161c792760f1ddc1885c7c3b755d Mon Sep 17 00:00:00 2001 From: Markus Podar Date: Tue, 25 Aug 2020 06:29:44 +0200 Subject: [PATCH] tests: ensure output mocking is disabled so we can actually catch the output (#1018) Discovered via https://github.com/barryvdh/laravel-ide-helper/pull/1017#issuecomment-679318764 This only happens if you run an artisan command _before_ `runCommand`, but since every of these tests performs migrations, using artisan, the mocked output instance is left behind and also affected us. The call added in `runCommand` explicitly unregisters `\Illuminate\Console\OutputStyle` and thus also throwing away possibly mocked versions. --- tests/Console/ModelsCommand/CustomCollection/Test.php | 2 +- tests/Console/ModelsCommand/CustomDate/Test.php | 2 +- tests/Console/ModelsCommand/GenerateBasicPhpdoc/Test.php | 2 +- .../Console/ModelsCommand/GenerateBasicPhpdocCamel/Test.php | 2 +- .../Console/ModelsCommand/GenerateBasicPhpdocFinal/Test.php | 2 +- tests/Console/ModelsCommand/GeneratePhpdocWithFqn/Test.php | 2 +- .../GeneratePhpdocWithFqnInExternalFile/Test.php | 2 +- tests/Console/ModelsCommand/Getter/Test.php | 2 +- tests/Console/ModelsCommand/Ignored/Test.php | 2 +- tests/Console/ModelsCommand/Interfaces/Test.php | 2 +- tests/Console/ModelsCommand/LaravelCustomCasts/Test.php | 2 +- tests/Console/ModelsCommand/MagicWhere/Test.php | 3 +-- tests/Console/ModelsCommand/PHPStormNoInspection/Test.php | 4 ++-- .../Console/ModelsCommand/RelationCountProperties/Test.php | 3 +-- tests/Console/ModelsCommand/Relations/Test.php | 2 +- tests/Console/ModelsCommand/ResetAndSmartReset/Test.php | 6 +++--- tests/Console/ModelsCommand/SoftDeletes/Test.php | 2 +- tests/TestCase.php | 4 ++++ 18 files changed, 24 insertions(+), 22 deletions(-) diff --git a/tests/Console/ModelsCommand/CustomCollection/Test.php b/tests/Console/ModelsCommand/CustomCollection/Test.php index bc753c1..fc5e98b 100644 --- a/tests/Console/ModelsCommand/CustomCollection/Test.php +++ b/tests/Console/ModelsCommand/CustomCollection/Test.php @@ -51,7 +51,7 @@ class Test extends AbstractModelsCommand ]); $this->assertSame(0, $tester->getStatusCode()); - $this->assertEmpty($tester->getDisplay()); + $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/CustomDate/Test.php b/tests/Console/ModelsCommand/CustomDate/Test.php index 3d6a733..b378df1 100644 --- a/tests/Console/ModelsCommand/CustomDate/Test.php +++ b/tests/Console/ModelsCommand/CustomDate/Test.php @@ -67,7 +67,7 @@ class Test extends AbstractModelsCommand ]); $this->assertSame(0, $tester->getStatusCode()); - $this->assertEmpty($tester->getDisplay()); + $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/GenerateBasicPhpdoc/Test.php b/tests/Console/ModelsCommand/GenerateBasicPhpdoc/Test.php index db786c1..72ff210 100644 --- a/tests/Console/ModelsCommand/GenerateBasicPhpdoc/Test.php +++ b/tests/Console/ModelsCommand/GenerateBasicPhpdoc/Test.php @@ -50,7 +50,7 @@ class Test extends AbstractModelsCommand ]); $this->assertSame(0, $tester->getStatusCode()); - $this->assertEmpty($tester->getDisplay()); + $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/GenerateBasicPhpdocCamel/Test.php b/tests/Console/ModelsCommand/GenerateBasicPhpdocCamel/Test.php index 21a5442..b43318f 100644 --- a/tests/Console/ModelsCommand/GenerateBasicPhpdocCamel/Test.php +++ b/tests/Console/ModelsCommand/GenerateBasicPhpdocCamel/Test.php @@ -52,7 +52,7 @@ class Test extends AbstractModelsCommand ]); $this->assertSame(0, $tester->getStatusCode()); - $this->assertEmpty($tester->getDisplay()); + $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/GenerateBasicPhpdocFinal/Test.php b/tests/Console/ModelsCommand/GenerateBasicPhpdocFinal/Test.php index fb5e3b7..d162bf8 100644 --- a/tests/Console/ModelsCommand/GenerateBasicPhpdocFinal/Test.php +++ b/tests/Console/ModelsCommand/GenerateBasicPhpdocFinal/Test.php @@ -50,7 +50,7 @@ class Test extends AbstractModelsCommand ]); $this->assertSame(0, $tester->getStatusCode()); - $this->assertEmpty($tester->getDisplay()); + $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/GeneratePhpdocWithFqn/Test.php b/tests/Console/ModelsCommand/GeneratePhpdocWithFqn/Test.php index 93a254e..aa33da2 100644 --- a/tests/Console/ModelsCommand/GeneratePhpdocWithFqn/Test.php +++ b/tests/Console/ModelsCommand/GeneratePhpdocWithFqn/Test.php @@ -54,7 +54,7 @@ class Test extends AbstractModelsCommand ]); $this->assertSame(0, $tester->getStatusCode()); - $this->assertEmpty($tester->getDisplay()); + $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/GeneratePhpdocWithFqnInExternalFile/Test.php b/tests/Console/ModelsCommand/GeneratePhpdocWithFqnInExternalFile/Test.php index 45a8d17..3742a05 100644 --- a/tests/Console/ModelsCommand/GeneratePhpdocWithFqnInExternalFile/Test.php +++ b/tests/Console/ModelsCommand/GeneratePhpdocWithFqnInExternalFile/Test.php @@ -50,7 +50,7 @@ class Test extends AbstractModelsCommand ]); $this->assertSame(0, $tester->getStatusCode()); - $this->assertEmpty($tester->getDisplay()); + $this->assertStringContainsString('Model information was written to _ide_helper_models.php', $tester->getDisplay()); $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/Getter/Test.php b/tests/Console/ModelsCommand/Getter/Test.php index 9718248..4f7e7f9 100644 --- a/tests/Console/ModelsCommand/Getter/Test.php +++ b/tests/Console/ModelsCommand/Getter/Test.php @@ -50,7 +50,7 @@ class Test extends AbstractModelsCommand ]); $this->assertSame(0, $tester->getStatusCode()); - $this->assertEmpty($tester->getDisplay()); + $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/Ignored/Test.php b/tests/Console/ModelsCommand/Ignored/Test.php index 2b2690b..7c2f58e 100644 --- a/tests/Console/ModelsCommand/Ignored/Test.php +++ b/tests/Console/ModelsCommand/Ignored/Test.php @@ -55,7 +55,7 @@ class Test extends AbstractModelsCommand ]); $this->assertSame(0, $tester->getStatusCode()); - $this->assertEmpty($tester->getDisplay()); + $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/Interfaces/Test.php b/tests/Console/ModelsCommand/Interfaces/Test.php index 16d4cc5..043e765 100644 --- a/tests/Console/ModelsCommand/Interfaces/Test.php +++ b/tests/Console/ModelsCommand/Interfaces/Test.php @@ -47,7 +47,7 @@ final class Test extends AbstractModelsCommand ]); $this->assertSame(0, $tester->getStatusCode()); - $this->assertEmpty($tester->getDisplay()); + $this->assertStringContainsString('Model information was written to _ide_helper_models.php', $tester->getDisplay()); $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/LaravelCustomCasts/Test.php b/tests/Console/ModelsCommand/LaravelCustomCasts/Test.php index aab21b9..e8baa7a 100644 --- a/tests/Console/ModelsCommand/LaravelCustomCasts/Test.php +++ b/tests/Console/ModelsCommand/LaravelCustomCasts/Test.php @@ -61,7 +61,7 @@ class Test extends AbstractModelsCommand ]); $this->assertSame(0, $tester->getStatusCode()); - $this->assertEmpty($tester->getDisplay()); + $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/MagicWhere/Test.php b/tests/Console/ModelsCommand/MagicWhere/Test.php index 630be57..d996cfb 100644 --- a/tests/Console/ModelsCommand/MagicWhere/Test.php +++ b/tests/Console/ModelsCommand/MagicWhere/Test.php @@ -51,8 +51,7 @@ class Test extends AbstractModelsCommand ]); $this->assertSame(0, $tester->getStatusCode()); - $this->assertEmpty($tester->getDisplay()); - + $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/PHPStormNoInspection/Test.php b/tests/Console/ModelsCommand/PHPStormNoInspection/Test.php index 4783f2f..fc32a7d 100644 --- a/tests/Console/ModelsCommand/PHPStormNoInspection/Test.php +++ b/tests/Console/ModelsCommand/PHPStormNoInspection/Test.php @@ -52,7 +52,7 @@ class Test extends AbstractModelsCommand ]); $this->assertSame(0, $tester->getStatusCode()); - $this->assertEmpty($tester->getDisplay()); + $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); $this->assertMatchesPhpSnapshot($actualContent); } @@ -83,7 +83,7 @@ class Test extends AbstractModelsCommand ]); $this->assertSame(0, $tester->getStatusCode()); - $this->assertEmpty($tester->getDisplay()); + $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/RelationCountProperties/Test.php b/tests/Console/ModelsCommand/RelationCountProperties/Test.php index ce06e42..1e923b0 100644 --- a/tests/Console/ModelsCommand/RelationCountProperties/Test.php +++ b/tests/Console/ModelsCommand/RelationCountProperties/Test.php @@ -53,8 +53,7 @@ class Test extends AbstractModelsCommand ]); $this->assertSame(0, $tester->getStatusCode()); - $this->assertEmpty($tester->getDisplay()); - + $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/Relations/Test.php b/tests/Console/ModelsCommand/Relations/Test.php index a7e30b5..6e6b5b8 100644 --- a/tests/Console/ModelsCommand/Relations/Test.php +++ b/tests/Console/ModelsCommand/Relations/Test.php @@ -50,7 +50,7 @@ class Test extends AbstractModelsCommand ]); $this->assertSame(0, $tester->getStatusCode()); - $this->assertEmpty($tester->getDisplay()); + $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/ResetAndSmartReset/Test.php b/tests/Console/ModelsCommand/ResetAndSmartReset/Test.php index d5ce7c7..7876b10 100644 --- a/tests/Console/ModelsCommand/ResetAndSmartReset/Test.php +++ b/tests/Console/ModelsCommand/ResetAndSmartReset/Test.php @@ -50,7 +50,7 @@ class Test extends AbstractModelsCommand ]); $this->assertSame(0, $tester->getStatusCode()); - $this->assertEmpty($tester->getDisplay()); + $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); $this->assertMatchesPhpSnapshot($actualContent); } @@ -81,7 +81,7 @@ class Test extends AbstractModelsCommand ]); $this->assertSame(0, $tester->getStatusCode()); - $this->assertEmpty($tester->getDisplay()); + $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); $this->assertMatchesPhpSnapshot($actualContent); } @@ -112,7 +112,7 @@ class Test extends AbstractModelsCommand ]); $this->assertSame(0, $tester->getStatusCode()); - $this->assertEmpty($tester->getDisplay()); + $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/Console/ModelsCommand/SoftDeletes/Test.php b/tests/Console/ModelsCommand/SoftDeletes/Test.php index de59601..578f0cb 100644 --- a/tests/Console/ModelsCommand/SoftDeletes/Test.php +++ b/tests/Console/ModelsCommand/SoftDeletes/Test.php @@ -50,7 +50,7 @@ class Test extends AbstractModelsCommand ]); $this->assertSame(0, $tester->getStatusCode()); - $this->assertEmpty($tester->getDisplay()); + $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); $this->assertMatchesPhpSnapshot($actualContent); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 05f2caf..4cf87a9 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests; use Illuminate\Console\Command; +use Illuminate\Console\OutputStyle; use Orchestra\Testbench\TestCase as BaseTestCase; use Spatie\Snapshots\MatchesSnapshots; use Symfony\Component\Console\Tester\CommandTester; @@ -29,6 +30,9 @@ abstract class TestCase extends BaseTestCase */ protected function runCommand(Command $command, array $arguments = [], array $interactiveInput = []): CommandTester { + // TODO: once Laravel 5.5 is dropped, call `$this->withoutMockingConsoleOutput()` instead + $this->app->offsetUnset(OutputStyle::class); + $command->setLaravel($this->app); $tester = new CommandTester($command);