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.
This commit is contained in:
Markus Podar
2020-08-25 06:29:44 +02:00
committed by GitHub
parent 1ad23fd14c
commit ac6fbffac3
18 changed files with 24 additions and 22 deletions
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
}
+1 -1
View File
@@ -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);
}
}
+1 -1
View File
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
}
+4
View File
@@ -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);