Skip to content

Commit

Permalink
Merge pull request thephpleague#258 from roxblnfk/feature/v3-update
Browse files Browse the repository at this point in the history
Update PHP version, phpunit and testcases for Plates v3 (thephpleague#257)
  • Loading branch information
ragboyjr committed Dec 23, 2020
2 parents 5f84d1f + 5eef170 commit 00116a1
Show file tree
Hide file tree
Showing 16 changed files with 331 additions and 216 deletions.
7 changes: 2 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- 7.4
- 8.0

sudo: false

Expand Down
13 changes: 9 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,23 @@
}
],
"require" : {
"php": "^5.3 | ^7.0"
"php": "^5.3|^7.0|^8.0"
},
"require-dev": {
"mikey179/vfsStream": "^1.4",
"phpunit/phpunit": "~4.0",
"squizlabs/php_codesniffer": "~1.5"
"mikey179/vfsstream": "^1.6",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.5"
},
"autoload": {
"psr-4": {
"League\\Plates\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"League\\Plates\\Tests\\": "tests"
}
},
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
Expand Down
42 changes: 29 additions & 13 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" bootstrap="vendor/autoload.php">

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.4/phpunit.xsd"
backupGlobals="false"
colors="true"
verbose="true"
bootstrap="vendor/autoload.php"
failOnRisky="true"
failOnWarning="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false"
executionOrder="random"
resolveDependencies="true"
>
<testsuites>
<testsuite name="all">
<directory suffix="Test.php">tests/</directory>
<testsuite name="Plates tests">
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>

<coverage>
<include>
<directory>src</directory>
</include>
</coverage>

<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<junit outputFile="build/report.junit.xml"/>
<testdoxHtml outputFile="build/coverage"/>
<testdoxText outputFile="build/coverage.txt"/>
<testdoxXml outputFile="build/logs/clover.xml"/>
</logging>
</phpunit>
12 changes: 8 additions & 4 deletions src/Template/Name.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,17 @@ public function getFile()
public function getPath()
{
if (is_null($this->folder)) {
return $this->getDefaultDirectory() . DIRECTORY_SEPARATOR . $this->file;
return "{$this->getDefaultDirectory()}/{$this->file}";
}

$path = $this->folder->getPath() . DIRECTORY_SEPARATOR . $this->file;
$path = "{$this->folder->getPath()}/{$this->file}";

if (!is_file($path) and $this->folder->getFallback() and is_file($this->getDefaultDirectory() . DIRECTORY_SEPARATOR . $this->file)) {
$path = $this->getDefaultDirectory() . DIRECTORY_SEPARATOR . $this->file;
if (
!is_file($path)
&& $this->folder->getFallback()
&& is_file("{$this->getDefaultDirectory()}/{$this->file}")
) {
$path = "{$this->getDefaultDirectory()}/{$this->file}";
}

return $path;
Expand Down
80 changes: 43 additions & 37 deletions tests/EngineTest.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?php

namespace League\Plates;
namespace League\Plates\Tests;

use League\Plates\Engine;
use org\bovigo\vfs\vfsStream;

class EngineTest extends \PHPUnit_Framework_TestCase
class EngineTest extends \PHPUnit\Framework\TestCase
{
private $engine;

public function setUp()
protected function setUp(): void
{
vfsStream::setup('templates');

Expand All @@ -23,41 +24,42 @@ public function testCanCreateInstance()
public function testSetDirectory()
{
$this->assertInstanceOf('League\Plates\Engine', $this->engine->setDirectory(vfsStream::url('templates')));
$this->assertEquals($this->engine->getDirectory(), vfsStream::url('templates'));
$this->assertSame(vfsStream::url('templates'), $this->engine->getDirectory());
}

public function testSetNullDirectory()
{
$this->assertInstanceOf('League\Plates\Engine', $this->engine->setDirectory(null));
$this->assertEquals($this->engine->getDirectory(), null);
$this->assertNull($this->engine->getDirectory());
}

public function testSetInvalidDirectory()
{
$this->setExpectedException('LogicException', 'The specified path "vfs://does/not/exist" does not exist.');
// The specified path "vfs://does/not/exist" does not exist.
$this->expectException(\LogicException::class);
$this->engine->setDirectory(vfsStream::url('does/not/exist'));
}

public function testGetDirectory()
{
$this->assertEquals($this->engine->getDirectory(), vfsStream::url('templates'));
$this->assertSame(vfsStream::url('templates'), $this->engine->getDirectory());
}

public function testSetFileExtension()
{
$this->assertInstanceOf('League\Plates\Engine', $this->engine->setFileExtension('tpl'));
$this->assertEquals($this->engine->getFileExtension(), 'tpl');
$this->assertSame('tpl', $this->engine->getFileExtension());
}

public function testSetNullFileExtension()
{
$this->assertInstanceOf('League\Plates\Engine', $this->engine->setFileExtension(null));
$this->assertEquals($this->engine->getFileExtension(), null);
$this->assertNull($this->engine->getFileExtension());
}

public function testGetFileExtension()
{
$this->assertEquals($this->engine->getFileExtension(), 'php');
$this->assertSame('php', $this->engine->getFileExtension());
}

public function testAddFolder()
Expand All @@ -71,19 +73,21 @@ public function testAddFolder()
);

$this->assertInstanceOf('League\Plates\Engine', $this->engine->addFolder('folder', vfsStream::url('templates/folder')));
$this->assertEquals($this->engine->getFolders()->get('folder')->getPath(), 'vfs://templates/folder');
$this->assertSame('vfs://templates/folder', $this->engine->getFolders()->get('folder')->getPath());
}

public function testAddFolderWithNamespaceConflict()
{
$this->setExpectedException('LogicException', 'The template folder "name" is already being used.');
// The template folder "name" is already being used.
$this->expectException(\LogicException::class);
$this->engine->addFolder('name', vfsStream::url('templates'));
$this->engine->addFolder('name', vfsStream::url('templates'));
}

public function testAddFolderWithInvalidDirectory()
{
$this->setExpectedException('LogicException', 'The specified directory path "vfs://does/not/exist" does not exist.');
// The specified directory path "vfs://does/not/exist" does not exist.
$this->expectException(\LogicException::class);
$this->engine->addFolder('namespace', vfsStream::url('does/not/exist'));
}

Expand All @@ -98,9 +102,9 @@ public function testRemoveFolder()
);

$this->engine->addFolder('folder', vfsStream::url('templates/folder'));
$this->assertEquals($this->engine->getFolders()->exists('folder'), true);
$this->assertTrue($this->engine->getFolders()->exists('folder'));
$this->assertInstanceOf('League\Plates\Engine', $this->engine->removeFolder('folder'));
$this->assertEquals($this->engine->getFolders()->exists('folder'), false);
$this->assertFalse($this->engine->getFolders()->exists('folder'));
}

