diff --git a/src/FuzeWorks/ComponentPathsTrait.php b/src/FuzeWorks/ComponentPathsTrait.php index 1c80264..18ed6c6 100644 --- a/src/FuzeWorks/ComponentPathsTrait.php +++ b/src/FuzeWorks/ComponentPathsTrait.php @@ -45,7 +45,7 @@ trait ComponentPathsTrait * * @var array $componentPaths */ - protected $componentPaths = array(); + protected $componentPaths = []; /** * Set the directories. Automatically gets invoked if componentPaths are added by FuzeWorks\Configurator. @@ -54,42 +54,47 @@ trait ComponentPathsTrait */ public function setDirectories(array $componentPaths) { - $this->componentPaths = array_merge($this->componentPaths, $componentPaths); + $this->componentPaths = $componentPaths; } /** * Add a path where objects for this component can be found * * @param string $componentPath + * @param int $priority */ - public function addComponentPath($componentPath) + public function addComponentPath($componentPath, $priority = Priority::NORMAL) { - if (!in_array($componentPath, $this->componentPaths)) - { - $this->componentPaths[] = $componentPath; - } + if (!isset($this->componentPaths[$priority])) + $this->componentPaths[$priority] = []; + + if (!in_array($componentPath, $this->componentPaths[$priority])) + $this->componentPaths[$priority][] = $componentPath; } /** * Remove a path where objects for this component can be found * * @param string $componentPath + * @param int $priority */ - public function removeComponentPath($componentPath) + public function removeComponentPath($componentPath, $priority = Priority::NORMAL) { - if (($key = array_search($componentPath, $this->componentPaths)) !== false) - { - unset($this->componentPaths[$key]); - } + if (!isset($this->componentPaths[$priority])) + return; + + if (($key = array_search($componentPath, $this->componentPaths[$priority])) !== false) + unset($this->componentPaths[$priority][$key]); } /** * Get a list of all current componentPaths * + * @param int $priority * @return array of paths where objects for this component can be found */ - public function getComponentPaths(): array + public function getComponentPaths($priority = Priority::NORMAL): array { - return $this->componentPaths; + return (isset($this->componentPaths[$priority]) ? $this->componentPaths[$priority] : []); } } \ No newline at end of file diff --git a/src/FuzeWorks/Config.php b/src/FuzeWorks/Config.php index 74b1aea..7ced647 100644 --- a/src/FuzeWorks/Config.php +++ b/src/FuzeWorks/Config.php @@ -66,11 +66,6 @@ class Config */ public static $configOverrides = []; - public function __construct() - { - $this->componentPaths = Core::$appDirs; - } - /** * Retrieve a config file object * @@ -81,20 +76,24 @@ class Config */ public function getConfig(string $configName, array $configPaths = []): ConfigORM { - // First determine what directories to use - $directories = (empty($configPaths) ? $this->componentPaths : $configPaths); - // Determine the config name $configName = strtolower($configName); - + // If it's already loaded, return the existing object if (isset($this->cfg[$configName])) { return $this->cfg[$configName]; } + // First determine what directories to use + $paths = []; + if (!empty($configPaths)) + $paths[3] = $configPaths; + else + $paths = $this->componentPaths; + // Otherwise try and load a new one - $this->cfg[$configName] = $this->loadConfigFile($configName, $directories); + $this->cfg[$configName] = $this->loadConfigFile($configName, $paths); return $this->cfg[$configName]; } @@ -148,29 +147,34 @@ class Config // If cancelled, load empty config if ($event->isCancelled()) - { return new ConfigORM(); - } - // Cycle through all directories - foreach ($event->configPaths as $configPath) + // Cycle through all priorities if they exist + for ($i=Priority::getHighestPriority(); $i<=Priority::getLowestPriority(); $i++) { - // If file exists, load it and break the loop - $file = $configPath . DS . 'config.'.strtolower($event->configName).'.php'; - if (file_exists($file)) + if (!isset($event->configPaths[$i])) + continue; + + // Cycle through all directories + foreach ($event->configPaths[$i] as $configPath) { - // Load object - $configORM = (new ConfigORM())->load($file); - - // Override config values if they exist - if (isset(self::$configOverrides[$event->configName])) + // If file exists, load it and break the loop + $file = $configPath . DS . 'config.'.strtolower($event->configName).'.php'; + if (file_exists($file)) { - foreach (self::$configOverrides[$event->configName] as $configKey => $configValue) - $configORM->{$configKey} = $configValue; - } + // Load object + $configORM = (new ConfigORM())->load($file); - // Return object - return $configORM; + // Override config values if they exist + if (isset(self::$configOverrides[$event->configName])) + { + foreach (self::$configOverrides[$event->configName] as $configKey => $configValue) + $configORM->{$configKey} = $configValue; + } + + // Return object + return $configORM; + } } } diff --git a/src/FuzeWorks/Configurator.php b/src/FuzeWorks/Configurator.php index cf1607e..759a5d8 100644 --- a/src/FuzeWorks/Configurator.php +++ b/src/FuzeWorks/Configurator.php @@ -75,7 +75,7 @@ class Configurator * * @var array of directories */ - protected $directories = ['app' => []]; + protected $directories = []; /** * Array of ComponentClass methods to be invoked once ComponentClass is loaded @@ -124,12 +124,20 @@ class Configurator * Add a directory to FuzeWorks * * @param string $directory - * @param string $category Optional. Defaults to 'app + * @param string $category Optional + * @param int $priority * @return $this */ - public function addDirectory(string $directory, string $category = 'app'): Configurator + public function addDirectory(string $directory, string $category, $priority = Priority::NORMAL): Configurator { - $this->directories[$category][] = $directory; + if (!isset($this->directories[$category])) + $this->directories[$category] = []; + + if (!isset($this->directories[$category][$priority])) + $this->directories[$category][$priority] = []; + + if (!in_array($directory, $this->directories[$category][$priority])) + $this->directories[$category][$priority][] = $directory; return $this; } @@ -318,7 +326,6 @@ class Configurator // First set all the fixed directories Core::$tempDir = $this->parameters['tempDir']; Core::$logDir = $this->parameters['logDir']; - Core::$appDirs = $this->directories['app']; // Then prepare the debugger $debug = ($this->parameters['debugEnabled'] && $this->parameters['debugMatch'] ? true : false); @@ -366,14 +373,14 @@ class Configurator } } - // And add all directories to the components - foreach ($this->directories as $component => $directories) { + // Add directories to Components + foreach ($this->directories as $component => $priorityArray) + { Logger::logDebug("Adding directories for '" . $component . "'"); - if ($component == 'app') - continue; - if (method_exists($container->{$component}, 'setDirectories')) - $container->{$component}->setDirectories($directories); + { + $container->{$component}->setDirectories($priorityArray); + } } $container->init(); diff --git a/src/FuzeWorks/Core.php b/src/FuzeWorks/Core.php index 5039164..a3367ac 100644 --- a/src/FuzeWorks/Core.php +++ b/src/FuzeWorks/Core.php @@ -71,8 +71,6 @@ class Core public static $logDir; - public static $appDirs = []; - /** * The HTTP status code of the current request * diff --git a/src/FuzeWorks/Helpers.php b/src/FuzeWorks/Helpers.php index 8a5925a..82ef361 100644 --- a/src/FuzeWorks/Helpers.php +++ b/src/FuzeWorks/Helpers.php @@ -69,11 +69,6 @@ class Helpers */ protected $helpers = []; - public function __construct() - { - $this->componentPaths = Core::$appDirs; - } - /** * Load a helper. * @@ -81,14 +76,14 @@ class Helpers * or from one of the helperPaths (which you can add). * * @param string $helperName Name of the helper - * @param array $helperDirectories + * @param array $helperPaths * @return bool Whether the helper was successfully loaded (true if yes) * @throws HelperException */ - public function load(string $helperName, array $helperDirectories = []): bool + public function load(string $helperName, array $helperPaths = []): bool { // Determine what directories should be checked - $helperPaths = (empty($helperDirectories) ? $this->componentPaths : $helperDirectories); + $helperPaths = (empty($helperPaths) ? $this->componentPaths : [3 => $helperPaths]); // Check it is already loaded if (isset($this->helpers[$helperName])) @@ -115,27 +110,33 @@ class Helpers } // Iterate over helperPaths and attempt to load if helper exists - foreach ($event->helperPaths as $helperPath) + for ($i=Priority::getHighestPriority(); $i<=Priority::getLowestPriority(); $i++) { - $file = $helperPath . DS . $event->helperName . '.php'; - $subfile = $helperPath . DS . $event->helperName . DS . $event->helperName . '.php'; - if (file_exists($file)) - { - // Load and register - include_once($file); - $this->helpers[$event->helperName] = true; - Logger::log("Loaded helper '".$event->helperName."'"); - return true; - } + if (!isset($event->helperPaths[$i])) + continue; - // If php file not in main directory, check subdirectories - elseif (file_exists($subfile)) + foreach ($event->helperPaths[$i] as $helperPath) { - // Load and register - include_once($subfile); - $this->helpers[$event->helperName] = true; - Logger::log("Loaded helper '".$event->helperName."''"); - return true; + $file = $helperPath . DS . $event->helperName . '.php'; + $subfile = $helperPath . DS . $event->helperName . DS . $event->helperName . '.php'; + if (file_exists($file)) + { + // Load and register + include_once($file); + $this->helpers[$event->helperName] = true; + Logger::log("Loaded helper '".$event->helperName."'"); + return true; + } + + // If php file not in main directory, check subdirectories + elseif (file_exists($subfile)) + { + // Load and register + include_once($subfile); + $this->helpers[$event->helperName] = true; + Logger::log("Loaded helper '".$event->helperName."''"); + return true; + } } } diff --git a/src/FuzeWorks/Libraries.php b/src/FuzeWorks/Libraries.php index 551a10f..d18640d 100644 --- a/src/FuzeWorks/Libraries.php +++ b/src/FuzeWorks/Libraries.php @@ -72,7 +72,6 @@ class Libraries public function __construct() { $this->factory = Factory::getInstance(); - $this->componentPaths = Core::$appDirs; } /** @@ -112,11 +111,11 @@ class Libraries * * @param string $libraryName * @param array $parameters - * @param array $altDirectories + * @param array $libraryPaths * @return object * @throws LibraryException */ - public function get(string $libraryName, array $parameters = [], array $altDirectories = []) + public function get(string $libraryName, array $parameters = [], array $libraryPaths = []) { // Test for empty string if (empty($libraryName)) @@ -136,24 +135,30 @@ class Libraries return $this->initLibrary($libraryName, $this->libraryClasses[$libraryNameLowerCase], $parameters); // Try and load from the alternate directory if provided - $paths = (empty($altDirectories) ? $this->componentPaths : $altDirectories); + $libraryPaths = (empty($libraryPaths) ? $this->componentPaths : [3 => $libraryPaths]); // Try and find the library in the libraryPaths - foreach ($paths as $path) + for ($i=Priority::getHighestPriority(); $i<=Priority::getLowestPriority(); $i++) { - // First look if a .php file exists in the libraryPath - $classFile = $path . DS . $libraryFilename . '.php'; - if (file_exists($classFile)) - { - require_once($classFile); - return $this->initLibrary($libraryName, $libraryClassname); - } + if (!isset($libraryPaths[$i])) + continue; - $classFile = $path . DS . $libraryFilename . DS . $libraryFilename . '.php'; - if (file_exists($classFile)) + foreach ($libraryPaths[$i] as $path) { - require_once($classFile); - return $this->initLibrary($libraryName, $libraryClassname); + // First look if a .php file exists in the libraryPath + $classFile = $path . DS . $libraryFilename . '.php'; + if (file_exists($classFile)) + { + require_once($classFile); + return $this->initLibrary($libraryName, $libraryClassname); + } + + $classFile = $path . DS . $libraryFilename . DS . $libraryFilename . '.php'; + if (file_exists($classFile)) + { + require_once($classFile); + return $this->initLibrary($libraryName, $libraryClassname); + } } } diff --git a/src/FuzeWorks/Plugins.php b/src/FuzeWorks/Plugins.php index 69ffbe6..cd91d65 100644 --- a/src/FuzeWorks/Plugins.php +++ b/src/FuzeWorks/Plugins.php @@ -95,7 +95,6 @@ class Plugins public function __construct() { $this->cfg = Factory::getInstance()->config->plugins; - $this->componentPaths = Core::$appDirs; } /** @@ -104,49 +103,55 @@ class Plugins public function loadHeadersFromPluginPaths() { // Cycle through all pluginPaths - foreach ($this->componentPaths as $pluginPath) { - - // If directory does not exist, skip it - if (!file_exists($pluginPath) || !is_dir($pluginPath)) - { - continue; - } + for ($i=Priority::getHighestPriority(); $i<=Priority::getLowestPriority(); $i++) + { + if (!isset($this->componentPaths[$i])) + continue; - // Fetch the contents of the path - $pluginPathContents = array_diff(scandir($pluginPath), array('..', '.')); - - // Now go through each entry in the plugin folder - foreach ($pluginPathContents as $pluginFolder) { - // @codeCoverageIgnoreStart - if (!is_dir($pluginPath . DS . $pluginFolder)) - { - continue; - } - // @codeCoverageIgnoreEnd + foreach ($this->componentPaths[$i] as $pluginPath) { - // If a header file exists, use it - $file = $pluginPath . DS . $pluginFolder . DS . 'header.php'; - $pluginFolder = ucfirst($pluginFolder); - $className = '\FuzeWorks\Plugins\\'.$pluginFolder.'Header'; - if (file_exists($file)) - { - // Load the header file - require_once($file); - $header = new $className(); - if (!$header instanceof iPluginHeader) + // If directory does not exist, skip it + if (!file_exists($pluginPath) || !is_dir($pluginPath)) + { + continue; + } + + // Fetch the contents of the path + $pluginPathContents = array_diff(scandir($pluginPath), array('..', '.')); + + // Now go through each entry in the plugin folder + foreach ($pluginPathContents as $pluginFolder) { + // @codeCoverageIgnoreStart + if (!is_dir($pluginPath . DS . $pluginFolder)) { continue; } + // @codeCoverageIgnoreEnd - // Load the header - $this->loadHeader($header); - } + // If a header file exists, use it + $file = $pluginPath . DS . $pluginFolder . DS . 'header.php'; + $pluginFolder = ucfirst($pluginFolder); + $className = '\FuzeWorks\Plugins\\'.$pluginFolder.'Header'; + if (file_exists($file)) + { + // Load the header file + require_once($file); + $header = new $className(); + if (!$header instanceof iPluginHeader) + { + continue; + } - // If it doesn't exist, skip it - continue; - } + // Load the header + $this->loadHeader($header); + } - } + // If it doesn't exist, skip it + continue; + } + + } + } } /** diff --git a/src/Layout/layout.logger_http.php b/src/Layout/layout.logger_http.php index ae5b14f..960b648 100644 --- a/src/Layout/layout.logger_http.php +++ b/src/Layout/layout.logger_http.php @@ -47,9 +47,6 @@ foreach ($logs as $log) { } elseif ($log['type'] == 'ERROR') { $string .= '
[' . $log['type'] . ']' . (!empty($log['context']) && is_string($log['context']) ? '[' . $log['context'] . ']' : '') . ' ' . $log['message'] . ' ' . (!empty($log['logFile']) ? $log['logFile'] : '') . ' : ' . (!empty($log['logLine']) ? $log['logLine'] : '') . '(' . round($log['runtime'] * 1000, 4) . ' ms)
'; - } elseif ($log['type'] == 'EXCEPTION') { - $string .= '
[' . $log['type'] . ']' . (!empty($log['context']) && is_string($log['context']) ? '[' . $log['context'] . ']' : '') . ' ' . $log['message'] . ' - ' . (!empty($log['logFile']) ? $log['logFile'] : '') . ' : ' . (!empty($log['logLine']) ? $log['logLine'] : '') . '(' . round($log['runtime'] * 1000, 4) . ' ms)
'; } elseif ($log['type'] == 'WARNING') { $string .= '
[' . $log['type'] . ']' . (!empty($log['context']) && is_string($log['context']) ? '[' . $log['context'] . ']' : '') . ' ' . $log['message'] . ' ' . (!empty($log['logFile']) ? $log['logFile'] : '') . ' : ' . (!empty($log['logLine']) ? $log['logLine'] : '') . '(' . round($log['runtime'] * 1000, 4) . ' ms)
'; diff --git a/test/components/TestAddComponentDirectory/TestAddComponentDirectory.php b/test/components/TestAddComponentDirectory/TestAddComponentDirectory.php index 2a19595..34a74b7 100644 --- a/test/components/TestAddComponentDirectory/TestAddComponentDirectory.php +++ b/test/components/TestAddComponentDirectory/TestAddComponentDirectory.php @@ -34,6 +34,7 @@ * @version Version 1.2.0 */ namespace FuzeWorks\Component; +use FuzeWorks\ComponentPathsTrait; use FuzeWorks\Configurator; use FuzeWorks\Factory; use FuzeWorks\iComponent; @@ -46,7 +47,7 @@ class TestAddComponentDirectoryComponent implements iComponent return ['testaddcomponentdirectory' => 'FuzeWorks\Component\TestAddComponentDirectory']; } - public function onAddComponent(Configurator $configurator): Configurator + public function onAddComponent(Configurator $configurator) { return $configurator; } @@ -64,11 +65,7 @@ class TestAddComponentDirectoryComponent implements iComponent class TestAddComponentDirectory { - public $variable = 5; - public $directories = []; + use ComponentPathsTrait; - public function setDirectories(array $directories) - { - $this->directories = $directories; - } + public $variable = 5; } \ No newline at end of file diff --git a/test/config/TestAddComponentPath/config.testaddcomponentpath.php b/test/config/TestLoadConfigWithAltDirectory/SubDirectory/config.testloadconfigwithaltdirectory.php similarity index 98% rename from test/config/TestAddComponentPath/config.testaddcomponentpath.php rename to test/config/TestLoadConfigWithAltDirectory/SubDirectory/config.testloadconfigwithaltdirectory.php index 2a9b349..5e43c3c 100644 --- a/test/config/TestAddComponentPath/config.testaddcomponentpath.php +++ b/test/config/TestLoadConfigWithAltDirectory/SubDirectory/config.testloadconfigwithaltdirectory.php @@ -34,5 +34,5 @@ * @version Version 1.2.0 */ return array( - 'key' => 'value' - ); \ No newline at end of file + 'key' => 'value' +); \ No newline at end of file diff --git a/test/core/core_configTest.php b/test/core/core_configTest.php index 64ee276..d636515 100644 --- a/test/core/core_configTest.php +++ b/test/core/core_configTest.php @@ -64,14 +64,28 @@ class configTest extends CoreTestAbstract /** * @depends testGetConfigClass + * @covers \FuzeWorks\Config::getConfig + * @covers \FuzeWorks\Config::loadConfigFile */ public function testLoadConfig() { $this->assertInstanceOf('FuzeWorks\ConfigORM\ConfigORM', $this->config->getConfig('error')); } + /** + * @depends testLoadConfig + * @covers \FuzeWorks\Config::getConfig + * @covers \FuzeWorks\Config::loadConfigFile + */ + public function testLoadConfigWithAltDirectory() + { + $config = $this->config->getConfig('TestLoadConfigWithAltDirectory', ['test'.DS.'config'.DS.'TestLoadConfigWithAltDirectory'.DS.'SubDirectory']); + $this->assertEquals('value', $config->key); + } + /** * @depends testLoadConfig + * @covers \FuzeWorks\Config::loadConfigFile * @expectedException FuzeWorks\Exception\ConfigException */ public function testFileNotFound() @@ -81,6 +95,7 @@ class configTest extends CoreTestAbstract /** * @depends testLoadConfig + * @covers \FuzeWorks\Config::loadConfigFile */ public function testLoadConfigCancel() { @@ -97,6 +112,7 @@ class configTest extends CoreTestAbstract /** * @depends testLoadConfig + * @covers \FuzeWorks\Config::loadConfigFile */ public function testLoadConfigIntercept() { @@ -152,44 +168,8 @@ class configTest extends CoreTestAbstract } /** - * @expectedException FuzeWorks\Exception\ConfigException + * @covers \FuzeWorks\Config::getConfig */ - public function testAddComponentPathFail() - { - // Now test if the config can be loaded (hint: it can not) - $this->config->getConfig('testAddComponentPath'); - } - - /** - * @depends testAddComponentPathFail - */ - public function testaddComponentPath() - { - // Add the configPath - $this->config->addComponentPath('test'.DS.'config'.DS.'TestAddComponentPath'); - - // And try to load it again - $this->assertInstanceOf('FuzeWorks\ConfigORM\ConfigORM', $this->config->getConfig('testAddComponentPath')); - } - - public function testremoveComponentPath() - { - // Test if the path does NOT exist - $this->assertFalse(in_array('test'.DS.'config'.DS.'TestRemoveComponentPath', $this->config->getComponentPaths())); - - // Add it - $this->config->addComponentPath('test'.DS.'config'.DS.'TestRemoveComponentPath'); - - // Assert if it's there - $this->assertTrue(in_array('test'.DS.'config'.DS.'TestRemoveComponentPath', $this->config->getComponentPaths())); - - // Remove it - $this->config->removeComponentPath('test'.DS.'config'.DS.'TestRemoveComponentPath'); - - // And test if it's gone again - $this->assertFalse(in_array('test'.DS.'config'.DS.'TestRemoveComponentPath', $this->config->getComponentPaths())); - } - public function testSameConfigObject() { $config = $this->config->getConfig('testsameconfigobject', array('test'.DS.'config'.DS.'TestSameConfigObject')); @@ -206,15 +186,4 @@ class configTest extends CoreTestAbstract $this->assertEquals($config2->key, 'other_value'); } - public function testSetDirectories() - { - // Add the directory - $directory = 'test' . DS . 'config'; - $this->config->setDirectories([$directory]); - - // Assert expectations - $expected = array_merge(\FuzeWorks\Core::$appDirs, [$directory]); - $this->assertEquals($expected, $this->config->getComponentPaths()); - } - } diff --git a/test/core/core_configuratorTest.php b/test/core/core_configuratorTest.php index edde115..731e8d4 100644 --- a/test/core/core_configuratorTest.php +++ b/test/core/core_configuratorTest.php @@ -63,7 +63,6 @@ class configuratorTest extends CoreTestAbstract public function tearDown() { - Core::$appDirs = [dirname(__DIR__) . '/application']; Core::$tempDir = dirname(__DIR__) . '/temp'; Core::$logDir = dirname(__DIR__) . '/temp'; } @@ -192,22 +191,6 @@ class configuratorTest extends CoreTestAbstract $this->configurator->setTempDirectory('not_exist'); } - /** - * @depends testCreateContainer - */ - public function testAddAppDirectory() - { - // Create mock filesystem - vfsStream::setup('testAddAppDirectory'); - - // Add the directory - $this->assertInstanceOf('FuzeWorks\Configurator', $this->configurator->addDirectory(vfsStream::url('testAddAppDirectory'))); - - // Create container and test if properly set - $this->configurator->createContainer(); - $this->assertEquals(Core::$appDirs, [vfsStream::url('testAddAppDirectory')]); - } - /** * @depends testCreateContainer * @depends testAddComponent @@ -232,7 +215,7 @@ class configuratorTest extends CoreTestAbstract $this->assertEquals(5, $container->testaddcomponentdirectory->variable); // Verify directory is set - $this->assertEquals($container->testaddcomponentdirectory->directories, [vfsStream::url('testAddComponentDirectory')]); + $this->assertEquals([vfsStream::url('testAddComponentDirectory')], $container->testaddcomponentdirectory->getComponentPaths()); } /* ---------------------------------- Deferred Invocation --------------------------------------- */ diff --git a/test/core/core_coreTest.php b/test/core/core_coreTest.php index c617222..1fc4941 100644 --- a/test/core/core_coreTest.php +++ b/test/core/core_coreTest.php @@ -48,11 +48,19 @@ class coreTest extends CoreTestAbstract // Assert $this->assertTrue(class_exists('FuzeWorks\Core')); $this->assertTrue(class_exists('FuzeWorks\Config')); - $this->assertTrue(class_exists('FuzeWorks\Logger')); + $this->assertTrue(class_exists('FuzeWorks\Configurator')); + $this->assertTrue(trait_exists('FuzeWorks\ComponentPathsTrait')); + $this->assertTrue(class_exists('FuzeWorks\DeferredComponentClass')); + $this->assertTrue(class_exists('FuzeWorks\Event')); $this->assertTrue(class_exists('FuzeWorks\Events')); $this->assertTrue(class_exists('FuzeWorks\Factory')); $this->assertTrue(class_exists('FuzeWorks\Helpers')); + $this->assertTrue(interface_exists('FuzeWorks\iComponent')); + $this->assertTrue(interface_exists('FuzeWorks\iPluginHeader')); $this->assertTrue(class_exists('FuzeWorks\Libraries')); + $this->assertTrue(class_exists('FuzeWorks\Logger')); + $this->assertTrue(class_exists('FuzeWorks\Plugins')); + $this->assertTrue(class_exists('FuzeWorks\Priority')); } public function testIsPHP() diff --git a/test/core/core_helperTest.php b/test/core/core_helperTest.php index bc5d625..8e0543f 100644 --- a/test/core/core_helperTest.php +++ b/test/core/core_helperTest.php @@ -55,7 +55,7 @@ class helperTest extends CoreTestAbstract { // Prepare class $this->helpers = new Helpers(); - $this->helpers->setDirectories(['test' . DS . 'helpers']); + $this->helpers->setDirectories([3 => ['test' . DS . 'helpers']]); } public function testGetHelpersClass() @@ -94,6 +94,22 @@ class helperTest extends CoreTestAbstract $this->assertTrue(function_exists('testLoadHelperWithoutSubdirectory')); } + /** + * @depends testLoadHelper + * @covers \FuzeWorks\Helpers::load + */ + public function testLoadHelperWithAltDirectory() + { + $this->assertFalse(function_exists('testLoadHelperWithAltDirectory')); + + $this->assertTrue($this->helpers->load( + 'TestLoadHelperWithAltDirectory', + ['test' . DS . 'helpers' . DS . 'TestLoadHelperWithAltDirectory' . DS . 'SubDirectory'] + )); + + $this->assertTrue(function_exists('testLoadHelperWithAltDirectory')); + } + /** * @depends testLoadHelper * @covers \FuzeWorks\Helpers::load @@ -149,71 +165,4 @@ class helperTest extends CoreTestAbstract // Test if the function exists now $this->assertTrue(function_exists('testGetHelper')); } - - /** - * @expectedException FuzeWorks\Exception\HelperException - * @covers \FuzeWorks\Helpers::load - */ - public function testAddComponentPathFail() - { - // First test if the function is not loaded yet - $this->assertFalse(function_exists('testAddComponentPathFunction')); - - // Now test if the helper can be loaded (hint: it can not) - $this->helpers->load('TestAddComponentPathFail'); - } - - /** - * @depends testAddComponentPathFail - * @covers \FuzeWorks\Helpers::addComponentPath - * @covers \FuzeWorks\Helpers::getComponentPaths - */ - public function testAddComponentPath() - { - // Add the componentPath - $this->helpers->addComponentPath('test'.DS.'helpers'.DS.'TestAddComponentPath'); - - // And try to load it again - $this->assertTrue($this->helpers->load('TestAddComponentPath')); - - // And test if the function is loaded - $this->assertTrue(function_exists('testAddComponentPathFunction')); - } - - /** - * @covers \FuzeWorks\Helpers::removeComponentPath - * @covers \FuzeWorks\Helpers::getComponentPaths - */ - public function testRemoveComponentPath() - { - // Test if the path does NOT exist - $this->assertFalse(in_array('test'.DS.'helpers'.DS.'TestRemoveComponentPath', $this->helpers->getComponentPaths())); - - // Add it - $this->helpers->addComponentPath('test'.DS.'helpers'.DS.'TestRemoveComponentPath'); - - // Assert if it's there - $this->assertTrue(in_array('test'.DS.'helpers'.DS.'TestRemoveComponentPath', $this->helpers->getComponentPaths())); - - // Remove it - $this->helpers->removeComponentPath('test'.DS.'helpers'.DS.'TestRemoveComponentPath'); - - // And test if it's gone again - $this->assertFalse(in_array('test'.DS.'helpers'.DS.'TestRemoveComponentPath', $this->helpers->getComponentPaths())); - } - - /** - * @covers \FuzeWorks\Helpers::setDirectories - * @covers \FuzeWorks\Helpers::getComponentPaths - */ - public function testSetDirectories() - { - // Add the directory - $directory = 'test' . DS . 'helpers'; - $this->helpers->setDirectories([$directory]); - - // Assert expectations - $expected = array_merge(\FuzeWorks\Core::$appDirs, ['test' . DS . 'helpers', $directory]); - $this->assertEquals($expected, $this->helpers->getComponentPaths()); - } } diff --git a/test/core/core_libraryTest.php b/test/core/core_libraryTest.php index e08b526..0849480 100644 --- a/test/core/core_libraryTest.php +++ b/test/core/core_libraryTest.php @@ -57,7 +57,7 @@ class libraryTest extends CoreTestAbstract $this->libraries = new Libraries(); // And then set all paths - $this->libraries->setDirectories(['test'.DS.'libraries']); + $this->libraries->setDirectories([3 => ['test'.DS.'libraries']]); } public function testLibrariesClass() @@ -65,67 +65,6 @@ class libraryTest extends CoreTestAbstract $this->assertInstanceOf('FuzeWorks\Libraries', $this->libraries); } - /* ---------------------------------- ComponentPaths ---------------------------------------------- */ - - /** - * @depends testLibrariesClass - */ - public function testSetDirectories() - { - // Test initial - $initial = array_merge(Core::$appDirs, ['test'.DS.'libraries']); - $this->assertEquals($initial, $this->libraries->getComponentPaths()); - - // Add path - $newPath = 'addPath'; - $this->libraries->setDirectories([$newPath]); - $initial[] = $newPath; - $this->assertEquals($initial, $this->libraries->getComponentPaths()); - } - - /** - * @expectedException FuzeWorks\Exception\LibraryException - */ - public function testAddComponentPathFail() - { - // First test if the library is not loaded yet - $this->assertFalse(class_exists('TestAddComponentPathFail', false)); - - // Now test if the library can be loaded (hint: it can not) - $this->libraries->get('TestAddComponentPathFail'); - } - - /** - * @depends testAddComponentPathFail - */ - public function testAddComponentPath() - { - // 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\TestAddComponentPath', $this->libraries->get('TestAddComponentPath')); - } - - public function testRemoveComponentPath() - { - // Test if the path does NOT exist - $this->assertFalse(in_array('test'.DS.'libraries'.DS.'TestRemoveComponentPath', $this->libraries->getComponentPaths())); - - // Add it - $this->libraries->addComponentPath('test'.DS.'libraries'.DS.'TestRemoveComponentPath'); - - // Assert if it's there - $this->assertTrue(in_array('test'.DS.'libraries'.DS.'TestRemoveComponentPath', $this->libraries->getComponentPaths())); - - // Remove it - $this->libraries->removeComponentPath('test'.DS.'libraries'.DS.'TestRemoveComponentPath'); - - // And test if it's gone again - $this->assertFalse(in_array('test'.DS.'libraries'.DS.'TestRemoveComponentPath', $this->libraries->getComponentPaths())); - } - /* ---------------------------------- Load library from directories ------------------- */ /** @@ -186,7 +125,7 @@ class libraryTest extends CoreTestAbstract // Prepare the config file $libraryName = 'TestGetLibraryParametersFromConfig'; $libraryDir = 'test'.DS.'libraries'.DS.'TestGetLibraryParametersFromConfig'; - $config = Factory::getInstance()->config->getConfig(strtolower($libraryName), [$libraryDir]); + Factory::getInstance()->config->getConfig(strtolower($libraryName), [$libraryDir]); // Load the library $lib = $this->libraries->get('TestGetLibraryParametersFromConfig'); diff --git a/test/core/core_pluginsTest.php b/test/core/core_pluginsTest.php index f74c78a..b1a9986 100644 --- a/test/core/core_pluginsTest.php +++ b/test/core/core_pluginsTest.php @@ -180,48 +180,6 @@ class pluginTest extends CoreTestAbstract $this->plugins->get('testRunInvalidDirectory'); } - public function testAddComponentPath() - { - // Add the componentPath - $this->plugins->addComponentPath('test'.DS.'plugins'.DS.'TestAddComponentPath'); - - // And try to load it again - $this->plugins->loadHeadersFromPluginPaths(); - $this->assertInstanceOf('Application\Plugin\ActualPlugin', $this->plugins->get('ActualPlugin')); - } - - /** - * @depends testAddComponentPath - */ - public function testRemoveComponentPath() - { - // Test if the path does NOT exist - $this->assertFalse(in_array('test'.DS.'plugins'.DS.'testRemoveComponentPath', $this->plugins->getComponentPaths())); - - // Add it - $this->plugins->addComponentPath('test'.DS.'plugins'.DS.'testRemoveComponentPath'); - - // Assert if it's there - $this->assertTrue(in_array('test'.DS.'plugins'.DS.'testRemoveComponentPath', $this->plugins->getComponentPaths())); - - // Remove it - $this->plugins->removeComponentPath('test'.DS.'plugins'.DS.'testRemoveComponentPath'); - - // And test if it's gone again - $this->assertFalse(in_array('test'.DS.'plugins'.DS.'testRemoveComponentPath', $this->plugins->getComponentPaths())); - } - - public function testSetDirectories() - { - // Add the directory - $appDir = Core::$appDirs[0]; - $directory = 'test' . DS . 'helpers'; - $expected = [$appDir, 'test'.DS.'plugins', $directory]; - $this->plugins->setDirectories([$directory]); - - $this->assertEquals($expected, $this->plugins->getComponentPaths()); - } - public function tearDown() { $factory = Factory::getInstance(); diff --git a/test/helpers/TestAddComponentPath/TestAddComponentPath.php b/test/helpers/TestLoadHelperWithAltDirectory/SubDirectory/TestLoadHelperWithAltDirectory/TestLoadHelperWithAltDirectory.php similarity index 90% rename from test/helpers/TestAddComponentPath/TestAddComponentPath.php rename to test/helpers/TestLoadHelperWithAltDirectory/SubDirectory/TestLoadHelperWithAltDirectory/TestLoadHelperWithAltDirectory.php index 39b0382..b1fec73 100644 --- a/test/helpers/TestAddComponentPath/TestAddComponentPath.php +++ b/test/helpers/TestLoadHelperWithAltDirectory/SubDirectory/TestLoadHelperWithAltDirectory/TestLoadHelperWithAltDirectory.php @@ -33,11 +33,12 @@ * * @version Version 1.2.0 */ -if ( ! function_exists('testAddComponentPathFunction')) + +if ( ! function_exists('testLoadHelperWithAltDirectory')) { - function testAddComponentPathFunction($someParameter) - { - return 'SomeResult'; - } + function testLoadHelperWithAltDirectory($someParameter) + { + return 'SomeResult'; + } } \ No newline at end of file diff --git a/test/libraries/TestAddComponentPath/TestAddComponentPath.php b/test/libraries/TestAddComponentPath/TestAddComponentPath.php deleted file mode 100644 index 16e3e94..0000000 --- a/test/libraries/TestAddComponentPath/TestAddComponentPath.php +++ /dev/null @@ -1,40 +0,0 @@ -