PHP 8.0 compatibility update.
continuous-integration/drone/push Build is passing Details

- Removed Smarty support
- PHPUnit 9 support
- Auto testing with drone.
This commit is contained in:
Abel Hoogeveen 2021-11-29 21:54:10 +01:00
parent 777a0fe7c5
commit 7f3341bdc2
Signed by: abelhooge
GPG Key ID: C540221690CBFFBA
16 changed files with 108 additions and 356 deletions

30
.drone.yml Normal file
View File

@ -0,0 +1,30 @@
kind: pipeline
type: docker
name: test
steps:
- name: composer
image: composer:latest
commands:
- composer install
- name: php74test
image: registry.i15.nl/i15/fuzephp:7.4-alpine
commands:
- docker-php-ext-enable xdebug
- vendor/bin/phpunit -c test/phpunit.xml
- name: php80test
image: registry.i15.nl/i15/fuzephp:8.0-alpine
commands:
- docker-php-ext-enable xdebug
- vendor/bin/phpunit -c test/phpunit.xml
- name: coverage
image: registry.i15.nl/i15/fuzephp:8.0-alpine
commands:
- docker-php-ext-enable xdebug
- vendor/bin/phpunit -c test/phpunit.xml --coverage-text
image_pull_secrets:
- dockerconfig

3
.gitignore vendored
View File

@ -3,4 +3,5 @@ composer.phar
.idea/
build/
test/temp/
vendor/
vendor/
*.cache

View File

@ -1,82 +0,0 @@
before_script:
# Install dependencies
- set -xe
- apt-get update -yqq
- apt-get install git zip unzip -yqq
stages:
- build
- test
- deploy
build:composer:
image: php:7.2
stage: build
script:
- curl -sS https://getcomposer.org/installer | php
- php composer.phar install
cache:
key: "$CI_BUILD_REF_$CI_BUILD_REF_NAME"
paths:
- vendor/
test:7.1:
stage: test
image: php:7.1
script:
- vendor/bin/phpunit -c test/phpunit.xml
cache:
key: "$CI_BUILD_REF_$CI_BUILD_REF_NAME"
paths:
- vendor
test:7.2:
stage: test
image: php:7.2
script:
- vendor/bin/phpunit -c test/phpunit.xml
cache:
key: "$CI_BUILD_REF_$CI_BUILD_REF_NAME"
paths:
- vendor/
test:7.3:
stage: test
image: php:7.3
script:
- vendor/bin/phpunit -c test/phpunit.xml
cache:
key: "$CI_BUILD_REF_$CI_BUILD_REF_NAME"
paths:
- vendor/
test:coverage:
stage: test
image: php:7.2
script:
- pecl install xdebug
- docker-php-ext-enable xdebug
- vendor/bin/phpunit -c test/phpunit.xml --coverage-text
cache:
key: "$CI_BUILD_REF_$CI_BUILD_REF_NAME"
paths:
- vendor/
release:
stage: deploy
image: php:7.2
only:
- master
script:
- pecl install xdebug
- docker-php-ext-enable xdebug
- vendor/bin/phpunit -c test/phpunit.xml --coverage-text
artifacts:
name: "${CI_BUILD_NAME}_${CI_BUILD_REF_NAME}"
paths:
- build/
expire_in: 3 weeks
cache:
key: "$CI_BUILD_REF_$CI_BUILD_REF_NAME"
paths:
- vendor/

View File

@ -1,12 +0,0 @@
language: php
php:
- 7.1
- 7.2
- 7.3
script:
- php vendor/bin/phpunit -v -c test/phpunit.xml --coverage-text
before_script:
- composer install

View File

@ -1,7 +1,7 @@
FuzeWorks::Layout Component - Readme
===================
Version 1.2.0
Version 1.3.0
A versatile PHP Framework built to perform.

View File