public function testGetFolders()
Expand All @@ -112,21 +116,21 @@ public function testAddData()
{
$this->engine->addData(array('name' => 'Jonathan'));
$data = $this->engine->getData();
$this->assertEquals($data['name'], 'Jonathan');
$this->assertSame('Jonathan', $data['name']);
}

public function testAddDataWithTemplate()
{
$this->engine->addData(array('name' => 'Jonathan'), 'template');
$data = $this->engine->getData('template');
$this->assertEquals($data['name'], 'Jonathan');
$this->assertSame('Jonathan', $data['name']);
}

public function testAddDataWithTemplates()
{
$this->engine->addData(array('name' => 'Jonathan'), array('template1', 'template2'));
$data = $this->engine->getData('template1');
$this->assertEquals($data['name'], 'Jonathan');
$this->assertSame('Jonathan', $data['name']);
}

public function testRegisterFunction()
Expand All @@ -139,20 +143,21 @@ public function testRegisterFunction()

$this->engine->registerFunction('uppercase', 'strtoupper');
$this->assertInstanceOf('League\Plates\Template\Func', $this->engine->getFunction('uppercase'));
$this->assertEquals($this->engine->getFunction('uppercase')->getCallback(), 'strtoupper');
$this->assertSame('strtoupper', $this->engine->getFunction('uppercase')->getCallback());
}

public function testDropFunction()
{
$this->engine->registerFunction('uppercase', 'strtoupper');
$this->assertEquals($this->engine->doesFunctionExist('uppercase'), true);
$this->assertTrue($this->engine->doesFunctionExist('uppercase'));
$this->engine->dropFunction('uppercase');
$this->assertEquals($this->engine->doesFunctionExist('uppercase'), false);
$this->assertFalse($this->engine->doesFunctionExist('uppercase'));
}

public function testDropInvalidFunction()
{
$this->setExpectedException('LogicException', 'The template function "some_function_that_does_not_exist" was not found.');
// The template function "some_function_that_does_not_exist" was not found.
$this->expectException(\LogicException::class);
$this->engine->dropFunction('some_function_that_does_not_exist');
}

Expand All @@ -162,38 +167,39 @@ public function testGetFunction()
$function = $this->engine->getFunction('uppercase');

