|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the SpiriitLabs php-excel-rust package. |
| 5 | + * Copyright (c) SpiriitLabs <https://www.spiriit.com/> |
| 6 | + * For the full copyright and license information, please view the LICENSE |
| 7 | + * file that was distributed with this source code. |
| 8 | + */ |
| 9 | + |
| 10 | +namespace Spiriit\Bundle\Tests\DependencyInjection; |
| 11 | + |
| 12 | +use PHPUnit\Framework\TestCase; |
| 13 | +use Spiriit\Bundle\AuthLogBundle\DependencyInjection\SpiriitAuthLogExtension; |
| 14 | +use Spiriit\Bundle\AuthLogBundle\SpiriitAuthLogBundle; |
| 15 | +use Spiriit\Bundle\Tests\Integration\Stubs\Kernel; |
| 16 | +use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension; |
| 17 | +use Symfony\Bundle\FrameworkBundle\FrameworkBundle; |
| 18 | +use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
| 19 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 20 | +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; |
| 21 | + |
| 22 | +class SpiriitAuthLogExtensionTest extends TestCase |
| 23 | +{ |
| 24 | + public function testEmptyConfiguration(): void |
| 25 | + { |
| 26 | + $container = $this->createContainer([ |
| 27 | + 'framework' => [ |
| 28 | + 'secret' => 'testing', |
| 29 | + ], |
| 30 | + 'spiriit_auth_log' => [], |
| 31 | + ]); |
| 32 | + |
| 33 | + self::expectException(InvalidConfigurationException::class); |
| 34 | + self::expectExceptionMessage('The child config "transports" under "spiriit_auth_log" must be configured.'); |
| 35 | + |
| 36 | + $container->compile(); |
| 37 | + } |
| 38 | + |
| 39 | + private function createContainer(array $configs = []): ContainerBuilder |
| 40 | + { |
| 41 | + $container = new ContainerBuilder(new ParameterBag([ |
| 42 | + 'kernel.bundles_metadata' => [], |
| 43 | + 'kernel.cache_dir' => __DIR__, |
| 44 | + 'kernel.debug' => false, |
| 45 | + 'kernel.environment' => 'test', |
| 46 | + 'kernel.name' => 'kernel', |
| 47 | + 'kernel.root_dir' => __DIR__, |
| 48 | + 'kernel.project_dir' => __DIR__, |
| 49 | + 'kernel.container_class' => 'AutowiringTestContainer', |
| 50 | + 'kernel.charset' => 'utf8', |
| 51 | + 'kernel.runtime_environment' => 'test', |
| 52 | + 'env(base64:default::SYMFONY_DECRYPTION_SECRET)' => 'dummy', |
| 53 | + 'kernel.build_dir' => __DIR__, |
| 54 | + 'debug.file_link_format' => null, |
| 55 | + 'env(bool:default::SYMFONY_TRUST_X_SENDFILE_TYPE_HEADER)' => true, |
| 56 | + 'env(default::SYMFONY_TRUSTED_HOSTS)' => [], |
| 57 | + 'env(default::SYMFONY_TRUSTED_PROXIES)' => [], |
| 58 | + 'env(default::SYMFONY_TRUSTED_HEADERS)' => [], |
| 59 | + 'kernel.bundles' => [ |
| 60 | + 'FrameworkBundle' => FrameworkBundle::class, |
| 61 | + 'SpiriitAuthLogBundle' => SpiriitAuthLogBundle::class, |
| 62 | + ], |
| 63 | + ])); |
| 64 | + |
| 65 | + $container->set('kernel', function () { |
| 66 | + return new Kernel('test', false); |
| 67 | + }); |
| 68 | + |
| 69 | + $container->registerExtension(new FrameworkExtension()); |
| 70 | + $container->registerExtension(new SpiriitAuthLogExtension()); |
| 71 | + |
| 72 | + foreach ($configs as $extension => $config) { |
| 73 | + $container->loadFromExtension($extension, $config); |
| 74 | + } |
| 75 | + |
| 76 | + return $container; |
| 77 | + } |
| 78 | +} |
0 commit comments