diff --git a/bundle/src/Testing/BaseTestingTrait.php b/bundle/src/Testing/BaseTestingTrait.php index ca40f10..df89da8 100644 --- a/bundle/src/Testing/BaseTestingTrait.php +++ b/bundle/src/Testing/BaseTestingTrait.php @@ -7,10 +7,12 @@ use Hyvor\Internal\Bundle\Comms\MockComms; use Hyvor\Internal\Bundle\EventDispatcher\TestEventDispatcher; use Monolog\Handler\TestHandler; +use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Messenger\MessageBusInterface; use Zenstruck\Foundry\Test\Factories; use Zenstruck\Messenger\Test\InteractsWithMessenger; +use Symfony\Bundle\FrameworkBundle\Console\Application; trait BaseTestingTrait { @@ -73,4 +75,12 @@ public function setEnvVar(string $key, string $value): void $_ENV[$key] = $value; } + public function getCommandTester(string $command): CommandTester + { + assert(self::$kernel !== null); + $application = new Application(self::$kernel); + $command = $application->find($command); + return new CommandTester($command); + } + } diff --git a/tests/Bundle/Testing/ApiTestingTraitTest.php b/tests/Bundle/Testing/ApiTestingTraitTest.php index d32196f..c506215 100644 --- a/tests/Bundle/Testing/ApiTestingTraitTest.php +++ b/tests/Bundle/Testing/ApiTestingTraitTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\BrowserKit\AbstractBrowser; use Symfony\Component\DependencyInjection\Container; +use Symfony\Component\HttpKernel\KernelInterface; class ApiTestingTraitTest extends TestCase { @@ -15,6 +16,7 @@ class ApiTestingTraitTest extends TestCase private static int $status; public Container $container; + public static ?KernelInterface $kernel = null; /** * @param array $json