$this->assertInstanceOf('League\Plates\Template\Func', $function);
$this->assertEquals($function->getName(), 'uppercase');
$this->assertEquals($function->getCallback(), 'strtoupper');
$this->assertSame('uppercase', $function->getName());
$this->assertSame('strtoupper', $function->getCallback());
}

public function testGetInvalidFunction()
{
$this->setExpectedException('LogicException', 'The template function "some_function_that_does_not_exist" was not found.');
// The template function "some_function_that_does_not_exist" was not found.
$this->expectException(\LogicException::class);
$this->engine->getFunction('some_function_that_does_not_exist');
}

public function testDoesFunctionExist()
{
$this->engine->registerFunction('uppercase', 'strtoupper');
$this->assertEquals($this->engine->doesFunctionExist('uppercase'), true);
$this->assertTrue($this->engine->doesFunctionExist('uppercase'));
}

public function testDoesFunctionNotExist()
{
$this->assertEquals($this->engine->doesFunctionExist('some_function_that_does_not_exist'), false);
$this->assertFalse($this->engine->doesFunctionExist('some_function_that_does_not_exist'));
}

public function testLoadExtension()
{
$this->assertEquals($this->engine->doesFunctionExist('uri'), false);
$this->assertFalse($this->engine->doesFunctionExist('uri'));
$this->assertInstanceOf('League\Plates\Engine', $this->engine->loadExtension(new \League\Plates\Extension\URI('')));
$this->assertEquals($this->engine->doesFunctionExist('uri'), true);
$this->assertTrue($this->engine->doesFunctionExist('uri'));
}

public function testLoadExtensions()
{
$this->assertEquals($this->engine->doesFunctionExist('uri'), false);
$this->assertEquals($this->engine->doesFunctionExist('asset'), false);
$this->assertFalse($this->engine->doesFunctionExist('uri'));
$this->assertFalse($this->engine->doesFunctionExist('asset'));
$this->assertInstanceOf(
'League\Plates\Engine',
$this->engine->loadExtensions(
Expand All @@ -203,26 +209,26 @@ public function testLoadExtensions()
)
)
);
$this->assertEquals($this->engine->doesFunctionExist('uri'), true);
$this->assertEquals($this->engine->doesFunctionExist('asset'), true);
$this->assertTrue($this->engine->doesFunctionExist('uri'));
$this->assertTrue($this->engine->doesFunctionExist('asset'));
}

public function testGetTemplatePath()
{
$this->assertEquals($this->engine->path('template'), 'vfs://templates/template.php');
$this->assertSame('vfs://templates/template.php', $this->engine->path('template'));
}

public function testTemplateExists()
{
$this->assertEquals($this->engine->exists('template'), false);
$this->assertFalse($this->engine->exists('template'));

vfsStream::create(
array(
'template.php' => '',
)
);

$this->assertEquals($this->engine->exists('template'), true);
$this->assertTrue($this->engine->exists('template'));
}

public function testMakeTemplate()
Expand All @@ -244,6 +250,6 @@ public function testRenderTemplate()
)
);

$this->assertEquals($this->engine->render('template'), 'Hello!');
$this->assertSame('Hello!', $this->engine->render('template'));
}
}
15 changes: 10 additions & 5 deletions tests/Extension/AssetTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<?php

namespace League\Plates\Extension;
declare(strict_types=1);

namespace League\Plates\Tests\Extension;

use League\Plates\Engine;
use League\Plates\Extension\Asset;
use org\bovigo\vfs\vfsStream;
use PHPUnit\Framework\TestCase;

class AssetTest extends \PHPUnit_Framework_TestCase
class AssetTest extends TestCase
{
public function setUp()
protected function setUp(): void
{
vfsStream::setup('assets');
}
Expand All @@ -24,7 +28,7 @@ public function testRegister()
$engine = new Engine();
$extension = new Asset(vfsStream::url('assets'));
$extension->register($engine);
$this->assertEquals($engine->doesFunctionExist('asset'), true);
$this->assertTrue($engine->doesFunctionExist('asset'));
}

public function testCachedAssetUrl()
Expand Down Expand Up @@ -68,7 +72,8 @@ public function testCachedAssetUrlUsingFilenameMethod()

public function testFileNotFoundException()
{
$this->setExpectedException('LogicException', 'Unable to locate the asset "styles.css" in the "' . vfsStream::url('assets') . '" directory.');
// Unable to locate the asset "styles.css" in the @assets directory.
$this->expectException(\LogicException::class);

$extension = new Asset(vfsStream::url('assets'));
$extension->cachedAssetUrl('styles.css');
Expand Down
Loading

0 comments on commit 00116a1

Please sign in to comment.