Skip to content

Commit

Permalink
Fix deprecations about cache warmers and route collections
Browse files Browse the repository at this point in the history
  • Loading branch information
javiereguiluz committed Oct 29, 2023
1 parent 59cc8f5 commit 48a82f2
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions tests/Cache/CacheWarmerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

use EasyCorp\Bundle\EasyAdminBundle\Cache\CacheWarmer;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Kernel;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RouterInterface;

class CacheWarmerTest extends TestCase
Expand All @@ -32,7 +34,7 @@ protected function tearDown(): void
public function testWarmUpWithNoRoutes()
{
$router = $this->getMockBuilder(RouterInterface::class)->getMock();
$router->method('getRouteCollection')->willReturn([]);
$router->method('getRouteCollection')->willReturn(Kernel::MAJOR_VERSION >= 7 ? new RouteCollection() : []);

$cacheWarmer = new CacheWarmer($router);
$cacheWarmer->warmUp($this->cacheDirectory);
Expand All @@ -42,16 +44,25 @@ public function testWarmUpWithNoRoutes()

public function testWarmUp()
{
$routesDefinition = [
'admin1' => new Route('/admin1', ['_controller' => TestingDashboardController::class.'::index']),
'admin2' => new Route('/admin2', ['_controller' => TestingDashboardController::class]),
'admin3' => new Route('/admin3', ['_controller' => [TestingDashboardController::class, 'index']]),
'admin4' => new Route('/admin4', ['_controller' => [TestingDashboardController::class]]),
'admin5' => new Route('/admin5', ['_controller' => TestingDashboardController::class.'::someMethod']),
'admin6' => new Route('/admin6', ['_controller' => [TestingDashboardController::class, 'someMethod']]),
];

$routeCollection = $routesDefinition;
if (Kernel::MAJOR_VERSION >= 7) {
$routeCollection = new RouteCollection();
foreach ($routesDefinition as $name => $route) {
$routeCollection->add($name, $route);
}
}

$router = $this->getMockBuilder(RouterInterface::class)->getMock();
$router->method('getRouteCollection')
->willReturn([
'admin1' => new Route('/admin1', ['_controller' => TestingDashboardController::class.'::index']),
'admin2' => new Route('/admin2', ['_controller' => TestingDashboardController::class]),
'admin3' => new Route('/admin3', ['_controller' => [TestingDashboardController::class, 'index']]),
'admin4' => new Route('/admin4', ['_controller' => [TestingDashboardController::class]]),
'admin5' => new Route('/admin5', ['_controller' => TestingDashboardController::class.'::someMethod']),
'admin6' => new Route('/admin6', ['_controller' => [TestingDashboardController::class, 'someMethod']]),
]);
$router->method('getRouteCollection')->willReturn($routeCollection);

$cacheWarmer = new CacheWarmer($router);
$cacheWarmer->warmUp($this->cacheDirectory);
Expand Down

0 comments on commit 48a82f2

Please sign in to comment.