@ -4,27 +4,21 @@
"license": ["MIT"],
"authors": [
{
"name": "TechFuze",
"homepage": "https://techfuze.net"
},
{
"name": "FuzeWorks Community",
"homepage": "https://techfuze.net/fuzeworks/contributors"
"name": "Abel Hoogeveen",
"homepage": "https://i15.nl"
}
],
"require": {
"php": ">=7.1.0",
"fuzeworks/core": "~1.2.0"
"php": ">=7.4.0",
"fuzeworks/core": "~1.3.0"
},
"require-dev": {
"ext-json": "*",
"smarty/smarty": "3.1.*",
"latte/latte": "2.5.*",
"phpunit/phpunit": "^7",
"mikey179/vfsstream": "1.6.5"
"latte/latte": "~2.5",
"phpunit/phpunit": "^9",
"mikey179/vfsstream": "~1.6.0"
},
"suggest": {
"smarty/smarty": "Template Engine that is natively supported by FuzeWorks.",
"latte/latte": "Template Engine that is natively supported by FuzeWorks"
},
"autoload": {
@ -32,5 +26,4 @@
"FuzeWorks\\": "src/FuzeWorks/"
}
}
}

View File

@ -31,14 +31,13 @@
* @link http://techfuze.net/fuzeworks
* @since Version 0.0.1
*
* @version Version 1.2.0
* @version Version 1.3.0
*/
namespace FuzeWorks;
use FuzeWorks\Event\LayoutLoadEvent;
use FuzeWorks\TemplateEngine\{JsonEngine,PHPEngine,SmartyEngine,LatteEngine,TemplateEngine};
use FuzeWorks\TemplateEngine\{JsonEngine,PHPEngine,LatteEngine,TemplateEngine};
use FuzeWorks\Exception\LayoutException;
use FuzeWorks\Exception\EventException;
@ -509,10 +508,6 @@ class Layout
if (class_exists('\Latte\Engine', true))
$this->registerEngine(new LatteEngine(), 'Latte', array('latte'));
// Smarty Engine
if (class_exists('\Smarty', true))
$this->registerEngine(new SmartyEngine(), 'Smarty', array('tpl'));
$this->engines_loaded = true;
return true;
}

View File

@ -1,172 +0,0 @@
<?php
/**
* FuzeWorks Framework Layout Template System.
*
* The FuzeWorks PHP FrameWork
*
* Copyright (C) 2013-2018 TechFuze
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @author TechFuze
* @copyright Copyright (c) 2013 - 2018, TechFuze. (http://techfuze.net)
* @license https://opensource.org/licenses/MIT MIT License
*
* @link http://techfuze.net/fuzeworks
* @since Version 0.0.1
*
* @version Version 1.2.0
*/
namespace FuzeWorks\TemplateEngine;
use FuzeWorks\Core;
use Smarty;
/**
* Wrapper for the Smarty Template Engine.
*
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2018, TechFuze. (http://techfuze.net)
*/
class SmartyEngine implements TemplateEngine
{
/**
* The currently used directory by the template.
*
* @var string
*/
protected $directory;
/**
* All the currently assigned variables.
*
* @var array
*/
protected $assigned_variables = array();
/**
* Instance of the Smarty Template Engine.
*
* @var \Smarty
*/
protected $smartyInstance;
public function setDirectory($directory)
{
$this->directory = $directory;
}
public function get($file, $assigned_variables)
{
// First set all the variables
$this->assigned_variables = $assigned_variables;
// Load Smarty
$this->loadSmarty();
// Set the directory
$this->smartyInstance->setTemplateDir($this->directory);
// Then assign all variables
foreach ($this->assigned_variables as $key => $value) {
$this->smartyInstance->assign($key, $value);
}
// And finally, load the template
return $this->smartyInstance->fetch($file);
}
/**
* Loads a Smarty instance if it is not already loaded.
*/
private function loadSmarty()
{
if (is_null($this->smartyInstance)) {
$this->smartyInstance = new Smarty();
// Then prepare all variables
$this->smartyInstance->setCompileDir(Core::$tempDir . DS . 'Smarty' . DS . 'Compile');
$this->smartyInstance->setCacheDir(Core::$tempDir . DS . 'Smarty');
}
}
public function getFileExtensions(): array
{
return array('tpl');
}
public function reset(): bool
{
$this->smartyInstance = null;
$this->directory = null;
$this->assigned_variables = array();
return true;
}
/**
* Retrieve a value from Smarty.
*
* @param string $name Variable name
*
* @return mixed Variable Value
*
* @throws \FuzeWorks\LayoutException on error
*/
public function __get($name)
{
// First load Smarty
$this->loadSmarty();
return $this->smartyInstance->$name;
}
/**
* Set a variable in Smarty.
*
* @param string $name Variable Name
* @param mixed $value Variable Value
*
* @throws \FuzeWorks\LayoutException on error
*/
public function __set($name, $value)
{
// First load Smarty
$this->loadSmarty();
$this->smartyInstance->$name = $value;
}
/**
* Calls a function in Smarty.
*
* @param string $name Name of the function to be called
* @param Paramaters $params Parameters to be used
*
* @return mixed Function output
*/
public function __call($name, $params)
{
// First load Smarty
$this->loadSmarty();
return call_user_func_array(array($this->smartyInstance, $name), $params);
}
}

