From f845a5ab8b67e1d0b11779f1754bcc3f2193d67b Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sun, 28 Oct 2018 12:59:49 +0100 Subject: Added caching for templating and routing See #486 (Implement caching) --- tests/Unit/ApplicationTest.php | 4 ++++ .../Middleware/RouteDispatcherServiceProviderTest.php | 11 ++++++++++- tests/Unit/Renderer/TwigServiceProviderTest.php | 16 ++++++++-------- 3 files changed, 22 insertions(+), 9 deletions(-) (limited to 'tests/Unit') diff --git a/tests/Unit/ApplicationTest.php b/tests/Unit/ApplicationTest.php index e6d77c7d..3fffe5ea 100644 --- a/tests/Unit/ApplicationTest.php +++ b/tests/Unit/ApplicationTest.php @@ -51,6 +51,10 @@ class ApplicationTest extends TestCase $this->assertTrue($app->has('path.lang')); $this->assertTrue($app->has('path.resources')); $this->assertTrue($app->has('path.views')); + $this->assertTrue($app->has('path.storage')); + $this->assertTrue($app->has('path.cache')); + $this->assertTrue($app->has('path.cache.routes')); + $this->assertTrue($app->has('path.cache.views')); $this->assertEquals(realpath('.'), $app->path()); $this->assertEquals(realpath('.') . '/config', $app->get('path.config')); diff --git a/tests/Unit/Middleware/RouteDispatcherServiceProviderTest.php b/tests/Unit/Middleware/RouteDispatcherServiceProviderTest.php index ca784c73..3947ac37 100644 --- a/tests/Unit/Middleware/RouteDispatcherServiceProviderTest.php +++ b/tests/Unit/Middleware/RouteDispatcherServiceProviderTest.php @@ -2,6 +2,7 @@ namespace Engelsystem\Test\Unit\Middleware; +use Engelsystem\Config\Config; use Engelsystem\Middleware\LegacyMiddleware; use Engelsystem\Middleware\RouteDispatcher; use Engelsystem\Middleware\RouteDispatcherServiceProvider; @@ -18,10 +19,18 @@ class RouteDispatcherServiceProviderTest extends ServiceProviderTest */ public function testRegister() { + /** @var ContextualBindingBuilder|MockObject $bindingBuilder */ $bindingBuilder = $this->createMock(ContextualBindingBuilder::class); + /** @var FastRouteDispatcher|MockObject $routeDispatcher */ $routeDispatcher = $this->getMockForAbstractClass(FastRouteDispatcher::class); + $config = new Config(['environment' => 'development']); - $app = $this->getApp(['alias', 'when']); + $app = $this->getApp(['alias', 'when', 'get']); + + $app->expects($this->exactly(2)) + ->method('get') + ->withConsecutive(['config'], ['path.cache.routes']) + ->willReturn($config, '/foo/routes.cache'); $app->expects($this->once()) ->method('alias') diff --git a/tests/Unit/Renderer/TwigServiceProviderTest.php b/tests/Unit/Renderer/TwigServiceProviderTest.php index 0d632633..86dee1de 100644 --- a/tests/Unit/Renderer/TwigServiceProviderTest.php +++ b/tests/Unit/Renderer/TwigServiceProviderTest.php @@ -91,7 +91,7 @@ class TwigServiceProviderTest extends ServiceProviderTest /** * @covers \Engelsystem\Renderer\TwigServiceProvider::registerTwigEngine */ - public function testRegisterTWigEngine() + public function testRegisterTwigEngine() { /** @var TwigEngine|MockObject $htmlEngine */ $twigEngine = $this->createMock(TwigEngine::class); @@ -114,7 +114,7 @@ class TwigServiceProviderTest extends ServiceProviderTest ->method('make') ->withConsecutive( [TwigLoader::class, ['paths' => $viewsPath]], - [Twig::class], + [Twig::class, ['options' => ['cache' => false, 'auto_reload' => true, 'strict_variables' => true]]], [TwigEngine::class] )->willReturnOnConsecutiveCalls( $twigLoader, @@ -133,17 +133,17 @@ class TwigServiceProviderTest extends ServiceProviderTest ['renderer.twigEngine', $twigEngine] ); - $app->expects($this->exactly(2)) + $app->expects($this->exactly(3)) ->method('get') - ->withConsecutive(['path.views'], ['config']) - ->willReturnOnConsecutiveCalls($viewsPath, $config); + ->withConsecutive(['path.views'], ['config'], ['path.cache.views']) + ->willReturnOnConsecutiveCalls($viewsPath, $config, 'cache/views'); $this->setExpects($app, 'tag', ['renderer.twigEngine', ['renderer.engine']]); - $config->expects($this->once()) + $config->expects($this->exactly(3)) ->method('get') - ->with('timezone') - ->willReturn('The/World'); + ->withConsecutive(['environment'], ['environment'], ['timezone']) + ->willReturnOnConsecutiveCalls('development', 'development', 'The/World'); $twig->expects($this->once()) ->method('getExtension') -- cgit v1.2.3-54-g00ecf