Implemented ComponentPathsTrait.
Now every classes that uses paths doesn't have its own code anymore. All methods for handling paths have been standardized.
This commit is contained in:
parent
8fc17c2a91
commit
be449b4f0d
|
@ -0,0 +1,95 @@
|
|||
<?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 1.2.0
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
||||
|
||||
trait ComponentPathsTrait
|
||||
{
|
||||
|
||||
/**
|
||||
* Array of all the paths where objects for this component can be found
|
||||
*
|
||||
* @var array $componentPaths
|
||||
*/
|
||||
protected $componentPaths = array();
|
||||
|
||||
/**
|
||||
* Set the directories. Automatically gets invoked if componentPaths are added by FuzeWorks\Configurator.
|
||||
*
|
||||
* @param array $componentPaths
|
||||
*/
|
||||
public function setDirectories(array $componentPaths)
|
||||
{
|
||||
$this->componentPaths = array_merge($this->componentPaths, $componentPaths);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a path where objects for this component can be found
|
||||
*
|
||||
* @param string $componentPath
|
||||
*/
|
||||
public function addComponentPath($componentPath)
|
||||
{
|
||||
if (!in_array($componentPath, $this->componentPaths))
|
||||
{
|
||||
$this->componentPaths[] = $componentPath;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a path where objects for this component can be found
|
||||
*
|
||||
* @param string $componentPath
|
||||
*/
|
||||
public function removeComponentPath($componentPath)
|
||||
{
|
||||
if (($key = array_search($componentPath, $this->componentPaths)) !== false)
|
||||
{
|
||||
unset($this->componentPaths[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all current componentPaths
|
||||
*
|
||||
* @return array of paths where objects for this component can be found
|
||||
*/
|
||||
public function getComponentPaths(): array
|
||||
{
|
||||
return $this->componentPaths;
|
||||
}
|
||||
}
|
|
@ -50,6 +50,7 @@ use FuzeWorks\Exception\EventException;
|
|||
*/
|
||||
class Config
|
||||
{
|
||||
use ComponentPathsTrait;
|
||||
|
||||
/**
|
||||
* Array where all config files are saved while FuzeWorks runs
|
||||
|
@ -65,18 +66,9 @@ class Config
|
|||
*/
|
||||
public static $configOverrides = [];
|
||||
|
||||
/**
|
||||
* Paths where Helpers can be found.
|
||||
*
|
||||
* Libraries will only be loaded if either a directory is supplied or it is in one of the helperPaths
|
||||
*
|
||||
* @var array Array of paths where helpers can be found
|
||||
*/
|
||||
protected $configPaths = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->configPaths = Core::$appDirs;
|
||||
$this->componentPaths = Core::$appDirs;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -90,7 +82,7 @@ class Config
|
|||
public function getConfig(string $configName, array $configPaths = []): ConfigORM
|
||||
{
|
||||
// First determine what directories to use
|
||||
$directories = (empty($configPaths) ? $this->configPaths : $configPaths);
|
||||
$directories = (empty($configPaths) ? $this->componentPaths : $configPaths);
|
||||
|
||||
// Determine the config name
|
||||
$configName = strtolower($configName);
|
||||
|
@ -225,52 +217,4 @@ class Config
|
|||
self::$configOverrides[$configName][$configKey] = $configValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the directories. Automatically gets invoked if configPaths are added to FuzeWorks\Configurator.
|
||||
*
|
||||
* @param array $directories
|
||||
*/
|
||||
public function setDirectories(array $directories)
|
||||
{
|
||||
$this->configPaths = array_merge($this->configPaths, $directories);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a path where config files can be found
|
||||
*
|
||||
* @param string $directory The directory
|
||||
* @return void
|
||||
*/
|
||||
public function addConfigPath($directory)
|
||||
{
|
||||
if (!in_array($directory, $this->configPaths))
|
||||
{
|
||||
$this->configPaths[] = $directory;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a path where config files can be found
|
||||
*
|
||||
* @param string $directory The directory
|
||||
* @return void
|
||||
*/
|
||||
public function removeConfigPath($directory)
|
||||
{
|
||||
if (($key = array_search($directory, $this->configPaths)) !== false)
|
||||
{
|
||||
unset($this->configPaths[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all current configPaths
|
||||
*
|
||||
* @return array Array of paths where config files can be found
|
||||
*/
|
||||
public function getConfigPaths(): array
|
||||
{
|
||||
return $this->configPaths;
|
||||
}
|
||||
|
||||
}
|
|
@ -60,6 +60,7 @@ use FuzeWorks\Exception\HelperException;
|
|||
*/
|
||||
class Helpers
|
||||
{
|
||||
use ComponentPathsTrait;
|
||||
|
||||
/**
|
||||
* Array of loadedHelpers, so that they won't be reloaded
|
||||
|
@ -68,18 +69,9 @@ class Helpers
|
|||
*/
|
||||
protected $helpers = [];
|
||||
|
||||
/**
|
||||
* Paths where Helpers can be found.
|
||||
*
|
||||
* Libraries will only be loaded if either a directory is supplied or it is in one of the helperPaths
|
||||
*
|
||||
* @var array Array of paths where helpers can be found
|
||||
*/
|
||||
protected $helperPaths = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->helperPaths = Core::$appDirs;
|
||||
$this->componentPaths = Core::$appDirs;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -96,7 +88,7 @@ class Helpers
|
|||
public function load(string $helperName, array $helperDirectories = []): bool
|
||||
{
|
||||
// Determine what directories should be checked
|
||||
$helperPaths = (empty($helperDirectories) ? $this->helperPaths : $helperDirectories);
|
||||
$helperPaths = (empty($helperDirectories) ? $this->componentPaths : $helperDirectories);
|
||||
|
||||
// Check it is already loaded
|
||||
if (isset($this->helpers[$helperName]))
|
||||
|
@ -163,52 +155,4 @@ class Helpers
|
|||
{
|
||||
return $this->load($helperName, $helperPaths);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the directories. Automatically gets invoked if helperPaths are added to FuzeWorks\Configurator.
|
||||
*
|
||||
* @param array $directories
|
||||
*/
|
||||
public function setDirectories(array $directories)
|
||||
{
|
||||
$this->helperPaths = array_merge($this->helperPaths, $directories);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a path where helpers can be found
|
||||
*
|
||||
* @param string $directory The directory
|
||||
* @return void
|
||||
*/
|
||||
public function addHelperPath($directory)
|
||||
{
|
||||
if (!in_array($directory, $this->helperPaths))
|
||||
{
|
||||
$this->helperPaths[] = $directory;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a path where helpers can be found
|
||||
*
|
||||
* @param string $directory The directory
|
||||
* @return void
|
||||
*/
|
||||
public function removeHelperPath($directory)
|
||||
{
|
||||
if (($key = array_search($directory, $this->helperPaths)) !== false)
|
||||
{
|
||||
unset($this->helperPaths[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all current helperPaths
|
||||
*
|
||||
* @return array Array of paths where helpers can be found
|
||||
*/
|
||||
public function getHelperPaths(): array
|
||||
{
|
||||
return $this->helperPaths;
|
||||
}
|
||||
}
|
|
@ -36,18 +36,12 @@
|
|||
|
||||
namespace FuzeWorks;
|
||||
|
||||
|
||||
use FuzeWorks\Exception\ConfigException;
|
||||
use FuzeWorks\Exception\LibraryException;
|
||||
|
||||
class Libraries
|
||||
{
|
||||
/**
|
||||
* Array of all the paths where libraries can be found
|
||||
*
|
||||
* @var array Library paths
|
||||
*/
|
||||
protected $libraryPaths = [];
|
||||
use ComponentPathsTrait;
|
||||
|
||||
/**
|
||||
* Array of loaded library objects
|
||||
|
@ -78,7 +72,7 @@ class Libraries
|
|||
public function __construct()
|
||||
{
|
||||
$this->factory = Factory::getInstance();
|
||||
$this->libraryPaths = Core::$appDirs;
|
||||
$this->componentPaths = Core::$appDirs;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -142,7 +136,7 @@ class Libraries
|
|||
return $this->initLibrary($libraryName, $this->libraryClasses[$libraryNameLowerCase], $parameters);
|
||||
|
||||
// Try and load from the alternate directory if provided
|
||||
$paths = (empty($altDirectories) ? $this->libraryPaths : $altDirectories);
|
||||
$paths = (empty($altDirectories) ? $this->componentPaths : $altDirectories);
|
||||
|
||||
// Try and find the library in the libraryPaths
|
||||
foreach ($paths as $path)
|
||||
|
@ -209,52 +203,4 @@ class Libraries
|
|||
$this->factory->logger->log("Loaded Library: ".$libraryName);
|
||||
return $this->libraryObjects[strtolower($libraryName)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the directories. Automatically gets invoked if libraryPaths are added to FuzeWorks\Configurator.
|
||||
*
|
||||
* @param array $directories
|
||||
*/
|
||||
public function setDirectories(array $directories)
|
||||
{
|
||||
$this->libraryPaths = array_merge($this->libraryPaths, $directories);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a path where libraries can be found
|
||||
*
|
||||
* @param string $directory The directory
|
||||
* @return void
|
||||
*/
|
||||
public function addLibraryPath($directory)
|
||||
{
|
||||
if (!in_array($directory, $this->libraryPaths))
|
||||
{
|
||||
$this->libraryPaths[] = $directory;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a path where libraries can be found
|
||||
*
|
||||
* @param string $directory The directory
|
||||
* @return void
|
||||
*/
|
||||
public function removeLibraryPath($directory)
|
||||
{
|
||||
if (($key = array_search($directory, $this->libraryPaths)) !== false)
|
||||
{
|
||||
unset($this->libraryPaths[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all current libraryPaths
|
||||
*
|
||||
* @return array Array of paths where libraries can be found
|
||||
*/
|
||||
public function getLibraryPaths(): array
|
||||
{
|
||||
return $this->libraryPaths;
|
||||
}
|
||||
}
|
|
@ -62,13 +62,7 @@ use ReflectionException;
|
|||
*/
|
||||
class Plugins
|
||||
{
|
||||
|
||||
/**
|
||||
* Array of all the paths where plugins can be found
|
||||
*
|
||||
* @var array Plugin paths
|
||||
*/
|
||||
protected $pluginPaths = array();
|
||||
use ComponentPathsTrait;
|
||||
|
||||
/**
|
||||
* Array of loaded Plugins, so that they won't be reloaded
|
||||
|
@ -101,7 +95,7 @@ class Plugins
|
|||
public function __construct()
|
||||
{
|
||||
$this->cfg = Factory::getInstance()->config->plugins;
|
||||
$this->pluginPaths = Core::$appDirs;
|
||||
$this->componentPaths = Core::$appDirs;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -110,7 +104,7 @@ class Plugins
|
|||
public function loadHeadersFromPluginPaths()
|
||||
{
|
||||
// Cycle through all pluginPaths
|
||||
foreach ($this->pluginPaths as $pluginPath) {
|
||||
foreach ($this->componentPaths as $pluginPath) {
|
||||
|
||||
// If directory does not exist, skip it
|
||||
if (!file_exists($pluginPath) || !is_dir($pluginPath))
|
||||
|
@ -286,52 +280,4 @@ class Plugins
|
|||
// And return it
|
||||
return $this->plugins[$pluginName];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the directories. Automatically gets invoked if pluginPaths are added to FuzeWorks\Configurator.
|
||||
*
|
||||
* @param array $directories
|
||||
*/
|
||||
public function setDirectories(array $directories)
|
||||
{
|
||||
$this->pluginPaths = array_merge($this->pluginPaths, $directories);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a path where plugins can be found
|
||||
*
|
||||
* @param string $directory The directory
|
||||
* @return void
|
||||
*/
|
||||
public function addPluginPath($directory)
|
||||
{
|
||||
if (!in_array($directory, $this->pluginPaths))
|
||||
{
|
||||
$this->pluginPaths[] = $directory;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a path where plugins can be found
|
||||
*
|
||||
* @param string $directory The directory
|
||||
* @return void
|
||||
*/
|
||||
public function removePluginPath($directory)
|
||||
{
|
||||
if (($key = array_search($directory, $this->pluginPaths)) !== false)
|
||||
{
|
||||
unset($this->pluginPaths[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all current pluginPaths
|
||||
*
|
||||
* @return array Array of paths where plugins can be found
|
||||
*/
|
||||
public function getPluginPaths(): array
|
||||
{
|
||||
return $this->pluginPaths;
|
||||
}
|
||||
}
|
|
@ -154,40 +154,40 @@ class configTest extends CoreTestAbstract
|
|||
/**
|
||||
* @expectedException FuzeWorks\Exception\ConfigException
|
||||
*/
|
||||
public function testAddConfigPathFail()
|
||||
public function testAddComponentPathFail()
|
||||
{
|
||||
// Now test if the config can be loaded (hint: it can not)
|
||||
$this->config->getConfig('testAddConfigPath');
|
||||
$this->config->getConfig('testAddComponentPath');
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testAddConfigPathFail
|
||||
* @depends testAddComponentPathFail
|
||||
*/
|
||||
public function testAddConfigPath()
|
||||
public function testaddComponentPath()
|
||||
{
|
||||
// Add the configPath
|
||||
$this->config->addConfigPath('test'.DS.'config'.DS.'TestAddConfigPath');
|
||||
$this->config->addComponentPath('test'.DS.'config'.DS.'TestAddComponentPath');
|
||||
|
||||
// And try to load it again
|
||||
$this->assertInstanceOf('FuzeWorks\ConfigORM\ConfigORM', $this->config->getConfig('testAddConfigPath'));
|
||||
$this->assertInstanceOf('FuzeWorks\ConfigORM\ConfigORM', $this->config->getConfig('testAddComponentPath'));
|
||||
}
|
||||
|
||||
public function testRemoveConfigPath()
|
||||
public function testremoveComponentPath()
|
||||
{
|
||||
// Test if the path does NOT exist
|
||||
$this->assertFalse(in_array('test'.DS.'config'.DS.'TestRemoveConfigPath', $this->config->getConfigPaths()));
|
||||
$this->assertFalse(in_array('test'.DS.'config'.DS.'TestRemoveComponentPath', $this->config->getComponentPaths()));
|
||||
|
||||
// Add it
|
||||
$this->config->addConfigPath('test'.DS.'config'.DS.'TestRemoveConfigPath');
|
||||
$this->config->addComponentPath('test'.DS.'config'.DS.'TestRemoveComponentPath');
|
||||
|
||||
// Assert if it's there
|
||||
$this->assertTrue(in_array('test'.DS.'config'.DS.'TestRemoveConfigPath', $this->config->getConfigPaths()));
|
||||
$this->assertTrue(in_array('test'.DS.'config'.DS.'TestRemoveComponentPath', $this->config->getComponentPaths()));
|
||||
|
||||
// Remove it
|
||||
$this->config->removeConfigPath('test'.DS.'config'.DS.'TestRemoveConfigPath');
|
||||
$this->config->removeComponentPath('test'.DS.'config'.DS.'TestRemoveComponentPath');
|
||||
|
||||
// And test if it's gone again
|
||||
$this->assertFalse(in_array('test'.DS.'config'.DS.'TestRemoveConfigPath', $this->config->getConfigPaths()));
|
||||
$this->assertFalse(in_array('test'.DS.'config'.DS.'TestRemoveComponentPath', $this->config->getComponentPaths()));
|
||||
}
|
||||
|
||||
public function testSameConfigObject()
|
||||
|
@ -214,7 +214,7 @@ class configTest extends CoreTestAbstract
|
|||
|
||||
// Assert expectations
|
||||
$expected = array_merge(\FuzeWorks\Core::$appDirs, [$directory]);
|
||||
$this->assertEquals($expected, $this->config->getConfigPaths());
|
||||
$this->assertEquals($expected, $this->config->getComponentPaths());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -154,57 +154,57 @@ class helperTest extends CoreTestAbstract
|
|||
* @expectedException FuzeWorks\Exception\HelperException
|
||||
* @covers \FuzeWorks\Helpers::load
|
||||
*/
|
||||
public function testAddHelperPathFail()
|
||||
public function testAddComponentPathFail()
|
||||
{
|
||||
// First test if the function is not loaded yet
|
||||
$this->assertFalse(function_exists('testAddHelperPathFunction'));
|
||||
$this->assertFalse(function_exists('testAddComponentPathFunction'));
|
||||
|
||||
// Now test if the helper can be loaded (hint: it can not)
|
||||
$this->helpers->load('TestAddHelperPathFail');
|
||||
$this->helpers->load('TestAddComponentPathFail');
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testAddHelperPathFail
|
||||
* @covers \FuzeWorks\Helpers::addHelperPath
|
||||
* @covers \FuzeWorks\Helpers::getHelperPaths
|
||||
* @depends testAddComponentPathFail
|
||||
* @covers \FuzeWorks\Helpers::addComponentPath
|
||||
* @covers \FuzeWorks\Helpers::getComponentPaths
|
||||
*/
|
||||
public function testAddHelperPath()
|
||||
public function testAddComponentPath()
|
||||
{
|
||||
// Add the helperPath
|
||||
$this->helpers->addHelperPath('test'.DS.'helpers'.DS.'TestAddHelperPath');
|
||||
// Add the componentPath
|
||||
$this->helpers->addComponentPath('test'.DS.'helpers'.DS.'TestAddComponentPath');
|
||||
|
||||
// And try to load it again
|
||||
$this->assertTrue($this->helpers->load('TestAddHelperPath'));
|
||||
$this->assertTrue($this->helpers->load('TestAddComponentPath'));
|
||||
|
||||
// And test if the function is loaded
|
||||
$this->assertTrue(function_exists('testAddHelperPathFunction'));
|
||||
$this->assertTrue(function_exists('testAddComponentPathFunction'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FuzeWorks\Helpers::removeHelperPath
|
||||
* @covers \FuzeWorks\Helpers::getHelperPaths
|
||||
* @covers \FuzeWorks\Helpers::removeComponentPath
|
||||
* @covers \FuzeWorks\Helpers::getComponentPaths
|
||||
*/
|
||||
public function testRemoveHelperPath()
|
||||
public function testRemoveComponentPath()
|
||||
{
|
||||
// Test if the path does NOT exist
|
||||
$this->assertFalse(in_array('test'.DS.'helpers'.DS.'TestRemoveHelperPath', $this->helpers->getHelperPaths()));
|
||||
$this->assertFalse(in_array('test'.DS.'helpers'.DS.'TestRemoveComponentPath', $this->helpers->getComponentPaths()));
|
||||
|
||||
// Add it
|
||||
$this->helpers->addHelperPath('test'.DS.'helpers'.DS.'TestRemoveHelperPath');
|
||||
$this->helpers->addComponentPath('test'.DS.'helpers'.DS.'TestRemoveComponentPath');
|
||||
|
||||
// Assert if it's there
|
||||
$this->assertTrue(in_array('test'.DS.'helpers'.DS.'TestRemoveHelperPath', $this->helpers->getHelperPaths()));
|
||||
$this->assertTrue(in_array('test'.DS.'helpers'.DS.'TestRemoveComponentPath', $this->helpers->getComponentPaths()));
|
||||
|
||||
// Remove it
|
||||
$this->helpers->removeHelperPath('test'.DS.'helpers'.DS.'TestRemoveHelperPath');
|
||||
$this->helpers->removeComponentPath('test'.DS.'helpers'.DS.'TestRemoveComponentPath');
|
||||
|
||||
// And test if it's gone again
|
||||
$this->assertFalse(in_array('test'.DS.'helpers'.DS.'TestRemoveHelperPath', $this->helpers->getHelperPaths()));
|
||||
$this->assertFalse(in_array('test'.DS.'helpers'.DS.'TestRemoveComponentPath', $this->helpers->getComponentPaths()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FuzeWorks\Helpers::setDirectories
|
||||
* @covers \FuzeWorks\Helpers::getHelperPaths
|
||||
* @covers \FuzeWorks\Helpers::getComponentPaths
|
||||
*/
|
||||
public function testSetDirectories()
|
||||
{
|
||||
|
@ -214,6 +214,6 @@ class helperTest extends CoreTestAbstract
|
|||
|
||||
// Assert expectations
|
||||
$expected = array_merge(\FuzeWorks\Core::$appDirs, ['test' . DS . 'helpers', $directory]);
|
||||
$this->assertEquals($expected, $this->helpers->getHelperPaths());
|
||||
$this->assertEquals($expected, $this->helpers->getComponentPaths());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ class libraryTest extends CoreTestAbstract
|
|||
$this->assertInstanceOf('FuzeWorks\Libraries', $this->libraries);
|
||||
}
|
||||
|
||||
/* ---------------------------------- LibraryPaths ---------------------------------------------- */
|
||||
/* ---------------------------------- ComponentPaths ---------------------------------------------- */
|
||||
|
||||
/**
|
||||
* @depends testLibrariesClass
|
||||
|
@ -74,56 +74,56 @@ class libraryTest extends CoreTestAbstract
|
|||
{
|
||||
// Test initial
|
||||
$initial = array_merge(Core::$appDirs, ['test'.DS.'libraries']);
|
||||
$this->assertEquals($initial, $this->libraries->getLibraryPaths());
|
||||
$this->assertEquals($initial, $this->libraries->getComponentPaths());
|
||||
|
||||
// Add path
|
||||
$newPath = 'addPath';
|
||||
$this->libraries->setDirectories([$newPath]);
|
||||
$initial[] = $newPath;
|
||||
$this->assertEquals($initial, $this->libraries->getLibraryPaths());
|
||||
$this->assertEquals($initial, $this->libraries->getComponentPaths());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException FuzeWorks\Exception\LibraryException
|
||||
*/
|
||||
public function testAddLibraryPathFail()
|
||||
public function testAddComponentPathFail()
|
||||
{
|
||||
// First test if the library is not loaded yet
|
||||
$this->assertFalse(class_exists('TestAddLibraryPathFail', false));
|
||||
$this->assertFalse(class_exists('TestAddComponentPathFail', false));
|
||||
|
||||
// Now test if the library can be loaded (hint: it can not)
|
||||
$this->libraries->get('TestAddLibraryPathFail');
|
||||
$this->libraries->get('TestAddComponentPathFail');
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testAddLibraryPathFail
|
||||
* @depends testAddComponentPathFail
|
||||
*/
|
||||
public function testAddLibraryPath()
|
||||
public function testAddComponentPath()
|
||||
{
|
||||
// Add the libraryPath
|
||||
$this->libraries->removeLibraryPath('test'.DS.'libraries');
|
||||
$this->libraries->addLibraryPath('test'.DS.'libraries'.DS.'TestAddLibraryPath');
|
||||
// Add the componentPath
|
||||
$this->libraries->removeComponentPath('test'.DS.'libraries');
|
||||
$this->libraries->addComponentPath('test'.DS.'libraries'.DS.'TestAddComponentPath');
|
||||
|
||||
// And try to load it again
|
||||
$this->assertInstanceOf('Application\Library\TestAddLibraryPath', $this->libraries->get('TestAddLibraryPath'));
|
||||
$this->assertInstanceOf('Application\Library\TestAddComponentPath', $this->libraries->get('TestAddComponentPath'));
|
||||
}
|
||||
|
||||
public function testRemoveLibraryPath()
|
||||
public function testRemoveComponentPath()
|
||||
{
|
||||
// Test if the path does NOT exist
|
||||
$this->assertFalse(in_array('test'.DS.'libraries'.DS.'TestRemoveLibraryPath', $this->libraries->getLibraryPaths()));
|
||||
$this->assertFalse(in_array('test'.DS.'libraries'.DS.'TestRemoveComponentPath', $this->libraries->getComponentPaths()));
|
||||
|
||||
// Add it
|
||||
$this->libraries->addLibraryPath('test'.DS.'libraries'.DS.'TestRemoveLibraryPath');
|
||||
$this->libraries->addComponentPath('test'.DS.'libraries'.DS.'TestRemoveComponentPath');
|
||||
|
||||
// Assert if it's there
|
||||
$this->assertTrue(in_array('test'.DS.'libraries'.DS.'TestRemoveLibraryPath', $this->libraries->getLibraryPaths()));
|
||||
$this->assertTrue(in_array('test'.DS.'libraries'.DS.'TestRemoveComponentPath', $this->libraries->getComponentPaths()));
|
||||
|
||||
// Remove it
|
||||
$this->libraries->removeLibraryPath('test'.DS.'libraries'.DS.'TestRemoveLibraryPath');
|
||||
$this->libraries->removeComponentPath('test'.DS.'libraries'.DS.'TestRemoveComponentPath');
|
||||
|
||||
// And test if it's gone again
|
||||
$this->assertFalse(in_array('test'.DS.'libraries'.DS.'TestRemoveLibraryPath', $this->libraries->getLibraryPaths()));
|
||||
$this->assertFalse(in_array('test'.DS.'libraries'.DS.'TestRemoveComponentPath', $this->libraries->getComponentPaths()));
|
||||
}
|
||||
|
||||
/* ---------------------------------- Load library from directories ------------------- */
|
||||
|
@ -142,7 +142,7 @@ class libraryTest extends CoreTestAbstract
|
|||
public function testGetLibraryFromSubdirectory()
|
||||
{
|
||||
// Add test directory path
|
||||
$this->libraries->addLibraryPath('test'.DS.'libraries'.DS.'TestGetLibraryFromSubdirectory');
|
||||
$this->libraries->addComponentPath('test'.DS.'libraries'.DS.'TestGetLibraryFromSubdirectory');
|
||||
|
||||
$this->assertInstanceOf('Application\Library\TestGetLibraryFromSubdirectory', $this->libraries->get('TestGetLibraryFromSubdirectory'));
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ class pluginTest extends CoreTestAbstract
|
|||
public function setUp()
|
||||
{
|
||||
$this->plugins = new Plugins();
|
||||
$this->plugins->addPluginPath('test'.DS.'plugins');
|
||||
$this->plugins->addComponentPath('test'.DS.'plugins');
|
||||
$this->plugins->loadHeadersFromPluginPaths();
|
||||
}
|
||||
|
||||
|
@ -175,15 +175,15 @@ class pluginTest extends CoreTestAbstract
|
|||
*/
|
||||
public function testRunInvalidDirectory()
|
||||
{
|
||||
$this->plugins->addPluginPath('exists_not');
|
||||
$this->plugins->addComponentPath('exists_not');
|
||||
$this->plugins->loadHeadersFromPluginPaths();
|
||||
$this->plugins->get('testRunInvalidDirectory');
|
||||
}
|
||||
|
||||
public function testAddPluginPath()
|
||||
public function testAddComponentPath()
|
||||
{
|
||||
// Add the pluginPath
|
||||
$this->plugins->addPluginPath('test'.DS.'plugins'.DS.'TestAddPluginPath');
|
||||
// Add the componentPath
|
||||
$this->plugins->addComponentPath('test'.DS.'plugins'.DS.'TestAddComponentPath');
|
||||
|
||||
// And try to load it again
|
||||
$this->plugins->loadHeadersFromPluginPaths();
|
||||
|
@ -191,24 +191,24 @@ class pluginTest extends CoreTestAbstract
|
|||
}
|
||||
|
||||
/**
|
||||
* @depends testAddPluginPath
|
||||
* @depends testAddComponentPath
|
||||
*/
|
||||
public function testRemovePluginPath()
|
||||
public function testRemoveComponentPath()
|
||||
{
|
||||
// Test if the path does NOT exist
|
||||
$this->assertFalse(in_array('test'.DS.'plugins'.DS.'testRemovePluginPath', $this->plugins->getPluginPaths()));
|
||||
$this->assertFalse(in_array('test'.DS.'plugins'.DS.'testRemoveComponentPath', $this->plugins->getComponentPaths()));
|
||||
|
||||
// Add it
|
||||
$this->plugins->addPluginPath('test'.DS.'plugins'.DS.'testRemovePluginPath');
|
||||
$this->plugins->addComponentPath('test'.DS.'plugins'.DS.'testRemoveComponentPath');
|
||||
|
||||
// Assert if it's there
|
||||
$this->assertTrue(in_array('test'.DS.'plugins'.DS.'testRemovePluginPath', $this->plugins->getPluginPaths()));
|
||||
$this->assertTrue(in_array('test'.DS.'plugins'.DS.'testRemoveComponentPath', $this->plugins->getComponentPaths()));
|
||||
|
||||
// Remove it
|
||||
$this->plugins->removePluginPath('test'.DS.'plugins'.DS.'testRemovePluginPath');
|
||||
$this->plugins->removeComponentPath('test'.DS.'plugins'.DS.'testRemoveComponentPath');
|
||||
|
||||
// And test if it's gone again
|
||||
$this->assertFalse(in_array('test'.DS.'plugins'.DS.'testRemovePluginPath', $this->plugins->getPluginPaths()));
|
||||
$this->assertFalse(in_array('test'.DS.'plugins'.DS.'testRemoveComponentPath', $this->plugins->getComponentPaths()));
|
||||
}
|
||||
|
||||
public function testSetDirectories()
|
||||
|
@ -219,7 +219,7 @@ class pluginTest extends CoreTestAbstract
|
|||
$expected = [$appDir, 'test'.DS.'plugins', $directory];
|
||||
$this->plugins->setDirectories([$directory]);
|
||||
|
||||
$this->assertEquals($expected, $this->plugins->getPluginPaths());
|
||||
$this->assertEquals($expected, $this->plugins->getComponentPaths());
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
|
|
|
@ -33,10 +33,10 @@
|
|||
*
|
||||
* @version Version 1.2.0
|
||||
*/
|
||||
if ( ! function_exists('testAddHelperPathFunction'))
|
||||
if ( ! function_exists('testAddComponentPathFunction'))
|
||||
{
|
||||
|
||||
function testAddHelperPathFunction($someParameter)
|
||||
function testAddComponentPathFunction($someParameter)
|
||||
{
|
||||
return 'SomeResult';
|
||||
}
|
|
@ -35,6 +35,6 @@
|
|||
*/
|
||||
namespace Application\Library;
|
||||
|
||||
class TestAddLibraryPath {
|
||||
class TestAddComponentPath {
|
||||
|
||||
}
|
Loading…
Reference in New Issue