View File

@ -31,7 +31,7 @@
* @link http://techfuze.net/fuzeworks
* @since Version 1.2.0
*
* @version Version 1.2.0
* @version Version 1.3.0
*/
use FuzeWorks\Logger;
@ -41,17 +41,11 @@ chdir(dirname(__DIR__));
// Load the FuzeWorks container
$container = require('bootstrap.php');
Logger::disableHandlers();
// Load the test abstract
require_once 'layout/LayoutTestAbstract.php';
// Reset error and exception handlers
restore_error_handler();
restore_exception_handler();
// Set logger template for output in CLI
Logger::setLoggerTemplate('logger_cli');
// Display all errors
ini_set('display_errors', 1);
error_reporting(E_ALL | E_STRICT);
@ -59,4 +53,10 @@ error_reporting(E_ALL | E_STRICT);
// Set localhost "remote" IP
isset($_SERVER['REMOTE_ADDR']) OR $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
// Alias vfsStream
class_alias('org\bovigo\vfs\vfsStream', 'vfsStream');
class_alias('org\bovigo\vfs\vfsStreamDirectory', 'vfsStreamDirectory');
class_alias('org\bovigo\vfs\vfsStreamWrapper', 'vfsStreamWrapper');
// Set logger template for output in CLI
Logger::setLoggerTemplate('logger_cli');

View File

@ -31,7 +31,7 @@
* @link http://techfuze.net/fuzeworks
* @since Version 1.2.0
*
* @version Version 1.2.0
* @version Version 1.3.0
*/
require_once(dirname(__DIR__) . '/vendor/autoload.php');
@ -44,14 +44,14 @@ $configurator->setLogDirectory(dirname(__FILE__) . '/temp');
// Other values
$configurator->setTimeZone('Europe/Amsterdam');
$configurator->enableDebugMode(true);
// Debug related
$configurator->enableDebugMode();
$configurator->setDebugAddress('ALL');
// Implement the Layout Component
$configurator->addComponent(new \FuzeWorks\LayoutComponent());
// Create container
$container = $configurator->createContainer();
// And return the result
return $container;
return $configurator->createContainer();

View File

