Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 18453aa

Browse files
author
Amrouche Hamza
committed
[FrameworkBundle] add a notice when passing a routerInterface with warmupInterface in RouterCacheWarmer
1 parent a603ba0 commit 18453aa

File tree

5 files changed

+72
-1
lines changed

5 files changed

+72
-1
lines changed

UPGRADE-4.1.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@ Translation
1616

1717
* The `FileDumper::setBackup()` method is deprecated and will be removed in 5.0.
1818
* The `TranslationWriter::disableBackup()` method is deprecated and will be removed in 5.0.
19+
20+
FrameworkBundle
21+
---------------
22+
23+
* A `RouterInterface` that does not implement the `WarmableInterface` is deprecated and will not be supported in Symfony 5.0.

UPGRADE-5.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@ Translation
1616

1717
* The `FileDumper::setBackup()` method has been removed.
1818
* The `TranslationWriter::disableBackup()` method has been removed.
19+
20+
FrameworkBundle
21+
---------------
22+
23+
* Using a `RouterInterface` that does not implement the `WarmableInterface` is not supported anymore.

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ CHANGELOG
55
-----
66

77
* allowed to pass an optional `LoggerInterface $logger` instance to the `Router`
8-
8+
* Using a `RouterInterface` that does not implement the `WarmableInterface` is deprecated and will not be supported in Symfony 5.0.
9+
910
4.0.0
1011
-----
1112

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+
49+
return;
4850
}
51+
52+
@trigger_error(sprintf('Passing a %s without implementing %s is deprecated since 4.1.', RouterInterface::class, WarmableInterface::class), \E_USER_DEPRECATED);
4953
}
5054

5155
/**
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 <[email protected]>
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)