diff options
author | Igor Scheller <igor.scheller@igorshp.de> | 2018-12-03 23:39:50 +0100 |
---|---|---|
committer | Igor Scheller <igor.scheller@igorshp.de> | 2019-07-08 01:58:06 +0200 |
commit | e9f157ec5ccdfae73b4c9e82c9ae7c37bcfa1513 (patch) | |
tree | fea2fdb1df183008f31f7827d9f83a5f6fc13cfb /tests/Unit | |
parent | bcce2625a8cb0b630d945c6849014049869e10ce (diff) |
Renderer: Added shared data
Diffstat (limited to 'tests/Unit')
-rw-r--r-- | tests/Unit/Controllers/Metrics/MetricsEngineTest.php | 11 | ||||
-rw-r--r-- | tests/Unit/Renderer/EngineTest.php | 25 | ||||
-rw-r--r-- | tests/Unit/Renderer/HtmlEngineTest.php | 5 | ||||
-rw-r--r-- | tests/Unit/Renderer/Stub/EngineImplementation.php | 32 | ||||
-rw-r--r-- | tests/Unit/Renderer/TwigEngineTest.php | 12 |
5 files changed, 77 insertions, 8 deletions
diff --git a/tests/Unit/Controllers/Metrics/MetricsEngineTest.php b/tests/Unit/Controllers/Metrics/MetricsEngineTest.php index 38817b36..87a7dc88 100644 --- a/tests/Unit/Controllers/Metrics/MetricsEngineTest.php +++ b/tests/Unit/Controllers/Metrics/MetricsEngineTest.php @@ -66,4 +66,15 @@ class MetricsEngineTest extends TestCase $this->assertFalse($engine->canRender('/metrics.foo')); $this->assertTrue($engine->canRender('/metrics')); } + + /** + * @covers \Engelsystem\Controllers\Metrics\MetricsEngine::share + */ + public function testShare() + { + $engine = new MetricsEngine(); + + $engine->share('foo', 42); + $this->assertEquals('', $engine->get('/metrics')); + } } diff --git a/tests/Unit/Renderer/EngineTest.php b/tests/Unit/Renderer/EngineTest.php new file mode 100644 index 00000000..659d85c5 --- /dev/null +++ b/tests/Unit/Renderer/EngineTest.php @@ -0,0 +1,25 @@ +<?php + +namespace Engelsystem\Test\Unit\Renderer; + +use Engelsystem\Test\Unit\Renderer\Stub\EngineImplementation; +use PHPUnit\Framework\TestCase; + +class EngineTest extends TestCase +{ + /** + * @covers \Engelsystem\Renderer\Engine::share + */ + public function testShare() + { + $engine = new EngineImplementation(); + $engine->share(['foo' => ['bar' => 'baz', 'lorem' => 'ipsum']]); + $engine->share(['foo' => ['lorem' => 'dolor']]); + $engine->share('key', 'value'); + + $this->assertEquals( + ['foo' => ['bar' => 'baz', 'lorem' => 'dolor'], 'key' => 'value'], + $engine->getSharedData() + ); + } +} diff --git a/tests/Unit/Renderer/HtmlEngineTest.php b/tests/Unit/Renderer/HtmlEngineTest.php index 4a31e4bc..f76e7528 100644 --- a/tests/Unit/Renderer/HtmlEngineTest.php +++ b/tests/Unit/Renderer/HtmlEngineTest.php @@ -16,11 +16,12 @@ class HtmlEngineTest extends TestCase public function testGet() { $engine = new HtmlEngine(); + $engine->share('shared_data', 'tester'); - $file = $this->createTempFile('<div>%main_content%</div>'); + $file = $this->createTempFile('<div>%main_content% is a %shared_data%</div>'); $data = $engine->get($file, ['main_content' => 'Lorem ipsum dolor sit']); - $this->assertEquals('<div>Lorem ipsum dolor sit</div>', $data); + $this->assertEquals('<div>Lorem ipsum dolor sit is a tester</div>', $data); } /** diff --git a/tests/Unit/Renderer/Stub/EngineImplementation.php b/tests/Unit/Renderer/Stub/EngineImplementation.php new file mode 100644 index 00000000..fc436569 --- /dev/null +++ b/tests/Unit/Renderer/Stub/EngineImplementation.php @@ -0,0 +1,32 @@ +<?php + +namespace Engelsystem\Test\Unit\Renderer\Stub; + +use Engelsystem\Renderer\Engine; + +class EngineImplementation extends Engine +{ + /** + * @inheritdoc + */ + public function get(string $path, array $data = []): string + { + return ''; + } + + /** + * @inheritdoc + */ + public function canRender(string $path): bool + { + return true; + } + + /** + * @return array + */ + public function getSharedData(): array + { + return $this->sharedData; + } +} diff --git a/tests/Unit/Renderer/TwigEngineTest.php b/tests/Unit/Renderer/TwigEngineTest.php index 9d0618f1..5e5e59d9 100644 --- a/tests/Unit/Renderer/TwigEngineTest.php +++ b/tests/Unit/Renderer/TwigEngineTest.php @@ -20,16 +20,16 @@ class TwigEngineTest extends TestCase $twig = $this->createMock(Twig::class); $path = 'foo.twig'; - $data = ['lorem' => 'ipsum']; - $twig->expects($this->once()) ->method('render') - ->with($path, $data) - ->willReturn('LoremIpsum!'); + ->with($path, ['lorem' => 'ipsum', 'shared' => 'data']) + ->willReturn('LoremIpsum data!'); $engine = new TwigEngine($twig); - $return = $engine->get($path, $data); - $this->assertEquals('LoremIpsum!', $return); + $engine->share('shared', 'data'); + + $return = $engine->get($path, ['lorem' => 'ipsum']); + $this->assertEquals('LoremIpsum data!', $return); } |