8000 [FrameworkBundle] add a notice when passing a routerInterface with wa… · symfony/symfony@cfd840f · GitHub
[go: up one dir, main page]

Skip to content

Commit cfd840f

Browse files
author
Amrouche Hamza
committed
[FrameworkBundle] add a notice when passing a routerInterface with warmupInterface in RouterCacheWarmer
1 parent 6a40488 commit cfd840f

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/CacheWarmer/RouterCacheWarmer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public function warmUp($cacheDir)
4545

4646
if ($router instanceof WarmableInterface) {
4747
$router->warmUp($cacheDir);
48+
49+
return;
50+
} else {
51+
@trigger_error(sprintf('Passing a %s without implementing %s is deprecated since 4.1.', RouterInterface::class, WarmableInterface::class), \E_USER_DEPRECATED);
4852
}
4953
}
5054

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\CacheWarmer;
13+
14+
use Psr\Container\ContainerInterface;
15+
use Symfony\Bundle\FrameworkBundle\CacheWarmer\RouterCacheWarmer;
16+
use PHPUnit\Framework\TestCase;
17+
use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
18+
use Symfony\Component\Routing\RouterInterface;
19+
20+
class RouterCacheWarmerTest extends TestCase
21+
{
22+
public function testWarmUpWithWarmebleInterface()
23+
{
24+
$containerMock = $this->getMockBuilder(ContainerInterface::class)->setMethods(array('get', 'has'))->getMock();
25+
26+
$routerMock = $this->getMockBuilder(testRouterInterfaceWithWarmebleInterface::class)->setMethods(array('match', 'generate', 'getContext', 'setContext', 'getRouteCollection', 'warmUp'))->getMock();
27+
$containerMock->expects($this->any())->method('get')->with('router')->willReturn($routerMock);
28+
$routerCacheWarmer = new RouterCacheWarmer($containerMock);
29+
30+
$routerCacheWarmer->warmUp('/tmp');
31+
$routerMock->expects($this->any())->method('warmUp')->with('/tmp')->willReturn('');
32+
$this->addToAssertionCount(1);
33+
}
34+
35+
/**
36+
* @expectedDeprecation Passing a Symfony\Component\Routing\RouterInterface without implementing Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface is deprecated since 4.1.
37+
* @group legacy
38+
*/
39+
public function testWarmUpWithoutWarmebleInterface()
40+
{
41+
$containerMock = $this->getMockBuilder(ContainerInterface::class)->setMethods(array('get', 'has'))->getMock();
42+
43+
$routerMock = $this->getMockBuilder(testRouterInterfaceWithoutWarmebleInterface::class)->setMethods(array('match', 'generate', 'getContext', 'setContext', 'getRouteCollection'))->getMock();
44+
$containerMock->expects($this->any())->method('get')->with('router')->willReturn($routerMock);
45+
$routerCacheWarmer = new RouterCacheWarmer($containerMock);
46+
$routerCacheWarmer->warmUp('/tmp');
47+
}
48+
}
49+
50+
interface testRouterInterfaceWithWarmebleInterface extends RouterInterface, WarmableInterface
51+
{
52+
}
53+
54+
interface testRouterInterfaceWithoutWarmebleInterface extends RouterInterface
55+
{
56+
}

0 commit comments

Comments
 (0)
0