@ -31,9 +31,10 @@
* @link http://techfuze.net/fuzeworks
* @since Version 1.2.0
*
* @version Version 1.2.0
* @version Version 1.3.0
*/
use FuzeWorks\Exception\LayoutException;
use FuzeWorks\Factory;
use FuzeWorks\Layout;
use FuzeWorks\Events;
@ -57,11 +58,11 @@ class LayoutTest extends LayoutTestAbstract
*/
protected $layout;
public function setUp()
public function setUp(): void
{
// Load the factory first
$this->factory = Factory::getInstance();
$this->layout = Factory::getInstance()->layouts;
$this->layout = Factory::getInstance('layouts');
$this->layout->reset();
}
@ -80,13 +81,13 @@ class LayoutTest extends LayoutTestAbstract
$configurator->setTempDirectory(dirname(__DIR__) . '/temp');
$configurator->setLogDirectory(dirname(__DIR__) . '/temp');
// Create container
$container = $configurator->createContainer();
// Init container;
$this->assertTrue(property_exists($container, 'layouts'));
$this->assertInstanceOf('FuzeWorks\Layout', $container->layouts);
$this->assertInstanceOf('FuzeWorks\Layout', Factory::getInstance('layouts'));
}
/**
@ -147,12 +148,13 @@ class LayoutTest extends LayoutTestAbstract
/**
* @depends testGetFilePath
* @expectedException FuzeWorks\Exception\LayoutException
* @covers \FuzeWorks\Layout::setFileFromString
* @covers \FuzeWorks\Layout::getFileFromString
*/
public function testMalformedPaths()
{
$this->expectException(LayoutException::class);
// Extensions to be used in this test
$extensions = array('php', 'json');
@ -160,33 +162,35 @@ class LayoutTest extends LayoutTestAbstract
}
/**
* @expectedException FuzeWorks\Exception\LayoutException
* @covers \FuzeWorks\Layout::setFileFromString
* @covers \FuzeWorks\Layout::getFileFromString
*/
public function testMissingDirectory()
{
$this->expectException(LayoutException::class);
// Directory that does not exist
$this->layout->setFileFromString('test', [3=>['test'.DS.'templates'.DS.'doesNotExist']], array('php'));
}
/**
* @expectedException FuzeWorks\Exception\LayoutException
* @covers \FuzeWorks\Layout::setFileFromString
* @covers \FuzeWorks\Layout::getFileFromString
*/
public function testMissingFile()
{
$this->expectException(LayoutException::class);
$this->layout->setFileFromString('test', [3=>['test'.DS.'templates'.DS.'testMissingFile']], array('php'));
}
/**
* @expectedException FuzeWorks\Exception\LayoutException
* @covers \FuzeWorks\Layout::setFileFromString
* @covers \FuzeWorks\Layout::getFileFromString
*/
public function testUnknownFileExtension()
{
$this->expectException(LayoutException::class);
$this->layout->setFileFromString('test', [3=>['test'.DS.'templates'.DS.'testUnknownFileExtension']], array('php'));
}
@ -225,12 +229,13 @@ class LayoutTest extends LayoutTestAbstract
}
/**
* @expectedException FuzeWorks\Exception\LayoutException
* @covers \FuzeWorks\Layout::get
* @covers \FuzeWorks\Event\LayoutLoadEvent::init
*/
public function testLayoutGetEventWrongFile()
{
$this->expectException(LayoutException::class);
$directories = ['test'.DS.'templates'.DS.'testLayoutGetEventWrongFile'];
Events::addListener(function($event){
$event->file = 'does_not_exist';
@ -289,16 +294,16 @@ class LayoutTest extends LayoutTestAbstract
// Test all the default engines
$this->assertInstanceOf('FuzeWorks\TemplateEngine\PHPEngine', $this->layout->getEngineFromExtension('php'));
$this->assertInstanceOf('FuzeWorks\TemplateEngine\JsonEngine', $this->layout->getEngineFromExtension('json'));
$this->assertInstanceOf('FuzeWorks\TemplateEngine\SmartyEngine', $this->layout->getEngineFromExtension('tpl'));
$this->assertInstanceOf('FuzeWorks\TemplateEngine\LatteEngine', $this->layout->getEngineFromExtension('latte'));
}
/**
* @depends testGetEngineFromExtension
* @expectedException FuzeWorks\Exception\LayoutException
* @covers \FuzeWorks\Layout::getEngineFromExtension
*/
public function testGetEngineFromExtensionFail()
{
$this->expectException(LayoutException::class);
$this->layout->getEngineFromExtension('faulty');
}
@ -320,10 +325,11 @@ class LayoutTest extends LayoutTestAbstract
/**
* @covers \FuzeWorks\Layout::loadTemplateEngines
* @expectedException \FuzeWorks\Exception\LayoutException
*/
public function testLoadLoadEngineEvent()
{
$this->expectException(LayoutException::class);
Events::addListener(function($event){
$this->assertInstanceOf('\FuzeWorks\Event\NotifierEvent', $event);
throw new \FuzeWorks\Exception\EventException('Forcing failure in loadTemplateEngines()');
@ -357,11 +363,12 @@ class LayoutTest extends LayoutTestAbstract
/**
* @depends testCustomEngine
* @expectedException \FuzeWorks\Exception\LayoutException
* @covers \FuzeWorks\Layout::registerEngine
*/
public function testExistingCustomEngine()
{
$this->expectException(LayoutException::class);
// Create mock
$mock = $this->getMockBuilder('FuzeWorks\TemplateEngine\TemplateEngine')->getMock();
$mock->method('get')->willReturn('output');
@ -375,11 +382,12 @@ class LayoutTest extends LayoutTestAbstract
/**
* @depends testCustomEngine
* @expectedException \FuzeWorks\Exception\LayoutException
* @covers \FuzeWorks\Layout::registerEngine
*/
public function testCustomEngineWithExistingExtensions()
{
$this->expectException(LayoutException::class);
// Create mock
$mock = $this->getMockBuilder('FuzeWorks\TemplateEngine\TemplateEngine')->getMock();
$mock->method('get')->willReturn('output');
@ -419,21 +427,21 @@ class LayoutTest extends LayoutTestAbstract
/**
* @depends testSetEngine
* @expectedException \FuzeWorks\Exception\LayoutException
* @covers \FuzeWorks\Layout::setEngine
*/
public function testSetInvalidEngine()
{
$this->expectException(LayoutException::class);
$this->layout->setEngine('invalid');
}
/**
* @depends testSetEngine
* @expectedException \FuzeWorks\Exception\LayoutException
* @covers \FuzeWorks\Layout::getEngine
*/
public function testGetInvalidEngine()
{
$this->expectException(LayoutException::class);
$this->layout->getEngine('invalid');
}
@ -453,8 +461,8 @@ class LayoutTest extends LayoutTestAbstract
$this->assertEquals('JSON Template Check', json_decode($this->layout->get('json', $directories), true)[0]);
$this->layout->reset();
// And the Smarty Engine
$this->assertEquals('Smarty Template Check', $this->layout->get('smarty', $directories));
// And the Latte Engine
$this->assertEquals("Latte Template Check", $this->layout->get('latte', $directories));
}
/**
@ -475,10 +483,11 @@ class LayoutTest extends LayoutTestAbstract
$this->assertEquals('value', json_decode($this->layout->get('json', $directories), true)['data']['key']);
$this->layout->reset();
// And the Smarty Engine
// And the Latte Engine
$this->layout->assign('key', 'value');
$this->assertEquals('value', $this->layout->get('smarty', $directories));
$this->assertEquals('value', $this->layout->get('latte', $directories));
}
}
class MockEngine {

View File

@ -31,9 +31,10 @@
* @link http://techfuze.net/fuzeworks
* @since Version 1.2.0
*
* @version Version 1.2.0
* @version Version 1.3.0
*/
use FuzeWorks\Config;
use PHPUnit\Framework\TestCase;
use FuzeWorks\Events;
use FuzeWorks\Factory;
@ -51,15 +52,21 @@ abstract class LayoutTestAbstract extends TestCase
*
* Reset the layout manager
*/
public function tearDown()
public function tearDown(): void
{
// Clear all events created by tests
Events::$listeners = array();
// Reset all config files
Factory::getInstance()->config->discardConfigFiles();
Factory::getInstance('config')->discardConfigFiles();
// Re-enable events, in case they have been disabled
Events::enable();
// Remove COnfig overrides
Config::$configOverrides = [];
// Remove autoloader
Core::clearAutoloader();
}
}

View File

@ -1,34 +1,17 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
bootstrap="autoload.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
colors="false">
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="autoload.php" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" colors="false">
<coverage processUncoveredFiles="false">
<include>
<directory suffix=".php">../</directory>
</include>
<exclude>
<directory suffix=".php">../vendor/</directory>
<directory suffix=".php">../test/</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="Core Functionality">
<testsuite name="Layout Suite">
<directory>./</directory>
</testsuite>
</testsuites>
<logging>
<log type="json" target="../build/phpunit/logfile.json"/>
<log type="junit" target="../build/phpunit/logfile.xml"/>
<log type="testdox-html" target="../build/phpunit/testdox.html"/>
<log type="testdox-text" target="../build/phpunit/testdox.txt"/>
</logging>
<filter>
<whitelist processUncoveredFilesFromWhitelist="false">
<directory suffix=".php">../</directory>
<exclude>
<directory suffix=".php">../vendor/</directory>
<directory suffix=".php">../test/</directory>
</exclude>
</whitelist>
</filter>
</phpunit>

View File

@ -0,0 +1 @@
Latte Template Check

View File

@ -1 +0,0 @@
Smarty Template Check