From 52c2af87d7460bc7c0253fb39c572849b14d1669 Mon Sep 17 00:00:00 2001 From: Damien Harper Date: Wed, 3 Jan 2024 22:08:28 +0100 Subject: [PATCH] Update test deps, fixes CI for 6.x --- composer.json | 2 +- tests/DHAuditorBundleTest.php | 72 ++++++++++++++++++++--------------- 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/composer.json b/composer.json index 5b348eef..38421d3d 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ "require-dev": { "gedmo/doctrine-extensions": "^2.4|^3.0", "matthiasnoback/symfony-dependency-injection-test": "^3.1|^4.0|^5.0", - "nyholm/symfony-bundle-test": "1.x-dev", + "nyholm/symfony-bundle-test": "^2.0|^3.0", "phpunit/phpunit": "^9.0", "symfony/browser-kit": "^5.4|^6.0|^7.0", "symfony/css-selector": "^5.4|^6.0|^7.0", diff --git a/tests/DHAuditorBundleTest.php b/tests/DHAuditorBundleTest.php index 48efdf82..f70a1ab5 100644 --- a/tests/DHAuditorBundleTest.php +++ b/tests/DHAuditorBundleTest.php @@ -15,48 +15,41 @@ use DH\AuditorBundle\DHAuditorBundle; use DH\AuditorBundle\Event\ConsoleEventSubscriber; use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; -use Nyholm\BundleTest\BaseBundleTestCase; -use Nyholm\BundleTest\CompilerPass\PublicServicePass; +use Nyholm\BundleTest\TestKernel; +use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Bundle\SecurityBundle\SecurityBundle; use Symfony\Bundle\TwigBundle\TwigBundle; use Symfony\Component\HttpKernel\Kernel; +use Symfony\Component\HttpKernel\KernelInterface; /** * @internal * * @small */ -final class DHAuditorBundleTest extends BaseBundleTestCase +final class DHAuditorBundleTest extends KernelTestCase { - protected function setUp(): void - { - parent::setUp(); - - // Make services public - $this->addCompilerPass(new PublicServicePass('#^(DH\\\\Auditor(Bundle)?\\\\|dh_auditor\.).*$#')); - } - public function testInitBundle(): void { - $kernel = $this->createKernel(); - - $kernel->addConfigFile(__DIR__.'/Fixtures/Resources/config/dh_auditor.yaml'); - $kernel->addConfigFile(__DIR__.'/Fixtures/Resources/config/doctrine.yaml'); - if (6 > Kernel::MAJOR_VERSION) { - $kernel->addConfigFile(__DIR__.'/Fixtures/Resources/config/sf4_5/security.yaml'); - // $kernel->addConfigFile(__DIR__ . '/Fixtures/Resources/routes/sf4_5/annotations.yaml'); - } else { - $kernel->addConfigFile(__DIR__.'/Fixtures/Resources/config/sf6_7/security.yaml'); - // $kernel->addConfigFile(__DIR__ . '/Fixtures/Resources/routes/sf6_7/attributes.yaml'); - } - - $kernel->addBundle(DoctrineBundle::class); - $kernel->addBundle(SecurityBundle::class); - $kernel->addBundle(TwigBundle::class); - - $this->bootKernel(); - - $container = $this->getContainer(); + // Boot the kernel with a config closure, the handleOptions call in createKernel is important for that to work + $kernel = self::bootKernel(['config' => static function (TestKernel $kernel) { + // Add some other bundles we depend on + $kernel->addTestBundle(DoctrineBundle::class); + $kernel->addTestBundle(SecurityBundle::class); + $kernel->addTestBundle(TwigBundle::class); + + // Add some configuration + $kernel->addTestConfig(__DIR__.'/Fixtures/Resources/config/dh_auditor.yaml'); + $kernel->addTestConfig(__DIR__.'/Fixtures/Resources/config/doctrine.yaml'); + if (6 > Kernel::MAJOR_VERSION) { + $kernel->addTestConfig(__DIR__.'/Fixtures/Resources/config/sf4_5/security.yaml'); + } else { + $kernel->addTestConfig(__DIR__.'/Fixtures/Resources/config/sf6_7/security.yaml'); + } + }]); + + // Get the container + $container = self::getContainer(); self::assertTrue($container->has(AuditorConfiguration::class)); self::assertInstanceOf(AuditorConfiguration::class, $container->get(AuditorConfiguration::class)); @@ -89,8 +82,25 @@ public function testInitBundle(): void self::assertInstanceOf(ConsoleEventSubscriber::class, $container->get(ConsoleEventSubscriber::class)); } - protected function getBundleClass() + protected function getBundleClass(): string { return DHAuditorBundle::class; } + + protected static function getKernelClass(): string + { + return TestKernel::class; + } + + protected static function createKernel(array $options = []): KernelInterface + { + /** + * @var TestKernel $kernel + */ + $kernel = parent::createKernel($options); + $kernel->addTestBundle(DHAuditorBundle::class); + $kernel->handleOptions($options); + + return $kernel; + } }