From c7347a23e05ac6fa6481be31ffb7d7affeb64d28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Andr=C3=A9?= Date: Wed, 8 Jan 2025 22:47:39 +0100 Subject: [PATCH] minor: Complete InteractsWithConsole test coverage (#25) Add a small test to get 100% coverage --- tests/UnitTest.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/UnitTest.php b/tests/UnitTest.php index 366d9d4..23ca3af 100644 --- a/tests/UnitTest.php +++ b/tests/UnitTest.php @@ -18,6 +18,7 @@ use Symfony\Component\Console\Helper\OutputWrapper; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\HttpKernel\Kernel; +use Zenstruck\Console\Test\InteractsWithConsole; use Zenstruck\Console\Test\TestCommand; use Zenstruck\Console\Test\Tests\Fixture\FixtureCommand; @@ -297,4 +298,27 @@ public function configure(): void ->complete('kevin --message=g')->is(['hello', 'hi', 'greetings'])->back() ; } + + /** + * @test + */ + public function trait_throws_when_not_in_kernel_test_case(): void + { + $testClass = new class { + use InteractsWithConsole; + + /** + * @test + */ + public function test(): void + { + $this->consoleCommand('my:command'); + } + }; + + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('The Zenstruck\Console\Test\InteractsWithConsole trait can only be used with Symfony\Bundle\FrameworkBundle\Test\KernelTestCase.'); + + (new $testClass())->test(); + } }