diff --git a/Tests/DependencyInjection/WebProfilerExtensionTest.php b/Tests/DependencyInjection/WebProfilerExtensionTest.php index 2d9ae56f..7ba63112 100644 --- a/Tests/DependencyInjection/WebProfilerExtensionTest.php +++ b/Tests/DependencyInjection/WebProfilerExtensionTest.php @@ -22,8 +22,11 @@ use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\HttpKernel\DataCollector\DumpDataCollector; use Symfony\Component\HttpKernel\KernelInterface; +use Symfony\Component\HttpKernel\Profiler\Profile; use Symfony\Component\HttpKernel\Profiler\Profiler; use Symfony\Component\HttpKernel\Profiler\ProfilerStorageInterface; +use Symfony\Component\Routing\RequestContext; +use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\RouterInterface; class WebProfilerExtensionTest extends TestCase @@ -58,15 +61,11 @@ protected function setUp(): void $this->kernel = $this->createMock(KernelInterface::class); - $profiler = $this->createMock(Profiler::class); - $profilerStorage = $this->createMock(ProfilerStorageInterface::class); - $router = $this->createMock(RouterInterface::class); - $this->container = new ContainerBuilder(); $this->container->register('data_collector.dump', DumpDataCollector::class)->setPublic(true); $this->container->register('error_handler.error_renderer.html', HtmlErrorRenderer::class)->setPublic(true); $this->container->register('event_dispatcher', EventDispatcher::class)->setPublic(true); - $this->container->register('router', \get_class($router))->setPublic(true); + $this->container->register('router', Router::class)->setPublic(true); $this->container->register('twig', 'Twig\Environment')->setPublic(true); $this->container->register('twig_loader', 'Twig\Loader\ArrayLoader')->addArgument([])->setPublic(true); $this->container->register('twig', 'Twig\Environment')->addArgument(new Reference('twig_loader'))->setPublic(true); @@ -78,9 +77,9 @@ protected function setUp(): void $this->container->setParameter('kernel.charset', 'UTF-8'); $this->container->setParameter('debug.file_link_format', null); $this->container->setParameter('profiler.class', ['Symfony\\Component\\HttpKernel\\Profiler\\Profiler']); - $this->container->register('profiler', \get_class($profiler)) + $this->container->register('profiler', Profiler::class) ->setPublic(true) - ->addArgument(new Definition(\get_class($profilerStorage))); + ->addArgument(new Definition(NullProfilerStorage::class)); $this->container->setParameter('data_collector.templates', []); $this->container->set('kernel', $this->kernel); $this->container->addCompilerPass(new RegisterListenersPass()); @@ -212,3 +211,54 @@ private function getCompiledContainer() return $this->container; } } + +class Router implements RouterInterface +{ + private $context; + + public function setContext(RequestContext $context): void + { + $this->context = $context; + } + + public function getContext(): RequestContext + { + return $this->context; + } + + public function getRouteCollection(): RouteCollection + { + return new RouteCollection(); + } + + public function generate(string $name, array $parameters = [], int $referenceType = self::ABSOLUTE_PATH): string + { + } + + public function match(string $pathinfo): array + { + return []; + } +} + +class NullProfilerStorage implements ProfilerStorageInterface +{ + public function find(?string $ip, ?string $url, ?int $limit, ?string $method, ?int $start = null, ?int $end = null): array + { + return []; + } + + public function read(string $token): ?Profile + { + return null; + } + + public function write(Profile $profile): bool + { + return true; + } + + public function purge() + { + } +}