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

Skip to content

Commit 6656dbe

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

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-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,7 +45,11 @@ public function warmUp($cacheDir)
4545

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

5155
/**
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 PHPUnit\Framework\Error\Notice;
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+
$routerMock = $this->getMockBuilder(testRouterInterfaceWithWarmebleInterface::class)->setMethods(array('match', 'generate', 'getContext', 'setContext', 'warmUp', 'getRouteCollection'))->getMock();
25+
$routerCacheWarmer = new RouterCacheWarmer($routerMock);
26+
$routerCacheWarmer->warmUp('/tmp');
27+
$routerMock->expects($this->any())->method('warmUp')->with('/tmp')->willReturn('');
28+
$this->addToAssertionCount(1);
29+
}
30+
31+
public function testWarmUpWithoutWarmebleInterface()
32+
{
33+
$routerMock = $this->getMockBuilder(testRouterInterfaceWithoutWarmebleInterface::class)->setMethods(array('match', 'generate', 'getContext', 'setContext', 'getRouteCollection'))->getMock();
34+
$routerCacheWarmer = new RouterCacheWarmer($routerMock);
35+
36+
if (class_exists(Notice::class)) {
37+
$class = Notice::class;
38+
} else {
39+
$class = \PHPUnit_Framework_Error_Notice::class;
40+
}
41+
if (method_exists($this, 'expectException')) {
42+
$this->expectExceptionMessage(sprintf('%s is not a instanceof Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface, no warmUp has been triggered.', get_class($routerMock)));
43+
$this->expectException($class);
44+
} else {
45+
$this->setExpectedException($class, sprintf('%s is not a instanceof Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface, no warmUp has been triggered.', get_class($routerMock)));
46+
}
47+
48+
$routerCacheWarmer->warmUp('/tmp');
49+
}
50+
}
51+
52+
interface testRouterInterfaceWithWarmebleInterface extends RouterInterface, WarmableInterface
53+
{
54+
}
55+
56+
interface testRouterInterfaceWithoutWarmebleInterface extends RouterInterface
57+
{
58+
}

0 commit comments

Comments
 (0)
0