Merge branch 'holiday-branch' into 'development'

1.2.0 RC4

See merge request fuzeworks/core!68
This commit is contained in:
Abel Hoogeveen 2019-08-21 15:54:01 +00:00
commit be915fa98a
36 changed files with 695 additions and 170 deletions

View File

@ -36,6 +36,7 @@
namespace FuzeWorks;
use FuzeWorks\Exception\CoreException;
use FuzeWorks\Exception\EventException;
/**
@ -43,6 +44,7 @@ use FuzeWorks\Exception\EventException;
*
* Holds all the modules and starts the framework. Allows for starting and managing modules
*
* @todo Implement unit tests for autoloader() methods
* @author TechFuze <contact@techfuze.net>
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
*/
@ -53,7 +55,7 @@ class Core
*
* @var string Framework version
*/
public static $version = '1.0.0';
public static $version = '1.2.0';
/**
* Working directory of the Framework.
@ -84,6 +86,13 @@ class Core
*/
protected static $errorHandlers = [];
/**
* Array of all classMaps which can be autoloaded.
*
* @var array
*/
protected static $autoloadMap = [];
/**
* Initializes the core.
*
@ -108,6 +117,7 @@ class Core
register_shutdown_function(array('\FuzeWorks\Core', 'shutdown'));
set_error_handler(array('\FuzeWorks\Core', 'errorHandler'), E_ALL);
set_exception_handler(array('\FuzeWorks\Core', 'exceptionHandler'));
spl_autoload_register(['\FuzeWorks\Core', 'autoloader'], true,false);
// Return the Factory
return new Factory();
@ -157,11 +167,6 @@ class Core
return $_is_php[$version];
}
public static function isCli(): bool
{
return (PHP_SAPI === 'cli' OR defined('STDIN'));
}
public static function exceptionHandler()
{
for ($i = Priority::getHighestPriority(); $i <= Priority::getLowestPriority(); $i++)
@ -186,7 +191,6 @@ class Core
}
}
/**
* Add an exception handler to be called when an exception occurs
*
@ -249,6 +253,56 @@ class Core
}
}
/**
* @param string $nameSpacePrefix
* @param string $filePath
* @throws CoreException
*/
public static function addAutoloadMap(string $nameSpacePrefix, string $filePath)
{
// Remove leading slashes
$nameSpacePrefix = ltrim($nameSpacePrefix, '\\');
if (isset(self::$autoloadMap[$nameSpacePrefix]))
throw new CoreException("Could not add classes to autoloader. ClassMap already exists.");
if (!file_exists($filePath) && !is_dir($filePath))
throw new CoreException("Could not add classes to autoloader. Provided filePath does not exist.");
self::$autoloadMap[$nameSpacePrefix] = $filePath;
}
public static function autoloader(string $class)
{
// Remove leading slashes
$class = ltrim($class, '\\');
// First attempt and find if the prefix of the class is in the autoloadMap
foreach (self::$autoloadMap as $prefix => $path)
{
// If not, try next
if (strpos($class, $prefix) === false)
continue;
// If it contains the prefix, attempt to find the file
$className = substr($class, strlen($prefix) + 1);
$filePath = $path . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $className) . '.php';
if (file_exists($filePath) && is_file($filePath))
require($filePath);
}
}
/**
* Clears the autoloader to its original state.
*
* Not intended for use by developer. Only for use during testing
* @internal
*/
public static function clearAutoloader()
{
self::$autoloadMap = [];
}
/**
* Tests for file writability
*

View File

@ -71,13 +71,6 @@ class Factory
*/
private static $sharedFactoryInstance;
/**
* Whether to clone all Factory instances upon calling Factory::getInstance()
*
* @var bool Clone all Factory instances.
*/
private static $cloneInstances = false;
/**
* Whether the Factory has been initialized or not
*
@ -124,6 +117,7 @@ class Factory
/**
* Factory instance constructor. Should only really be called once
* @throws ConfigException
* @throws FactoryException
*/
public function __construct()
{
@ -174,9 +168,7 @@ class Factory
// Disable events if requested to do so
if (!$cfg->get('enable_events'))
{
Events::disable();
}
// Initialize all components
foreach ($this as $component)
@ -201,40 +193,25 @@ class Factory
return $this;
}
/**
* Get a new instance of the Factory class.
*
* @param bool $cloneInstance Whether to get a cloned instance (true) or exactly the same instance (false)
* @return Factory Instance
*/
public static function getInstance($cloneInstance = false): Factory
{
if ($cloneInstance === true || self::$cloneInstances === true)
{
return clone self::$sharedFactoryInstance;
}
/**
* Get an instance of a componentClass.
*
* @param string|null $instanceName
* @return mixed
* @throws FactoryException
*/
public static function getInstance(string $instanceName = null)
{
if (is_null($instanceName))
return self::$sharedFactoryInstance;
return self::$sharedFactoryInstance;
}
// Determine the instance name
$instanceName = strtolower($instanceName);
/**
* Enable cloning all Factory instances upon calling Factory::getInstance()
*
* @return void
*/
public static function enableCloneInstances()
{
self::$cloneInstances = true;
}
if (!isset(self::$sharedFactoryInstance->{$instanceName}))
throw new FactoryException("Could not get instance. Instance was not found.");
/**
* Disable cloning all Factory instances upon calling Factory::getInstance()
*
* @return void
*/
public static function disableCloneInstances()
{
self::$cloneInstances = false;
return self::$sharedFactoryInstance->{$instanceName};
}
/**
@ -275,25 +252,29 @@ class Factory
* Clone an instance of one of the loaded classes.
* It clones the class. It does NOT re-create it.
*
* If the $onlyReturn = true is provided, the cloned instance will only be returned, and not set to the factory.
*
* @param string $className The name of the loaded class, WITHOUT the namespace
* @return Factory Instance
* @param bool $onlyReturn
* @return mixed
* @throws FactoryException
*/
public function cloneInstance($className): self
public static function cloneInstance(string $className, bool $onlyReturn = false)
{
// Determine the class to load
$instanceName = strtolower($className);
if (!isset($this->{$instanceName}))
{
if (!isset(self::$sharedFactoryInstance->{$instanceName}))
throw new FactoryException("Could not clone instance of '".$instanceName."'. Instance was not found.", 1);
}
if ($onlyReturn)
return clone self::$sharedFactoryInstance->{$instanceName};
// Clone the instance
$this->{$instanceName} = clone $this->{$instanceName};
self::$sharedFactoryInstance->{$instanceName} = clone self::$sharedFactoryInstance->{$instanceName};
// Return itself
return $this;
return self::$sharedFactoryInstance->{$instanceName};
}
/**

View File

@ -37,7 +37,10 @@
namespace FuzeWorks;
use FuzeWorks\Exception\ConfigException;
use FuzeWorks\Exception\CoreException;
use FuzeWorks\Exception\LibraryException;
use ReflectionClass;
use ReflectionException;
class Libraries
{
@ -181,10 +184,8 @@ class Libraries
protected function initLibrary(string $libraryName, string $libraryClass, array $parameters = [])
{
// First check to see if the library is already loaded
if (!class_exists($libraryClass, false))
{
if (!class_exists($libraryClass, true))
throw new LibraryException("Could not initiate library. Class not found", 1);
}
// Determine what parameters to use
if (empty($parameters))
@ -198,9 +199,27 @@ class Libraries
}
// Load the class object
/** @var iLibrary $classObject */
$classObject = new $libraryClass($parameters);
// Check if the address is already reserved, if it is, we can presume that a new instance is requested.
// If not instance of iLibrary, refuse the library
if (!$classObject instanceof iLibrary)
throw new LibraryException("Could not initiate library. Library is not instance of iLibrary.");
// Add the library files to the autoloader
try {
$headerReflection = new ReflectionClass(get_class($classObject));
$filePath = dirname($headerReflection->getFileName()) . (!is_null($classObject->getSourceDirectory()) ? DS . $classObject->getSourceDirectory() : '' );
$prefix = $classObject->getClassesPrefix();
if (!is_null($filePath) && !is_null($prefix))
Core::addAutoloadMap($prefix, $filePath);
} catch (ReflectionException $e) {
throw new LibraryException("Could not initiate library. ReflectionClass threw exception.");
} catch (CoreException $e) {
throw new LibraryException("Could not initiate library. Failed to add to autoloader.");
}
// @todo Check if the address is already reserved, if it is, we can presume that a new instance is requested.
// Otherwise this code would not be reached
// Now load the class

View File

@ -223,9 +223,7 @@ class Logger {
}
if (self::$log_last_request == true)
{
self::logLastRequest();
}
if (self::$log_errors_to_file == true)
self::logErrorsToFile();
@ -342,9 +340,8 @@ class Logger {
require(dirname(__DIR__) . DS . 'Layout' . DS . 'layout.logger_file.php');
$contents = ob_get_clean();
$file = Core::$logDir . DS . 'fwlog_request.log';
if (is_writable(dirname($file))) {
if (is_writable(dirname($file)))
file_put_contents($file, $contents);
}
}
/**
@ -357,14 +354,14 @@ class Logger {
$logs = [];
foreach (self::$logs as $log)
{
if ($log['type'] === 'ERROR')
if ($log['type'] === 'ERROR' || $log['type'] === 'EXCEPTION')
$logs[] = $log;
}
require(dirname(__DIR__) . DS . 'Layout' . DS . 'layout.logger_file.php');
$contents = ob_get_clean();
$file = Core::$logDir . DS . 'fwlog_errors.log';
if (is_writable(dirname($file)))
file_put_contents($file, $contents, FILE_APPEND | LOCK_EX);
file_put_contents($file, $contents, FILE_APPEND);
}
/* =========================================LOGGING METHODS============================================================== */

View File

@ -37,7 +37,8 @@
namespace FuzeWorks;
use FuzeWorks\ConfigORM\ConfigORM;
use FuzeWorks\Event\PluginGetEvent;
use FuzeWorks\Exception\ConfigException;
use FuzeWorks\Exception\CoreException;
use FuzeWorks\Exception\FactoryException;
use FuzeWorks\Exception\PluginException;
use ReflectionClass;
use ReflectionException;
@ -89,12 +90,12 @@ class Plugins
protected $cfg;
/**
* Called upon creation of the plugins class.
* Called upon initialization of the Container
*
* @throws ConfigException
* @throws FactoryException
* @codeCoverageIgnore
*/
public function __construct()
public function init()
{
$this->cfg = Factory::getInstance()->config->getConfig('plugins');
}
@ -210,10 +211,8 @@ class Plugins
*/
public function get($pluginName, array $parameters = null)
{
if (empty($pluginName))
{
if (empty($pluginName))
throw new PluginException("Could not load plugin. No name provided", 1);
}
// Determine the name of the plugin
$pluginName = ucfirst($pluginName);
@ -222,38 +221,44 @@ class Plugins
/** @var PluginGetEvent $event */
$event = Events::fireEvent('pluginGetEvent', $pluginName);
if ($event->isCancelled())
{
return false;
}
elseif ($event->getPlugin() != null)
{
return $event->getPlugin();
}
// Otherwise just set the variables
$pluginName = $event->pluginName;
// Check if the plugin is already loaded and return directly
if (isset($this->plugins[$pluginName]))
{
return $this->plugins[$pluginName];
}
// Check if the plugin header exists
if (!isset($this->headers[$pluginName]))
{
throw new PluginException("Could not load plugin. Plugin header does not exist", 1);
}
// If disabled, don't bother
if (in_array($pluginName, $this->cfg->get('disabled_plugins')))
{
throw new PluginException("Could not load plugin. Plugin is disabled", 1);
}
// Determine what file to load
/** @var iPluginHeader $header */
$header = $this->headers[$pluginName];
// Add to autoloader
$headerReflection = new ReflectionClass( get_class($header) );
$prefix = $header->getClassesPrefix();
$filePath = dirname($headerReflection->getFileName()) . (!empty($header->getSourceDirectory()) ? DS . $header->getSourceDirectory() : '');
$pluginClass = $header->getPluginClass();
if (!is_null($prefix) && !is_null($filePath))
{
try {
Core::addAutoloadMap($prefix, $filePath);
} catch (CoreException $e) {
throw new PluginException("Could not load plugin. Autoloader invalid: '".$e->getMessage()."'");
}
}
// If a 'getPlugin' method is found in the header, call that instead
if (method_exists($header, 'getPlugin'))
{
@ -262,26 +267,11 @@ class Plugins
return $this->plugins[$pluginName];
}
// Determine class name and file
// @todo Find a more reliable method for determining header directory
$headerReflection = new ReflectionClass( get_class($header) );
$directory = dirname($headerReflection->getFileName());
$classFile = (isset($header->classFile) ? $directory.DS.$header->classFile : $directory.DS.'plugin.'.strtolower($pluginName).".php");
$className = (isset($header->className) ? $header->className : '\Application\Plugin\\'.$pluginName);
// Try to access the file
if (!file_exists($classFile))
{
throw new PluginException("Could not load plugin. Class file does not exist", 1);
}
// Attempt to load the plugin
require_once($classFile);
if (!class_exists($className, false))
{
if (!class_exists($pluginClass, true))
throw new PluginException("Could not load plugin. Class does not exist", 1);
}
$this->plugins[$pluginName] = new $className($parameters);
$this->plugins[$pluginName] = new $pluginClass($parameters);
Logger::log('Loaded Plugin: \'' . $pluginName . '\'');
// And return it

View File

@ -0,0 +1,64 @@
<?php
/**
* FuzeWorks Framework Core.
*
* The FuzeWorks PHP FrameWork
*
* Copyright (C) 2013-2019 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 - 2019, 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;
interface iLibrary
{
/**
* Should return the namespace prefix of the classes of this library.
*
* Used to autoload classes of this library.
* @see https://www.php-fig.org/psr/psr-4/
*
* Invoked upon `FuzeWorks\Libraries:get`. Autoloading library classes before that is not possible.
*
* @return string|null
*/
public function getClassesPrefix(): ?string;
/**
* Should return the directory where the classes of this library can be found.
*
* Only the source directory within the library should be returned, e.g:
* If the source directory is 'src' within the library directory, return 'src'
*
* @return string|null
*/
public function getSourceDirectory(): ?string;
}

View File

@ -39,6 +39,50 @@ namespace FuzeWorks;
interface iPluginHeader
{
/**
* Should return the name of the plugin.
*
* This is the name used to access the plugin when using Plugins::get()
* @return string
*/
public function getName(): string;
/**
* Should return the namespace prefix of the classes of this plugin.
*
* Used to autoload classes of this plugin.
* @see https://www.php-fig.org/psr/psr-4/
*
* Invoked upon `FuzeWorks\Plugins::get`. Autoloading plugin classes before that is not possible.
*
* @return string|null
*/
public function getClassesPrefix(): ?string;
/**
* Should return the directory where the classes of this plugin can be found.
*
* Only the source directory within the plugin should be returned, e.g:
* If the source directory is 'src' within the plugin directory, return 'src'
*
* @return string|null
*/
public function getSourceDirectory(): ?string;
/**
* Should return the className of the main class of this plugin
*
* Should only return null if the pluginHeader has the optional getPlugin() method.
*
* @return string|null
*/
public function getPluginClass(): ?string;
/**
* Initializes the pluginHeader. This method allows the developer to hook into multiple systems of FuzeWorks
* upon FuzeWorks initialization. See the FuzeWorks boot process for more information.
*
* @return mixed
*/
public function init();
}

View File

@ -34,19 +34,16 @@
* @version Version 1.2.0
*/
$mask = "|%5s |%-95s |\n";
$mask = "|%5s |%5s |%-90s |\n";
$id = 1;
if (!empty($logs))
printf($mask, $id, ' REQUEST ' . date('Y-m-d H:i') . '-'.substr(sha1(uniqid()), 0, 8).'');
printf($mask, $id, 'REQUEST', ' ' . date('Y-m-d H:i') . '-'.substr(sha1(uniqid()), 0, 8).'');
foreach ($logs as $log) {
$id++;
$string = '';
$string .= '[ERROR]' . ' - ';
$string .= $log['message'];
printf($mask, $id, $log['type'], $log['message']);
}
if (!empty($logs))
printf($mask, $id, '');
printf($mask, $id, 'HALT', '---------------------');

View File

@ -48,22 +48,23 @@ use FuzeWorks\LoggerTracyBridge;
abstract class CoreTestAbstract extends TestCase
{
/**
* Remove all listeners before the next test starts.
*
* Reset the layout manager
* Reset multiple components to their original state before running the next test
*/
public function tearDown()
{
// Clear all events created by tests
Events::$listeners = array();
Events::$listeners = [];
// 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

@ -64,6 +64,8 @@ class configuratorTest extends CoreTestAbstract
public function tearDown()
{
parent::tearDown();
Core::$tempDir = dirname(__DIR__) . '/temp';
Core::$logDir = dirname(__DIR__) . '/temp';
}

View File

@ -54,6 +54,32 @@ class factoryTest extends CoreTestAbstract
$this->assertInstanceOf('FuzeWorks\Factory', Factory::getInstance());
}
/**
* @covers ::getInstance
*/
public function testGetInstance()
{
// Add the mock
$mock = $this->getMockBuilder(MockFactory::class)->getMock();
Factory::getInstance()->setInstance('Mock', $mock);
// First test a global getInstance Factory
$this->assertInstanceOf('\FuzeWorks\Factory', Factory::getInstance());
// Second, test retrieving a component
$this->assertInstanceOf(get_class($mock), Factory::getInstance('Mock'));
}
/**
* @depends testGetInstance
* @covers ::getInstance
* @expectedException \FuzeWorks\Exception\FactoryException
*/
public function testGetInstanceNotFound()
{
Factory::getInstance('NotFound');
}
/**
* @depends testCanLoadFactory
* @covers ::getInstance
@ -70,11 +96,23 @@ class factoryTest extends CoreTestAbstract
*/
public function testLoadDifferentInstance()
{
// Add the mock
$mock = $this->getMockBuilder(MockFactory::class)->getMock();
Factory::getInstance()->setInstance('Mock', $mock);
// First a situation where one is the shared instance and one is a cloned instance
$this->assertNotSame(Factory::getInstance(), Factory::getInstance(true));
$a = Factory::getInstance('Mock');
$b = Factory::cloneInstance('Mock');
$this->assertInstanceOf(get_class($mock), $a);
$this->assertInstanceOf(get_class($mock), $b);
$this->assertNotSame($a,$b);
// And a situation where both are cloned instances
$this->assertNotSame(Factory::getInstance(true), Factory::getInstance(true));
$a = Factory::cloneInstance('Mock');
$b = Factory::cloneInstance('Mock');
$this->assertInstanceOf(get_class($mock), $a);
$this->assertInstanceOf(get_class($mock), $b);
$this->assertNotSame($a,$b);
}
/**
@ -91,6 +129,8 @@ class factoryTest extends CoreTestAbstract
$this->assertFalse(isset(Factory::getInstance()->mock));
// Same instance factories
/** @var Factory $factory1 */
/** @var Factory $factory2 */
$factory1 = Factory::getInstance()->setInstance('Mock', $mock);
$factory2 = Factory::getInstance()->setInstance('Mock', $mock);
@ -98,8 +138,8 @@ class factoryTest extends CoreTestAbstract
$this->assertSame($factory1->mock, $factory2->mock);
// Different instance factories
$factory3 = Factory::getInstance(true)->setInstance('Mock', $mock);
$factory4 = Factory::getInstance(true)->setInstance('Mock', $mock);
$factory3 = Factory::getInstance()->setInstance('Mock', $mock);
$factory4 = Factory::getInstance()->setInstance('Mock', $mock);
// Return the mocks
$this->assertSame($factory3->mock, $factory4->mock);
@ -121,23 +161,23 @@ class factoryTest extends CoreTestAbstract
$factory2 = Factory::getInstance()->setInstance('Mock', $mock);
// Clone the instance in factory2
$factory2->cloneInstance('Mock');
$factory2mock = $factory2->cloneInstance('Mock');
// Should be true, since both Factories use the same Mock instance
$this->assertSame($factory1->mock, $factory2->mock);
$this->assertSame($factory1->mock, $factory2mock);
// Different instance factories
$factory3 = Factory::getInstance(true)->setInstance('Mock', $mock);
$factory4 = Factory::getInstance(true)->setInstance('Mock', $mock);
$factory3 = Factory::getInstance()->setInstance('Mock', $mock);
$factory4 = Factory::getInstance()->setInstance('Mock', $mock);
// Should be same for now
$this->assertSame($factory3->mock, $factory4->mock);
// Clone the instance in factory4
$factory4->cloneInstance('Mock');
$factory4mock = $factory4->cloneInstance('Mock', true);
// Should be false, since both Factories use a different Mock instance
$this->assertNotSame($factory3->mock, $factory4->mock);
$this->assertNotSame($factory3->mock, $factory4mock);
}
/**
@ -154,31 +194,6 @@ class factoryTest extends CoreTestAbstract
$factory->cloneInstance('fake');
}
/**
* @depends testCanLoadFactory
* @covers ::enableCloneInstances
* @covers ::disableCloneInstances
* @covers ::cloneInstance
* @covers ::getInstance
*/
public function testGlobalCloneInstance()
{
// First test without global cloning
$this->assertSame(Factory::getInstance(), Factory::getInstance());
// Now enable global cloning
Factory::enableCloneInstances();
// Now test without global cloning
$this->assertNotSame(Factory::getInstance(), Factory::getInstance());
// Disable global cloning
Factory::disableCloneInstances();
// And test again without global cloning
$this->assertSame(Factory::getInstance(), Factory::getInstance());
}
/**
* @depends testCanLoadFactory
* @covers ::getInstance
@ -295,13 +310,11 @@ class factoryTest extends CoreTestAbstract
public function tearDown()
{
Factory::disableCloneInstances();
parent::tearDown();
$factory = Factory::getInstance();
if (isset($factory->Mock))
{
$factory->removeInstance('Mock');
}
if (isset($factory->mock))
$factory->removeInstance('mock');
}
}

View File

@ -195,8 +195,36 @@ class libraryTest extends CoreTestAbstract
$this->libraries->addLibraryClass('LibraryClassFail', '\Case\Not\Exist');
}
/**
* @depends testAddLibraryClass
* @covers ::initLibrary
*/
public function testAddLibraryWithAutoloader()
{
// First assert the extra class can't be autoloaded
$this->assertFalse(class_exists('FuzeWorks\Test\TestAddLibraryWithAutoloader\SomeExtraClass', true));
// Load the library and test the instance type
$this->assertInstanceOf('Application\Library\TestAddLibraryWithAutoloader', $this->libraries->get('TestAddLibraryWithAutoloader'));
// Afterwards test if the loader has been correctly added
$this->assertTrue(class_exists('FuzeWorks\Test\TestAddLibraryWithAutoloader\SomeExtraClass', true));
}
/**
* @depends testAddLibraryWithAutoloader
* @covers ::initLibrary
* @expectedException \FuzeWorks\Exception\LibraryException
*/
public function testAddBadAutoloader()
{
$this->assertInstanceOf('Application\Library\TestAddBadAutoloader', $this->libraries->get('TestAddBadAutoloader'));
}
public function tearDown()
{
parent::tearDown();
Factory::getInstance()->config->getConfig('error')->revert();
}

View File

@ -213,6 +213,8 @@ class loggerTest extends CoreTestAbstract
public function tearDown()
{
parent::tearDown();
Logger::disable();
Logger::$logs = array();
}

View File

@ -55,6 +55,7 @@ class pluginTest extends CoreTestAbstract
public function setUp()
{
$this->plugins = new Plugins();
$this->plugins->init();
$this->plugins->addComponentPath('test'.DS.'plugins');
$this->plugins->loadHeadersFromPluginPaths();
}
@ -73,7 +74,7 @@ class pluginTest extends CoreTestAbstract
*/
public function testLoadPlugin()
{
$this->assertInstanceOf('\Application\Plugin\TestLoadPlugin', $this->plugins->get('testLoadPlugin'));
$this->assertInstanceOf('\FuzeWorks\UnitTest\Plugins\TestLoadPlugin\TestLoadPlugin', $this->plugins->get('testLoadPlugin'));
}
/**
@ -99,7 +100,7 @@ class pluginTest extends CoreTestAbstract
$this->plugins->addPlugin($header);
// Assert the plugin
$this->assertInstanceOf('Application\Plugin\Plug', $this->plugins->get('Plug'));
$this->assertInstanceOf('\FuzeWorks\UnitTest\Plugins\TestLoadHeader\Plug', $this->plugins->get('Plug'));
}
/**
@ -125,9 +126,9 @@ class pluginTest extends CoreTestAbstract
* @depends testLoadPlugin
* @covers ::get
*/
public function testGetPluginWithClassFile()
public function testGetPluginWithClassMap()
{
$this->assertInstanceOf('OtherPlug', $this->plugins->get('TestGetPluginWithClassFile'));
$this->assertInstanceOf('FuzeWorks\UnitTest\Plugins\TestGetPluginWithClassMap\OtherPlug', $this->plugins->get('TestGetPluginWithClassMap'));
}
/**
@ -197,6 +198,8 @@ class pluginTest extends CoreTestAbstract
public function tearDown()
{
parent::tearDown();
$factory = Factory::getInstance();
$factory->config->plugins->revert();
}

View File

@ -0,0 +1,52 @@
<?php
/**
* FuzeWorks Framework Core.
*
* The FuzeWorks PHP FrameWork
*
* Copyright (C) 2013-2019 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 - 2019, 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 Application\Library;
use FuzeWorks\iLibrary;
class TestAddBadAutoloader implements iLibrary
{
public function getClassesPrefix(): ?string
{
return "";
}
public function getSourceDirectory(): ?string
{
return "non_existent";
}
}

View File

@ -34,7 +34,16 @@
* @version Version 1.2.0
*/
namespace Custom\Spaces;
use FuzeWorks\iLibrary;
class TestAddLibraryClass {
class TestAddLibraryClass implements iLibrary {
public function getClassesPrefix(): ?string
{
return null;
}
public function getSourceDirectory(): ?string
{
return null;
}
}

View File

@ -0,0 +1,43 @@
<?php
/**
* FuzeWorks Framework Core.
*
* The FuzeWorks PHP FrameWork
*
* Copyright (C) 2013-2019 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 - 2019, 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\Test\TestAddLibraryWithAutoloader;
class SomeExtraClass
{
}

View File

@ -0,0 +1,52 @@
<?php
/**
* FuzeWorks Framework Core.
*
* The FuzeWorks PHP FrameWork
*
* Copyright (C) 2013-2019 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 - 2019, 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 Application\Library;
use FuzeWorks\iLibrary;
class TestAddLibraryWithAutoloader implements iLibrary
{
public function getClassesPrefix(): ?string
{
return "FuzeWorks\Test\TestAddLibraryWithAutoloader";
}
public function getSourceDirectory(): ?string
{
return "";
}
}

View File

@ -34,7 +34,16 @@
* @version Version 1.2.0
*/
namespace Application\Library;
use FuzeWorks\iLibrary;
class TestGetLibraryFromAltDirectory {
class TestGetLibraryFromAltDirectory implements iLibrary {
public function getClassesPrefix(): ?string
{
return null;
}
public function getSourceDirectory(): ?string
{
return null;
}
}

View File

@ -34,7 +34,17 @@
* @version Version 1.2.0
*/
namespace Application\Library;
use FuzeWorks\iLibrary;
class TestGetLibraryFromDirectory {
class TestGetLibraryFromDirectory implements iLibrary {
public function getClassesPrefix(): ?string
{
return null;
}
public function getSourceDirectory(): ?string
{
return null;
}
}

View File

@ -34,7 +34,16 @@
* @version Version 1.2.0
*/
namespace Application\Library;
use FuzeWorks\iLibrary;
class TestGetLibraryFromSubdirectory {
class TestGetLibraryFromSubdirectory implements iLibrary {
public function getClassesPrefix(): ?string
{
return null;
}
public function getSourceDirectory(): ?string
{
return null;
}
}

View File

@ -34,8 +34,9 @@
* @version Version 1.2.0
*/
namespace Application\Library;
use FuzeWorks\iLibrary;
class TestGetLibraryParametersFromConfig {
class TestGetLibraryParametersFromConfig implements iLibrary {
public $parameters;
@ -44,4 +45,14 @@ class TestGetLibraryParametersFromConfig {
$this->parameters = $parameters;
}
public function getClassesPrefix(): ?string
{
return null;
}
public function getSourceDirectory(): ?string
{
return null;
}
}

View File

@ -47,4 +47,19 @@ class TestDisabledPluginHeader implements iPluginHeader
public function init()
{
}
public function getClassesPrefix(): ?string
{
return null;
}
public function getSourceDirectory(): ?string
{
return null;
}
public function getPluginClass(): ?string
{
return null;
}
}

View File

@ -52,4 +52,19 @@ class TestGetPluginMethodHeader implements iPluginHeader
{
return 'test_string';
}
public function getClassesPrefix(): ?string
{
return null;
}
public function getSourceDirectory(): ?string
{
return null;
}
public function getPluginClass(): ?string
{
return null;
}
}

View File

@ -34,6 +34,8 @@
* @version Version 1.2.0
*/
namespace FuzeWorks\UnitTest\Plugins\TestGetPluginWithClassMap;
class OtherPlug
{

View File

@ -36,18 +36,31 @@
namespace Application\Plugin;
use FuzeWorks\iPluginHeader;
class TestGetPluginWithClassFileHeader implements iPluginHeader
class TestGetPluginWithClassMapHeader implements iPluginHeader
{
public $classFile = 'OtherPlugFile.php';
public $className = 'OtherPlug';
public function getName(): string
{
return "TestGetPluginWithClassFile";
return "TestGetPluginWithClassMap";
}
public function getClassesPrefix(): ?string
{
return '\FuzeWorks\UnitTest\Plugins\TestGetPluginWithClassMap';
}
public function getSourceDirectory(): ?string
{
return '';
}
public function getPluginClass(): ?string
{
return '\FuzeWorks\UnitTest\Plugins\TestGetPluginWithClassMap\OtherPlug';
}
public function init()
{
}
}

View File

@ -44,6 +44,21 @@ class TestInvalidClassHeader implements iPluginHeader
return "TestInvalidClass";
}
public function getClassesPrefix(): ?string
{
return '\FuzeWorks\UnitTest\Plugins\TestInvalidClassHeader';
}
public function getSourceDirectory(): ?string
{
return '';
}
public function getPluginClass(): ?string
{
return '\FuzeWorks\UnitTest\Plugins\TestInvalidClassHeader\TestInvalidClass';
}
public function init()
{
}

View File

@ -33,7 +33,7 @@
*
* @version Version 1.2.0
*/
namespace Application\Plugin;
namespace FuzeWorks\UnitTest\Plugins\TestLoadHeader;
class Plug
{

View File

@ -44,6 +44,21 @@ class TestLoadHeaderHeader implements iPluginHeader
return "Plug";
}
public function getClassesPrefix(): ?string
{
return '\FuzeWorks\UnitTest\Plugins\TestLoadHeader';
}
public function getSourceDirectory(): ?string
{
return '';
}
public function getPluginClass(): ?string
{
return '\FuzeWorks\UnitTest\Plugins\TestLoadHeader\Plug';
}
public function init()
{
}

View File

@ -33,7 +33,7 @@
*
* @version Version 1.2.0
*/
namespace Application\Plugin;
namespace FuzeWorks\UnitTest\Plugins\TestLoadHeaderNotIPluginHeader;
class TestLoadPlugin
{

View File

@ -43,6 +43,21 @@ class TestLoadHeaderNotIPluginHeaderHeader
return "TestLoadHeaderNotIPluginHeader";
}
public function getClassesPrefix(): ?string
{
return '\FuzeWorks\UnitTest\Plugins\TestLoadHeaderNotIPluginHeader';
}
public function getSourceDirectory(): ?string
{
return '';
}
public function getPluginClass(): ?string
{
return '\FuzeWorks\UnitTest\Plugins\TestLoadHeaderNotIPluginHeader\TestLoadPlugin';
}
public function init()
{
}

View File

@ -33,7 +33,7 @@
*
* @version Version 1.2.0
*/
namespace Application\Plugin;
namespace FuzeWorks\UnitTest\Plugins\TestLoadPlugin;
class TestLoadPlugin
{

View File

@ -44,6 +44,21 @@ class TestLoadPluginHeader implements iPluginHeader
return "TestLoadPlugin";
}
public function getClassesPrefix(): ?string
{
return '\FuzeWorks\UnitTest\Plugins\TestLoadPlugin';
}
public function getSourceDirectory(): ?string
{
return '';
}
public function getPluginClass(): ?string
{
return '\FuzeWorks\UnitTest\Plugins\TestLoadPlugin\TestLoadPlugin';
}
public function init()
{
}

View File

@ -44,6 +44,21 @@ class TestMissingPluginHeader implements iPluginHeader
return "TestMissingPlugin";
}
public function getClassesPrefix(): ?string
{
return '\FuzeWorks\UnitTest\Plugins\TestMissingPlugin';
}
public function getSourceDirectory(): ?string
{
return '';
}
public function getPluginClass(): ?string
{
return '\FuzeWorks\UnitTest\Plugins\TestMissingPluginHeader\TestMissingPlugin';
}
public function init()
{
}

View File

@ -33,7 +33,7 @@
*
* @version Version 1.2.0
*/
namespace Application\Plugin;
namespace FuzeWorks\UnitTest\Plugins\TestReloadPlugin;
class TestReloadPlugin
{

View File

@ -44,6 +44,21 @@ class TestReloadPluginHeader implements iPluginHeader
return "TestReloadPlugin";
}
public function getClassesPrefix(): ?string
{
return '\FuzeWorks\UnitTest\Plugins\TestReloadPlugin';
}
public function getSourceDirectory(): ?string
{
return '';
}
public function getPluginClass(): ?string
{
return '\FuzeWorks\UnitTest\Plugins\TestReloadPlugin\TestReloadPlugin';
}
public function init()
{
}