From 7f3341bdc27b53b9c09cdde38046e858037495c5 Mon Sep 17 00:00:00 2001 From: Abel Hoogeveen Date: Mon, 29 Nov 2021 21:54:10 +0100 Subject: [PATCH] PHP 8.0 compatibility update. - Removed Smarty support - PHPUnit 9 support - Auto testing with drone. --- .drone.yml | 30 +++ .gitignore | 3 +- .gitlab-ci.yml | 82 --------- .travis.yml | 12 -- README.md | 2 +- composer.json | 21 +-- src/FuzeWorks/Layout.php | 9 +- src/FuzeWorks/TemplateEngine/SmartyEngine.php | 172 ------------------ test/autoload.php | 16 +- test/bootstrap.php | 12 +- test/layout/LayoutTest.php | 49 +++-- test/layout/LayoutTestAbstract.php | 13 +- test/phpunit.xml | 41 ++--- .../{layout.smarty.tpl => layout.latte.latte} | 0 test/templates/testEngines/layout.latte.latte | 1 + test/templates/testEngines/layout.smarty.tpl | 1 - 16 files changed, 108 insertions(+), 356 deletions(-) create mode 100644 .drone.yml delete mode 100644 .gitlab-ci.yml delete mode 100644 .travis.yml delete mode 100644 src/FuzeWorks/TemplateEngine/SmartyEngine.php rename test/templates/testEngineVariables/{layout.smarty.tpl => layout.latte.latte} (100%) create mode 100644 test/templates/testEngines/layout.latte.latte delete mode 100644 test/templates/testEngines/layout.smarty.tpl diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..ec6e2a6 --- /dev/null +++ b/.drone.yml @@ -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 \ No newline at end of file diff --git a/.gitignore b/.gitignore index c6f4d6e..fbb1132 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ composer.phar .idea/ build/ test/temp/ -vendor/ \ No newline at end of file +vendor/ +*.cache diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 59f3e14..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -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/ \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 2dd0882..0000000 --- a/.travis.yml +++ /dev/null @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index 0629396..0a5cec7 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ FuzeWorks::Layout Component - Readme =================== -Version 1.2.0 +Version 1.3.0 A versatile PHP Framework built to perform. diff --git a/composer.json b/composer.json index ee7e8cf..7cfad24 100644 --- a/composer.json +++ b/composer.json @@ -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/" } } - } \ No newline at end of file diff --git a/src/FuzeWorks/Layout.php b/src/FuzeWorks/Layout.php index 7f52e0e..4b6039e 100644 --- a/src/FuzeWorks/Layout.php +++ b/src/FuzeWorks/Layout.php @@ -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; } diff --git a/src/FuzeWorks/TemplateEngine/SmartyEngine.php b/src/FuzeWorks/TemplateEngine/SmartyEngine.php deleted file mode 100644 index 5165ece..0000000 --- a/src/FuzeWorks/TemplateEngine/SmartyEngine.php +++ /dev/null @@ -1,172 +0,0 @@ - - * @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); - } -} \ No newline at end of file diff --git a/test/autoload.php b/test/autoload.php index 97e355a..336ca1a 100644 --- a/test/autoload.php +++ b/test/autoload.php @@ -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'); \ No newline at end of file diff --git a/test/bootstrap.php b/test/bootstrap.php index 74daf76..bed7293 100644 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -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(); diff --git a/test/layout/LayoutTest.php b/test/layout/LayoutTest.php index eeb524c..5fbae11 100644 --- a/test/layout/LayoutTest.php +++ b/test/layout/LayoutTest.php @@ -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 { diff --git a/test/layout/LayoutTestAbstract.php b/test/layout/LayoutTestAbstract.php index 794d186..4247485 100644 --- a/test/layout/LayoutTestAbstract.php +++ b/test/layout/LayoutTestAbstract.php @@ -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(); } } diff --git a/test/phpunit.xml b/test/phpunit.xml index 7708a45..2e980a0 100644 --- a/test/phpunit.xml +++ b/test/phpunit.xml @@ -1,34 +1,17 @@ - - + + + + + ../ + + + ../vendor/ + ../test/ + + - + ./ - - - - - - - - - - - ../ - - ../vendor/ - ../test/ - - - \ No newline at end of file diff --git a/test/templates/testEngineVariables/layout.smarty.tpl b/test/templates/testEngineVariables/layout.latte.latte similarity index 100% rename from test/templates/testEngineVariables/layout.smarty.tpl rename to test/templates/testEngineVariables/layout.latte.latte diff --git a/test/templates/testEngines/layout.latte.latte b/test/templates/testEngines/layout.latte.latte new file mode 100644 index 0000000..fcc90b5 --- /dev/null +++ b/test/templates/testEngines/layout.latte.latte @@ -0,0 +1 @@ +Latte Template Check \ No newline at end of file diff --git a/test/templates/testEngines/layout.smarty.tpl b/test/templates/testEngines/layout.smarty.tpl deleted file mode 100644 index 6a4f97f..0000000 --- a/test/templates/testEngines/layout.smarty.tpl +++ /dev/null @@ -1 +0,0 @@ -Smarty Template Check \ No newline at end of file