From 401dae9e0764b7257529a8066bb9965f29b709f5 Mon Sep 17 00:00:00 2001 From: Aldarien Date: Mon, 29 Sep 2025 13:37:26 -0300 Subject: [PATCH] Added Slim\Views namespace extension --- composer.json | 3 +- lib/Slim/Views/ViewInterface.php | 9 +++++ src/Define/View.php | 2 +- src/Implement/Blade.php | 6 +++ tests/BladeTest.php | 15 +++++++ tests/BladeTests.php | 68 ++++++++++++++++++++++++++++++++ tests/ViewTest.php | 25 +++--------- 7 files changed, 107 insertions(+), 21 deletions(-) create mode 100644 lib/Slim/Views/ViewInterface.php create mode 100644 src/Implement/Blade.php create mode 100644 tests/BladeTest.php create mode 100644 tests/BladeTests.php 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 @@ +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 = <<