Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions bundle/src/Testing/BaseTestingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}

}
2 changes: 2 additions & 0 deletions tests/Bundle/Testing/ApiTestingTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -15,6 +16,7 @@ class ApiTestingTraitTest extends TestCase
private static int $status;

public Container $container;
public static ?KernelInterface $kernel = null;

/**
* @param array<mixed> $json
Expand Down