Skip to content

Commit

Permalink
Merge branch '6.4' into 7.1
Browse files Browse the repository at this point in the history
* 6.4:
  do not base services on PHPUnit mocks
  do not use TestCase::getName() when possible
  do not use assertCount() with generators
  • Loading branch information
xabbuh committed Oct 1, 2024
2 parents b8b1b6f + ec406e7 commit f290abb
Showing 1 changed file with 57 additions and 7 deletions.
64 changes: 57 additions & 7 deletions Tests/DependencyInjection/WebProfilerExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,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;
use Twig\Environment;
use Twig\Loader\ArrayLoader;
Expand Down Expand Up @@ -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', $router::class)->setPublic(true);
$this->container->register('router', Router::class)->setPublic(true);
$this->container->register('twig', Environment::class)->setPublic(true);
$this->container->register('twig_loader', ArrayLoader::class)->addArgument([])->setPublic(true);
$this->container->register('twig', Environment::class)->addArgument(new Reference('twig_loader'))->setPublic(true);
Expand All @@ -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', [Profiler::class]);
$this->container->register('profiler', $profiler::class)
$this->container->register('profiler', Profiler::class)
->setPublic(true)
->addArgument(new Definition($profilerStorage::class));
->addArgument(new Definition(NullProfilerStorage::class));
$this->container->setParameter('data_collector.templates', []);
$this->container->set('kernel', $this->kernel);
$this->container->addCompilerPass(new RegisterListenersPass());
Expand Down Expand Up @@ -211,3 +210,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()
{
}
}

0 comments on commit f290abb

Please sign in to comment.