|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Doctrine\Bundle\DoctrineBundle\Tests\ArgumentResolver\Fixtures; |
| 6 | + |
| 7 | +use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; |
| 8 | +use Doctrine\ORM\Configuration; |
| 9 | +use Psr\Log\NullLogger; |
| 10 | +use Symfony\Bundle\FrameworkBundle\FrameworkBundle; |
| 11 | +use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; |
| 12 | +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; |
| 13 | +use Symfony\Component\HttpKernel\Bundle\BundleInterface; |
| 14 | +use Symfony\Component\HttpKernel\Kernel; |
| 15 | +use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; |
| 16 | + |
| 17 | +use function md5; |
| 18 | +use function method_exists; |
| 19 | +use function mt_rand; |
| 20 | +use function sys_get_temp_dir; |
| 21 | + |
| 22 | +use const PHP_VERSION_ID; |
| 23 | + |
| 24 | +class EntityValueResolverFunctionalKernel extends Kernel |
| 25 | +{ |
| 26 | + use MicroKernelTrait; |
| 27 | + |
| 28 | + private string|null $projectDir = null; |
| 29 | + |
| 30 | + public function __construct() |
| 31 | + { |
| 32 | + parent::__construct('test', true); |
| 33 | + } |
| 34 | + |
| 35 | + /** @return iterable<BundleInterface> */ |
| 36 | + public function registerBundles(): iterable |
| 37 | + { |
| 38 | + return [ |
| 39 | + new FrameworkBundle(), |
| 40 | + new DoctrineBundle(), |
| 41 | + ]; |
| 42 | + } |
| 43 | + |
| 44 | + protected function configureContainer(ContainerConfigurator $container): void |
| 45 | + { |
| 46 | + $container->extension('framework', [ |
| 47 | + 'secret' => 'F00', |
| 48 | + 'http_method_override' => false, |
| 49 | + 'annotations' => false, |
| 50 | + 'php_errors' => ['log' => true], |
| 51 | + 'handle_all_throwables' => true, |
| 52 | + 'router' => ['utf8' => true], |
| 53 | + 'test' => true, |
| 54 | + ]); |
| 55 | + |
| 56 | + $container->extension('doctrine', [ |
| 57 | + 'dbal' => [ |
| 58 | + 'driver' => 'pdo_sqlite', |
| 59 | + 'memory' => true, |
| 60 | + 'schema_manager_factory' => 'doctrine.dbal.default_schema_manager_factory', |
| 61 | + ], |
| 62 | + 'orm' => [ |
| 63 | + 'controller_resolver' => ['auto_mapping' => false], |
| 64 | + 'enable_lazy_ghost_objects' => true, |
| 65 | + /** @phpstan-ignore function.alreadyNarrowedType */ |
| 66 | + 'enable_native_lazy_objects' => PHP_VERSION_ID >= 80400 && method_exists(Configuration::class, 'enableNativeLazyObjects'), |
| 67 | + 'mappings' => [ |
| 68 | + 'PostFixtures' => [ |
| 69 | + 'type' => 'attribute', |
| 70 | + 'dir' => __DIR__, |
| 71 | + 'prefix' => 'Doctrine\Bundle\DoctrineBundle\Tests\ArgumentResolver\Fixtures', |
| 72 | + ], |
| 73 | + ], |
| 74 | + ], |
| 75 | + ]); |
| 76 | + |
| 77 | + $services = $container->services(); |
| 78 | + $services->set('logger', NullLogger::class); |
| 79 | + $services->set(PostController::class) |
| 80 | + ->autowire() |
| 81 | + ->autoconfigure() |
| 82 | + ->public() |
| 83 | + ->tag('controller.service_arguments'); |
| 84 | + } |
| 85 | + |
| 86 | + protected function configureRoutes(RoutingConfigurator $routes): void |
| 87 | + { |
| 88 | + $routes->add('post_show', '/posts/{post}')->controller(PostController::class); |
| 89 | + } |
| 90 | + |
| 91 | + public function getProjectDir(): string |
| 92 | + { |
| 93 | + return $this->projectDir ??= sys_get_temp_dir() . '/sf_evr_kernel_' . md5((string) mt_rand()); |
| 94 | + } |
| 95 | +} |
0 commit comments