Skip to content

Commit e2c8b5f

Browse files
committed
Merge branch '7.1' into 7.2
* 7.1: do not base services on PHPUnit mocks do not use TestCase::getName() when possible do not use assertCount() with generators
2 parents d02ab3f + be20187 commit e2c8b5f

File tree

4 files changed

+61
-11
lines changed

4 files changed

+61
-11
lines changed

src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php

+57-7
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;
@@ -56,15 +59,11 @@ protected function setUp(): void
5659
{
5760
$this->kernel = $this->createMock(KernelInterface::class);
5861

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

src/Symfony/Component/Cache/Tests/Adapter/ApcuAdapterTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterfac
3030
$this->markTestSkipped('APCu extension is required.');
3131
}
3232
if ('cli' === \PHP_SAPI && !filter_var(\ini_get('apc.enable_cli'), \FILTER_VALIDATE_BOOL)) {
33-
if ('testWithCliSapi' !== $this->getName()) {
33+
if ('testWithCliSapi' !== (method_exists($this, 'name') ? $this->name() : $this->getName())) {
3434
$this->markTestSkipped('apc.enable_cli=1 is required.');
3535
}
3636
}

src/Symfony/Component/Finder/Tests/Iterator/LazyIteratorTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function testDelegate()
2929
{
3030
$iterator = new LazyIterator(fn () => new Iterator(['foo', 'bar']));
3131

32-
$this->assertCount(2, $iterator);
32+
$this->assertCount(2, iterator_to_array($iterator));
3333
}
3434

3535
public function testInnerDestructedAtTheEnd()

src/Symfony/Component/Routing/Tests/Generator/Dumper/CompiledUrlGeneratorDumperTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ protected function setUp(): void
3535
{
3636
$this->routeCollection = new RouteCollection();
3737
$this->generatorDumper = new CompiledUrlGeneratorDumper($this->routeCollection);
38-
$this->testTmpFilepath = sys_get_temp_dir().'/php_generator.'.$this->getName().'.php';
39-
$this->largeTestTmpFilepath = sys_get_temp_dir().'/php_generator.'.$this->getName().'.large.php';
38+
$this->testTmpFilepath = sys_get_temp_dir().'/php_generator.php';
39+
$this->largeTestTmpFilepath = sys_get_temp_dir().'/php_generator.large.php';
4040
@unlink($this->testTmpFilepath);
4141
@unlink($this->largeTestTmpFilepath);
4242
}

0 commit comments

Comments
 (0)