68 lines
1.9 KiB
PHP
68 lines
1.9 KiB
PHP
|
<?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());
|
||
|
}
|
||
|
}
|
||
|
}
|