diff --git a/.gitignore b/.gitignore index 0a58e42..205b3eb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ # Composer **/vendor/ composer.lock +**/.phpunit.cache/ diff --git a/composer.json b/composer.json index 9cc7ccc..a189130 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ ], "autoload": { "psr-4": { - "View\\": "src/" + "View\\": "src/", + "Slim\\Views\\": "lib/Slim/Views" } } } diff --git a/lib/Slim/Views/ViewInterface.php b/lib/Slim/Views/ViewInterface.php new file mode 100644 index 0000000..39e70cf --- /dev/null +++ b/lib/Slim/Views/ViewInterface.php @@ -0,0 +1,9 @@ + + + + + tests + + + + + + src + + + diff --git a/src/Define/View.php b/src/Define/View.php index 40dbeee..29da123 100644 --- a/src/Define/View.php +++ b/src/Define/View.php @@ -1,5 +1,5 @@ getResponse(); + + $view = new View\Implement\Blade($this->templatesFolder, $this->cacheFolder); + + $result = $view->render($response, $this->templateName); + $this->assertEquals($this->template, $result->getBody()->getContents()); + } +} \ No newline at end of file diff --git a/tests/BladeTests.php b/tests/BladeTests.php new file mode 100644 index 0000000..45e404e --- /dev/null +++ b/tests/BladeTests.php @@ -0,0 +1,68 @@ +setFolders(); + $this->setTemplate(); + } + protected function tearDown(): void + { + $this->removeFiles(); + $this->removeFolders(); + } + + protected function getResponse(): Psr\Http\Message\ResponseInterface + { + $response = $this->getMockBuilder(Psr\Http\Message\ResponseInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $body = $this->getMockBuilder(Psr\Http\Message\StreamInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $body->method('getContents')->willReturn($this->template); + $body->method('write')->willReturn($body); + $response->method('getBody')->willReturn($body); + + return $response; + } + + protected function setFolders(): void + { + mkdir($this->templatesFolder); + mkdir($this->cacheFolder); + chmod($this->cacheFolder, 0o777); + } + protected function removeFolders(): void + { + rmdir($this->cacheFolder); + rmdir($this->templatesFolder); + } + protected function setTemplate(): void + { + $this->templateName = 'test'; + $this->template = <<