/** * @test */ public function addRedirectEmitSignalAndFlushesRouterCacheForAffectedUri() { $this->mockRedirectRepository->expects($this->atLeastOnce())->method('findByTargetUriPathAndHost')->willReturn([]); $this->mockRouterCachingService->expects($this->once())->method('flushCachesForUriPath')->with('some/relative/path'); $this->redirectServiceMock->expects($this->atLeastOnce())->method('emitRedirectCreated'); $this->redirectStorage->addRedirect('some/relative/path', 'target'); }
/** * @test */ public function routeStoresMatchResultsInCacheIfNotFoundInCache() { $router = $this->getAccessibleMock(Router::class, ['createRoutesFromConfiguration']); $this->inject($router, 'routerCachingService', $this->mockRouterCachingService); $this->inject($router, 'systemLogger', $this->mockSystemLogger); $matchResults = ['some' => 'match results']; $mockHttpRequest = $this->getMockBuilder(Request::class)->disableOriginalConstructor()->getMock(); $mockRoute1 = $this->getMockBuilder(Route::class)->getMock(); $mockRoute1->expects($this->once())->method('matches')->with($mockHttpRequest)->will($this->returnValue(false)); $mockRoute2 = $this->getMockBuilder(Route::class)->getMock(); $mockRoute2->expects($this->once())->method('matches')->with($mockHttpRequest)->will($this->returnValue(true)); $mockRoute2->expects($this->once())->method('getMatchResults')->will($this->returnValue($matchResults)); $router->_set('routes', [$mockRoute1, $mockRoute2]); $this->mockRouterCachingService->expects($this->once())->method('storeMatchResults')->with($mockHttpRequest, $matchResults); $this->assertSame($matchResults, $router->route($mockHttpRequest)); }