Skip to content

Commit ec406e7

Browse files
committed
Merge branch '5.4' into 6.4
* 5.4: do not base services on PHPUnit mocks do not use TestCase::getName() when possible do not use assertCount() with generators
2 parents 21ef783 + ac41164 commit ec406e7

File tree

1 file changed

+57
-7
lines changed

1 file changed

+57
-7
lines changed

Tests/DependencyInjection/WebProfilerExtensionTest.php

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@
2323
use Symfony\Component\EventDispatcher\EventDispatcher;
2424
use Symfony\Component\HttpKernel\DataCollector\DumpDataCollector;
2525
use Symfony\Component\HttpKernel\KernelInterface;
26+
use Symfony\Component\HttpKernel\Profiler\Profile;
2627
use Symfony\Component\HttpKernel\Profiler\Profiler;
2728
use Symfony\Component\HttpKernel\Profiler\ProfilerStorageInterface;
29+
use Symfony\Component\Routing\RequestContext;
30+
use Symfony\Component\Routing\RouteCollection;
2831
use Symfony\Component\Routing\RouterInterface;
2932
use Twig\Environment;
3033
use Twig\Loader\ArrayLoader;
@@ -58,15 +61,11 @@ protected function setUp(): void
5861

5962
$this->kernel = $this->createMock(KernelInterface::class);
6063

61-
$profiler = $this->createMock(Profiler::class);
62-
$profilerStorage = $this->createMock(ProfilerStorageInterface::class);
63-
$router = $this->createMock(RouterInterface::class);
64-
6564
$this->container = new ContainerBuilder();
6665
$this->container->register('data_collector.dump', DumpDataCollector::class)->setPublic(true);
6766
$this->container->register('error_handler.error_renderer.html', HtmlErrorRenderer::class)->setPublic(true);
6867
$this->container->register('event_dispatcher', EventDispatcher::class)->setPublic(true);
69-
$this->container->register('router', $router::class)->setPublic(true);
68+
$this->container->register('router', Router::class)->setPublic(true);
7069
$this->container->register('twig', Environment::class)->setPublic(true);
7170
$this->container->register('twig_loader', ArrayLoader::class)->addArgument([])->setPublic(true);
7271
$this->container->register('twig', Environment::class)->addArgument(new Reference('twig_loader'))->setPublic(true);
@@ -78,9 +77,9 @@ protected function setUp(): void
7877
$this->container->setParameter('kernel.charset', 'UTF-8');
7978
$this->container->setParameter('debug.file_link_format', null);
8079
$this->container->setParameter('profiler.class', [Profiler::class]);
81-
$this->container->register('profiler', $profiler::class)
80+
$this->container->register('profiler', Profiler::class)
8281
->setPublic(true)
83-
->addArgument(new Definition($profilerStorage::class));
82+
->addArgument(new Definition(NullProfilerStorage::class));
8483
$this->container->setParameter('data_collector.templates', []);
8584
$this->container->set('kernel', $this->kernel);
8685
$this->container->addCompilerPass(new RegisterListenersPass());
@@ -211,3 +210,54 @@ private function getCompiledContainer()
211210
return $this->container;
212211
}
213212
}
213+
214+
class Router implements RouterInterface
215+
{
216+
private $context;
217+
218+
public function setContext(RequestContext $context): void
219+
{
220+
$this->context = $context;
221+
}
222+
223+
public function getContext(): RequestContext
224+
{
225+
return $this->context;
226+
}
227+
228+
public function getRouteCollection(): RouteCollection
229+
{
230+
return new RouteCollection();
231+
}
232+
233+
public function generate(string $name, array $parameters = [], int $referenceType = self::ABSOLUTE_PATH): string
234+
{
235+
}
236+
237+
public function match(string $pathinfo): array
238+
{
239+
return [];
240+
}
241+
}
242+
243+
class NullProfilerStorage implements ProfilerStorageInterface
244+
{
245+
public function find(?string $ip, ?string $url, ?int $limit, ?string $method, ?int $start = null, ?int $end = null): array
246+
{
247+
return [];
248+
}
249+
250+
public function read(string $token): ?Profile
251+
{
252+
return null;
253+
}
254+
255+
public function write(Profile $profile): bool
256+
{
257+
return true;
258+
}
259+
260+
public function purge()
261+
{
262+
}
263+
}

0 commit comments

Comments
 (0)