From 54e99d0a88c301552162b0156b8de3713eff14a5 Mon Sep 17 00:00:00 2001 From: Leo Feyer Date: Wed, 11 Sep 2019 14:39:23 +0200 Subject: [PATCH] Simplify the findPages() method --- core-bundle/src/Routing/RouteProvider.php | 2 +- .../tests/Routing/RouteProviderTest.php | 29 ++++++++----------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/core-bundle/src/Routing/RouteProvider.php b/core-bundle/src/Routing/RouteProvider.php index ef0e618b384..5cd00161e16 100644 --- a/core-bundle/src/Routing/RouteProvider.php +++ b/core-bundle/src/Routing/RouteProvider.php @@ -463,7 +463,7 @@ private function sortRoutes(array &$routes, array $languages = null): void } /** - * Finds the page models keeping the candidates order + * Finds the page models keeping the candidates order. * * @return Model[] */ diff --git a/core-bundle/tests/Routing/RouteProviderTest.php b/core-bundle/tests/Routing/RouteProviderTest.php index b2829f6a97b..4855b371d36 100644 --- a/core-bundle/tests/Routing/RouteProviderTest.php +++ b/core-bundle/tests/Routing/RouteProviderTest.php @@ -192,21 +192,16 @@ public function testReturnsAnEmptyCollectionIfTheLanguageIsNotGiven(): void */ public function testFindsPagesByAliasCandidates(string $path, string $urlSuffix, bool $prependLocale, bool $folderUrl, array $aliases, array $ids = []): void { - $conditions = []; - - if (!empty($ids)) { - $conditions[] = 'tl_page.id IN ('.implode(',', $ids).')'; - } - - if (!empty($aliases)) { - $conditions[] = 'tl_page.alias IN ('.implode(',', $aliases).')'; - } + $pageAdapter = $this->mockAdapter(['findByPk', 'findByAlias']); + $pageAdapter + ->expects(empty($ids) ? $this->never() : $this->once()) + ->method('findByPk') + ->willReturn(null) + ; - $pageAdapter = $this->mockAdapter(['findBy']); $pageAdapter - ->expects($this->once()) - ->method('findBy') - ->with([implode(' OR ', $conditions)], []) + ->expects($this->exactly(\count($aliases))) + ->method('findByAlias') ->willReturn(null) ; @@ -317,10 +312,10 @@ public function getAliasCandidates(): \Generator */ public function testSortsTheRoutes(array $pages, array $languages): void { - $pageAdapter = $this->mockAdapter(['findBy']); + $pageAdapter = $this->mockAdapter(['findByAlias']); $pageAdapter ->expects($this->once()) - ->method('findBy') + ->method('findByAlias') ->willReturn(new Collection(array_values($pages), 'tl_page')) ; @@ -469,10 +464,10 @@ public function testAddsRoutesForAPage(string $alias, string $language, string $ { $page = $this->createPage($language, $alias, true, $domain, $scheme); - $pageAdapter = $this->mockAdapter(['findBy']); + $pageAdapter = $this->mockAdapter(['findByAlias']); $pageAdapter ->expects($this->once()) - ->method('findBy') + ->method('findByAlias') ->willReturn(new Collection([$page], 'tl_page')) ;