Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
8680b43e40 | |||
401dae9e07 | |||
6f34ae24ec | |||
8eaff5b757 | |||
bbd5b4e8f1 | |||
3ce904c7af | |||
daa8f0f248 | |||
6b7097ec01 | |||
72b2df4c67 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
# Composer
|
||||
/vendor/
|
||||
**/vendor/
|
||||
composer.lock
|
||||
**/.phpunit.cache/
|
||||
|
@ -1,8 +0,0 @@
|
||||
<?php
|
||||
namespace ProVM\Common\Define;
|
||||
|
||||
use Slim\Views\Blade;
|
||||
use ProVM\Common\Alias\View as ViewInterface;
|
||||
|
||||
class View extends Blade implements ViewInterface {
|
||||
}
|
@ -3,11 +3,10 @@
|
||||
"description": "View wrapper for slim-blade-view",
|
||||
"type": "library",
|
||||
"require": {
|
||||
"rubellum/slim-blade-view": "^0.1.1"
|
||||
"berrnd/slim-blade-view": "^1"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^9.2",
|
||||
"kint-php/kint": "^3.3"
|
||||
"phpunit/phpunit": "*"
|
||||
},
|
||||
"license": "proprietary",
|
||||
"authors": [
|
||||
@ -18,7 +17,8 @@
|
||||
],
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"ProVM\\Common\\": "./common"
|
||||
"View\\": "src/",
|
||||
"Slim\\Views\\": "lib/Slim/Views"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
9
lib/Slim/Views/ViewInterface.php
Normal file
9
lib/Slim/Views/ViewInterface.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace Slim\Views;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
interface ViewInterface
|
||||
{
|
||||
public function render(ResponseInterface $response, $template, array $data = []);
|
||||
}
|
25
phpunit.xml
Normal file
25
phpunit.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
|
||||
bootstrap="vendor/autoload.php"
|
||||
cacheDirectory=".phpunit.cache"
|
||||
executionOrder="depends,defects"
|
||||
requireCoverageMetadata="false"
|
||||
beStrictAboutCoverageMetadata="false"
|
||||
beStrictAboutOutputDuringTests="true"
|
||||
displayDetailsOnPhpunitDeprecations="true"
|
||||
failOnPhpunitDeprecation="true"
|
||||
failOnRisky="true"
|
||||
failOnWarning="true">
|
||||
<testsuites>
|
||||
<testsuite name="default">
|
||||
<directory>tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true">
|
||||
<include>
|
||||
<directory>src</directory>
|
||||
</include>
|
||||
</source>
|
||||
</phpunit>
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace ProVM\Common\Alias;
|
||||
namespace View\Define;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
|
6
src/Implement/Blade.php
Normal file
6
src/Implement/Blade.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace View\Implement;
|
||||
|
||||
use Slim\Views;
|
||||
|
||||
class Blade extends Views\Blade implements Views\ViewInterface {}
|
7
src/Implement/View.php
Normal file
7
src/Implement/View.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace View\Implement;
|
||||
|
||||
use Slim\Views\Blade;
|
||||
use View\Define;
|
||||
|
||||
class View extends Blade implements Define\View {}
|
15
tests/BladeTest.php
Normal file
15
tests/BladeTest.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
require_once 'BladeTests.php';
|
||||
|
||||
class BladeTest extends BladeTests
|
||||
{
|
||||
public function testRender(): void
|
||||
{
|
||||
$response = $this->getResponse();
|
||||
|
||||
$view = new View\Implement\Blade($this->templatesFolder, $this->cacheFolder);
|
||||
|
||||
$result = $view->render($response, $this->templateName);
|
||||
$this->assertEquals($this->template, $result->getBody()->getContents());
|
||||
}
|
||||
}
|
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());
|
||||
}
|
||||
}
|
||||
}
|
15
tests/ViewTest.php
Normal file
15
tests/ViewTest.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
require_once 'BladeTests.php';
|
||||
|
||||
class ViewTest extends BladeTests
|
||||
{
|
||||
public function testRender(): void
|
||||
{
|
||||
$response = $this->getResponse();
|
||||
|
||||
$view = new View\Implement\View($this->templatesFolder, $this->cacheFolder);
|
||||
|
||||
$result = $view->render($response, $this->templateName);
|
||||
$this->assertEquals($this->template, $result->getBody()->getContents());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user