Skip to content

Commit

Permalink
Fix deprecation in FrameworkBundle (#1615)
Browse files Browse the repository at this point in the history
  • Loading branch information
jderusse authored Nov 30, 2023
1 parent 670ef21 commit e283973
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 25 deletions.
65 changes: 40 additions & 25 deletions tests/Functional/BundleInitializationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use AsyncAws\Symfony\Bundle\AsyncAwsBundle;
use AsyncAws\Symfony\Bundle\Secrets\SsmVault;
use Nyholm\BundleTest\TestKernel;
use Symfony\Bundle\FrameworkBundle\EventListener\ConsoleProfilerListener;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\HttpKernel\KernelInterface;
Expand All @@ -20,9 +21,9 @@ class BundleInitializationTest extends KernelTestCase
{
public function testInitBundle()
{
self::bootKernel(['config' => static function (TestKernel $kernel) {
$kernel->addTestConfig(__DIR__ . '/Resources/config/default.yaml');
}]);
$this->bootWithConfig([
'default.yaml',
]);

self::assertServiceExists('async_aws.client.s3', S3Client::class);
self::assertServiceExists('async_aws.client.sqs', SqsClient::class);
Expand All @@ -48,9 +49,9 @@ public function testInitBundle()

public function testEmptyConfig()
{
self::bootKernel(['config' => static function (TestKernel $kernel) {
$kernel->addTestConfig(__DIR__ . '/Resources/config/empty.yaml');
}]);
$this->bootWithConfig([
'empty.yaml',
]);

self::assertServiceExists('async_aws.client.s3', S3Client::class);
self::assertServiceExists('async_aws.client.sqs', SqsClient::class);
Expand All @@ -64,9 +65,9 @@ public function testEmptyConfig()

public function testNotRegisterServices()
{
self::bootKernel(['config' => static function (TestKernel $kernel) {
$kernel->addTestConfig(__DIR__ . '/Resources/config/no_services.yaml');
}]);
$this->bootWithConfig([
'no_services.yaml',
]);

$container = self::$kernel->getContainer();
self::assertFalse($container->has('async_aws.client.s3'));
Expand All @@ -76,9 +77,9 @@ public function testNotRegisterServices()

public function testEmptyClientsKey()
{
self::bootKernel(['config' => static function (TestKernel $kernel) {
$kernel->addTestConfig(__DIR__ . '/Resources/config/empty_clients_key.yaml');
}]);
$this->bootWithConfig([
'empty_clients_key.yaml',
]);

$container = self::$kernel->getContainer();
self::assertTrue($container->has('async_aws.client.s3'));
Expand All @@ -88,9 +89,9 @@ public function testEmptyClientsKey()

public function testNotRegisterSqs()
{
self::bootKernel(['config' => static function (TestKernel $kernel) {
$kernel->addTestConfig(__DIR__ . '/Resources/config/no_service_sqs.yaml');
}]);
$this->bootWithConfig([
'no_service_sqs.yaml',
]);

$container = self::$kernel->getContainer();
self::assertTrue($container->has('async_aws.client.s3'));
Expand All @@ -100,9 +101,9 @@ public function testNotRegisterSqs()

public function testConfigOverride()
{
self::bootKernel(['config' => static function (TestKernel $kernel) {
$kernel->addTestConfig(__DIR__ . '/Resources/config/override.yaml');
}]);
$this->bootWithConfig([
'override.yaml',
]);

$container = self::$kernel->getContainer();
self::assertTrue($container->has('async_aws.client.s3'));
Expand Down Expand Up @@ -134,17 +135,17 @@ public function testExceptionWhenConfigureServiceNotInstalled()

$this->expectException(InvalidConfigurationException::class);

self::bootKernel(['config' => static function (TestKernel $kernel) {
$kernel->addTestConfig(__DIR__ . '/Resources/config/not_installed_service.yaml');
}]);
$this->bootWithConfig([
'not_installed_service.yaml',
]);
}

public function testIssue793()
{
self::bootKernel(['config' => static function (TestKernel $kernel) {
$kernel->addTestConfig(__DIR__ . '/Resources/config/issue-793/default.yaml');
$kernel->addTestConfig(__DIR__ . '/Resources/config/issue-793/dev.yaml');
}]);
$this->bootWithConfig([
'issue-793/default.yaml',
'issue-793/dev.yaml',
]);

$container = self::$kernel->getContainer();
$x = $container->get(S3Client::class);
Expand Down Expand Up @@ -175,4 +176,18 @@ private function assertServiceExists(string $serviceId, string $instance)
self::assertTrue($container->has($serviceId));
self::assertInstanceOf($instance, $container->get($serviceId));
}

private function bootWithConfig(array $configs): void
{
self::bootKernel(['config' => static function (TestKernel $kernel) use ($configs) {
foreach ($configs as $config) {
$kernel->addTestConfig(__DIR__ . '/Resources/config/' . $config);
}

// hack to assert the version of the bundle
if (class_exists(ConsoleProfilerListener::class)) {
$kernel->addTestConfig(__DIR__ . '/Resources/config/default_sf64.yaml');
}
}]);
}
}
4 changes: 4 additions & 0 deletions tests/Functional/Resources/config/default_sf64.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
framework:
handle_all_throwables: true
php_errors:
log: true

0 comments on commit e283973

Please sign in to comment.