Skip to content

Commit

Permalink
Update test deps, fixes CI for 6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
DamienHarper committed Jan 3, 2024
1 parent b122eae commit 5f48046
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 32 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@
"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/dependency-injection": "^5.4|^6.0|^7.0",
"symfony/css-selector": "^5.4|^6.0|^7.0",
"symfony/framework-bundle": "^5.4|^6.0|^7.0",
"symfony/var-dumper": "^5.4|^6.0|^7.0",
Expand Down
72 changes: 41 additions & 31 deletions tests/DHAuditorBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 5f48046

Please # to comment.