Added Slim\Views namespace extension
This commit is contained in:
68
tests/BladeTests.php
Normal file
68
tests/BladeTests.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
abstract class BladeTests extends TestCase
|
||||
{
|
||||
protected string $templatesFolder = './templates';
|
||||
protected string $cacheFolder = './cache';
|
||||
protected string $templateName;
|
||||
protected string $template;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->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 = <<<TEMPLATE
|
||||
Test Template
|
||||
TEMPLATE;
|
||||
file_put_contents("{$this->templatesFolder}/{$this->templateName}.blade.php", $this->template);
|
||||
}
|
||||
protected function removeFiles(): void
|
||||
{
|
||||
$files = new FilesystemIterator($this->cacheFolder);
|
||||
foreach ($files as $file) {
|
||||
unlink($file->getRealPath());
|
||||
}
|
||||
|
||||
$files = new FilesystemIterator($this->templatesFolder);
|
||||
foreach ($files as $file) {
|
||||
unlink($file->getRealPath());
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user