|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Slepic\Tests\Templating\Template; |
| 6 | + |
| 7 | +use PHPUnit\Framework\TestCase; |
| 8 | +use Slepic\Templating\Template\DefaultDataTemplate; |
| 9 | +use Slepic\Templating\Template\TemplateInterface; |
| 10 | + |
| 11 | +final class DefaultDataTemplateTest extends TestCase |
| 12 | +{ |
| 13 | + public function testImplements(): void |
| 14 | + { |
| 15 | + $innerTemplate = self::createMock(TemplateInterface::class); |
| 16 | + $template = new DefaultDataTemplate($innerTemplate, []); |
| 17 | + $this->assertInstanceOf(TemplateInterface::class, $template); |
| 18 | + } |
| 19 | + |
| 20 | + /** |
| 21 | + * @param array $defaultData |
| 22 | + * @param array $data |
| 23 | + * @param array $allData |
| 24 | + * |
| 25 | + * @dataProvider provideRenderData |
| 26 | + */ |
| 27 | + public function testRender(array $defaultData, array $data, array $allData): void |
| 28 | + { |
| 29 | + $hash = \md5((string) \time()); |
| 30 | + $innerTemplate = self::createMock(TemplateInterface::class); |
| 31 | + $innerTemplate->expects(self::once()) |
| 32 | + ->method('render') |
| 33 | + ->with($allData) |
| 34 | + ->willReturn($hash); |
| 35 | + $template = new DefaultDataTemplate($innerTemplate, $defaultData); |
| 36 | + $output = $template->render($data); |
| 37 | + self::assertSame($hash, $output); |
| 38 | + } |
| 39 | + |
| 40 | + public function provideRenderData(): array |
| 41 | + { |
| 42 | + $hash = \md5((string) \time()); |
| 43 | + return [ |
| 44 | + [[], [], []], |
| 45 | + [ |
| 46 | + ['default' => 'value'], |
| 47 | + ['test' => $hash], |
| 48 | + ['test' => $hash, 'default' => 'value'] |
| 49 | + ], |
| 50 | + [ |
| 51 | + ['override' => 'default'], |
| 52 | + ['keep' => $hash, 'override' => 'overridden'], |
| 53 | + ['keep' => $hash, 'override' => 'overridden'] |
| 54 | + ], |
| 55 | + ]; |
| 56 | + } |
| 57 | +} |
0 commit comments