Implemented @covers in all unit tests. Code coverage now shows better what is actually covered and what is not.

This commit is contained in:
Abel Hoogeveen 2019-01-21 20:34:45 +01:00
parent f364245d90
commit e10d84b65d
No known key found for this signature in database
GPG Key ID: 96C2234920BF4292
19 changed files with 307 additions and 173 deletions

View File

@ -115,6 +115,18 @@ abstract class ConfigORMAbstract implements Iterator
return $this->cfg[$name]; return $this->cfg[$name];
} }
/**
* Return a value from a config file.
*
* @param string $name Key of the requested entry
* @return mixed Value of the requested entry
* @codeCoverageIgnore
*/
public function get($name)
{
return $this->cfg[$name];
}
/** /**
* Sets an entry in the config file. * Sets an entry in the config file.
* *
@ -127,6 +139,18 @@ abstract class ConfigORMAbstract implements Iterator
$this->cfg[$name] = $value; $this->cfg[$name] = $value;
} }
/**
* Sets an entry in the config file.
*
* @param string $name Key of the entry
* @param mixed $value Value of the entry
* @codeCoverageIgnore
*/
public function set($name, $value)
{
$this->cfg[$name] = $value;
}
/** /**
* Unset a value in a config file. * Unset a value in a config file.
* *

View File

@ -37,7 +37,6 @@
namespace FuzeWorks; namespace FuzeWorks;
use FuzeWorks\Exception\ConfiguratorException; use FuzeWorks\Exception\ConfiguratorException;
use FuzeWorks\Exception\InvalidArgumentException; use FuzeWorks\Exception\InvalidArgumentException;
use Tracy\Debugger;
/** /**
* Class Configurator. * Class Configurator.
@ -383,7 +382,7 @@ class Configurator
} }
} }
$container->init(); $container->initFactory();
return $container; return $container;
} }
} }

View File

@ -76,7 +76,7 @@ class Factory
* *
* @var bool Clone all Factory instances. * @var bool Clone all Factory instances.
*/ */
protected static $cloneInstances = false; private static $cloneInstances = false;
/** /**
* Whether the Factory has been initialized or not * Whether the Factory has been initialized or not
@ -158,7 +158,7 @@ class Factory
* @return Factory * @return Factory
* @throws CoreException * @throws CoreException
*/ */
public function init(): Factory public function initFactory(): Factory
{ {
// If already initialized, cancel // If already initialized, cancel
if ($this->initialized) if ($this->initialized)
@ -172,7 +172,7 @@ class Factory
} }
// Disable events if requested to do so // Disable events if requested to do so
if (!$cfg->enable_events) if (!$cfg->get('enable_events'))
{ {
Events::disable(); Events::disable();
} }

View File

@ -112,7 +112,7 @@ class Logger {
// Register the error handler, Untestable // Register the error handler, Untestable
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
if ($cfg_error->fuzeworks_error_reporting == true) if ($cfg_error->get('fuzeworks_error_reporting') == true)
{ {
self::enableHandlers(); self::enableHandlers();
} }

View File

@ -91,6 +91,7 @@ class Plugins
* Called upon creation of the plugins class. * Called upon creation of the plugins class.
* *
* @return void * @return void
* @codeCoverageIgnore
*/ */
public function __construct() public function __construct()
{ {

View File

@ -40,11 +40,12 @@ use FuzeWorks\ConfigORM\ConfigORMAbstract;
* Class ConfigORMAbstractTest * Class ConfigORMAbstractTest
* *
* Config testing suite, will test the special methods from ConfigORMAbstract * Config testing suite, will test the special methods from ConfigORMAbstract
* @coversDefaultClass \FuzeWorks\ConfigORM\ConfigORMAbstract
*/ */
class ConfigORMAbstractTest extends CoreTestAbstract class ConfigORMAbstractTest extends CoreTestAbstract
{ {
/** /**
* @covers \FuzeWorks\ConfigORM\ConfigORMAbstract::revert * @covers ::revert
*/ */
public function testRevert() public function testRevert()
{ {
@ -69,7 +70,7 @@ class ConfigORMAbstractTest extends CoreTestAbstract
} }
/** /**
* @covers \FuzeWorks\ConfigORM\ConfigORMAbstract::replace * @covers ::replace
*/ */
public function testReplaceWithNewValues() public function testReplaceWithNewValues()
{ {
@ -97,7 +98,7 @@ class ConfigORMAbstractTest extends CoreTestAbstract
/** /**
* @depends testReplaceWithNewValues * @depends testReplaceWithNewValues
* @covers \FuzeWorks\ConfigORM\ConfigORMAbstract::replace * @covers ::replace
*/ */
public function testReplaceExistingValues() public function testReplaceExistingValues()
{ {
@ -125,7 +126,7 @@ class ConfigORMAbstractTest extends CoreTestAbstract
} }
/** /**
* @covers \FuzeWorks\ConfigORM\ConfigORMAbstract::toArray * @covers ::toArray
*/ */
public function testToArray() public function testToArray()
{ {
@ -144,7 +145,7 @@ class ConfigORMAbstractTest extends CoreTestAbstract
/** /**
* @depends testToArray * @depends testToArray
* @covers \FuzeWorks\ConfigORM\ConfigORMAbstract::clear * @covers ::clear
*/ */
public function testClear() public function testClear()
{ {

View File

@ -43,6 +43,7 @@ use FuzeWorks\Events;
* Class ConfigTest. * Class ConfigTest.
* *
* Config testing suite, will test basic config functionality while also testing default ORM's * Config testing suite, will test basic config functionality while also testing default ORM's
* @coversDefaultClass \FuzeWorks\Config
*/ */
class configTest extends CoreTestAbstract class configTest extends CoreTestAbstract
{ {
@ -57,6 +58,9 @@ class configTest extends CoreTestAbstract
$this->config = new Config(); $this->config = new Config();
} }
/**
* @coversNothing
*/
public function testGetConfigClass() public function testGetConfigClass()
{ {
$this->assertInstanceOf('FuzeWorks\Config', $this->config); $this->assertInstanceOf('FuzeWorks\Config', $this->config);
@ -64,8 +68,8 @@ class configTest extends CoreTestAbstract
/** /**
* @depends testGetConfigClass * @depends testGetConfigClass
* @covers \FuzeWorks\Config::getConfig * @covers ::getConfig
* @covers \FuzeWorks\Config::loadConfigFile * @covers ::loadConfigFile
*/ */
public function testLoadConfig() public function testLoadConfig()
{ {
@ -74,8 +78,8 @@ class configTest extends CoreTestAbstract
/** /**
* @depends testLoadConfig * @depends testLoadConfig
* @covers \FuzeWorks\Config::getConfig * @covers ::getConfig
* @covers \FuzeWorks\Config::loadConfigFile * @covers ::loadConfigFile
*/ */
public function testLoadConfigWithAltDirectory() public function testLoadConfigWithAltDirectory()
{ {
@ -85,7 +89,7 @@ class configTest extends CoreTestAbstract
/** /**
* @depends testLoadConfig * @depends testLoadConfig
* @covers \FuzeWorks\Config::loadConfigFile * @covers ::loadConfigFile
* @expectedException FuzeWorks\Exception\ConfigException * @expectedException FuzeWorks\Exception\ConfigException
*/ */
public function testFileNotFound() public function testFileNotFound()
@ -95,7 +99,7 @@ class configTest extends CoreTestAbstract
/** /**
* @depends testLoadConfig * @depends testLoadConfig
* @covers \FuzeWorks\Config::loadConfigFile * @covers ::loadConfigFile
*/ */
public function testLoadConfigCancel() public function testLoadConfigCancel()
{ {
@ -112,7 +116,7 @@ class configTest extends CoreTestAbstract
/** /**
* @depends testLoadConfig * @depends testLoadConfig
* @covers \FuzeWorks\Config::loadConfigFile * @covers ::loadConfigFile
*/ */
public function testLoadConfigIntercept() public function testLoadConfigIntercept()
{ {
@ -129,8 +133,8 @@ class configTest extends CoreTestAbstract
/** /**
* @depends testLoadConfig * @depends testLoadConfig
* @covers \FuzeWorks\Config::overrideConfig * @covers ::overrideConfig
* @covers \FuzeWorks\Config::loadConfigFile * @covers ::loadConfigFile
*/ */
public function testLoadConfigOverride() public function testLoadConfigOverride()
{ {
@ -148,8 +152,8 @@ class configTest extends CoreTestAbstract
/** /**
* @depends testLoadConfigOverride * @depends testLoadConfigOverride
* @covers \FuzeWorks\Config::overrideConfig * @covers ::overrideConfig
* @covers \FuzeWorks\Config::loadConfigFile * @covers ::loadConfigFile
*/ */
public function testLoadConfigCoreOverride() public function testLoadConfigCoreOverride()
{ {
@ -168,7 +172,7 @@ class configTest extends CoreTestAbstract
} }
/** /**
* @covers \FuzeWorks\Config::getConfig * @covers ::getConfig
*/ */
public function testSameConfigObject() public function testSameConfigObject()
{ {

View File

@ -44,6 +44,7 @@ use FuzeWorks\Logger;
* Class ConfiguratorTest. * Class ConfiguratorTest.
* *
* This test will test the Configurator class * This test will test the Configurator class
* @coversDefaultClass \FuzeWorks\Configurator
*/ */
class configuratorTest extends CoreTestAbstract class configuratorTest extends CoreTestAbstract
{ {
@ -67,11 +68,17 @@ class configuratorTest extends CoreTestAbstract
Core::$logDir = dirname(__DIR__) . '/temp'; Core::$logDir = dirname(__DIR__) . '/temp';
} }
/**
* @coversNothing
*/
public function testGetConfiguratorClass() public function testGetConfiguratorClass()
{ {
$this->assertInstanceOf('FuzeWorks\Configurator', $this->configurator); $this->assertInstanceOf('FuzeWorks\Configurator', $this->configurator);
} }
/**
* @coversNothing
*/
public function testCreateContainer() public function testCreateContainer()
{ {
$this->assertInstanceOf('FuzeWorks\Factory', $this->configurator->createContainer()); $this->assertInstanceOf('FuzeWorks\Factory', $this->configurator->createContainer());
@ -81,6 +88,8 @@ class configuratorTest extends CoreTestAbstract
/** /**
* @depends testCreateContainer * @depends testCreateContainer
* @covers ::addComponent
* @covers ::createContainer
*/ */
public function testAddComponent() public function testAddComponent()
{ {
@ -98,6 +107,8 @@ class configuratorTest extends CoreTestAbstract
/** /**
* @depends testAddComponent * @depends testAddComponent
* @covers ::addComponent
* @covers ::createContainer
*/ */
public function testAddComponentClassByObject() public function testAddComponentClassByObject()
{ {
@ -117,6 +128,8 @@ class configuratorTest extends CoreTestAbstract
/** /**
* @depends testAddComponent * @depends testAddComponent
* @covers ::addComponent
* @covers ::createContainer
* @expectedException FuzeWorks\Exception\ConfiguratorException * @expectedException FuzeWorks\Exception\ConfiguratorException
*/ */
public function testAddComponentFail() public function testAddComponentFail()
@ -126,7 +139,7 @@ class configuratorTest extends CoreTestAbstract
$component = new FuzeWorks\Component\TestAddComponentFailComponent; $component = new FuzeWorks\Component\TestAddComponentFailComponent;
$this->configurator->addComponent($component); $this->configurator->addComponent($component);
// Create container // Create container and fail
$this->configurator->createContainer(); $this->configurator->createContainer();
} }
@ -134,6 +147,8 @@ class configuratorTest extends CoreTestAbstract
/** /**
* @depends testCreateContainer * @depends testCreateContainer
* @covers ::setLogDirectory
* @covers ::createContainer
*/ */
public function testSetLogDirectory() public function testSetLogDirectory()
{ {
@ -157,6 +172,7 @@ class configuratorTest extends CoreTestAbstract
/** /**
* @depends testSetLogDirectory * @depends testSetLogDirectory
* @covers ::setLogDirectory
* @expectedException \FuzeWorks\Exception\InvalidArgumentException * @expectedException \FuzeWorks\Exception\InvalidArgumentException
*/ */
public function testSetLogDirectoryNotDirectory() public function testSetLogDirectoryNotDirectory()
@ -167,6 +183,8 @@ class configuratorTest extends CoreTestAbstract
/** /**
* @depends testCreateContainer * @depends testCreateContainer
* @covers ::setTempDirectory
* @covers ::createContainer
*/ */
public function testSetTempDirectory() public function testSetTempDirectory()
{ {
@ -183,6 +201,7 @@ class configuratorTest extends CoreTestAbstract
/** /**
* @depends testSetTempDirectory * @depends testSetTempDirectory
* @covers ::setTempDirectory
* @expectedException \FuzeWorks\Exception\InvalidArgumentException * @expectedException \FuzeWorks\Exception\InvalidArgumentException
*/ */
public function testSetTempDirectoryNotDirectory() public function testSetTempDirectoryNotDirectory()
@ -194,6 +213,9 @@ class configuratorTest extends CoreTestAbstract
/** /**
* @depends testCreateContainer * @depends testCreateContainer
* @depends testAddComponent * @depends testAddComponent
* @covers ::addComponent
* @covers ::addDirectory
* @covers ::createContainer
*/ */
public function testAddComponentDirectory() public function testAddComponentDirectory()
{ {
@ -222,6 +244,11 @@ class configuratorTest extends CoreTestAbstract
/** /**
* @depends testAddComponent * @depends testAddComponent
* @covers ::deferComponentClassMethod
* @covers ::createContainer
* @covers \FuzeWorks\DeferredComponentClass::invoke
* @covers \FuzeWorks\DeferredComponentClass::isInvoked
* @covers \FuzeWorks\DeferredComponentClass::getResult
*/ */
public function testDeferComponentClassMethod() public function testDeferComponentClassMethod()
{ {
@ -251,6 +278,11 @@ class configuratorTest extends CoreTestAbstract
/** /**
* @depends testDeferComponentClassMethod * @depends testDeferComponentClassMethod
* @covers ::deferComponentClassMethod
* @covers ::createContainer
* @covers \FuzeWorks\DeferredComponentClass::invoke
* @covers \FuzeWorks\DeferredComponentClass::isInvoked
* @covers \FuzeWorks\DeferredComponentClass::getResult
*/ */
public function testDeferComponentClassMethodWithCallback() public function testDeferComponentClassMethodWithCallback()
{ {
@ -285,6 +317,7 @@ class configuratorTest extends CoreTestAbstract
/** /**
* @depends testCreateContainer * @depends testCreateContainer
* @covers ::setTimeZone
*/ */
public function testSetTimezone() public function testSetTimezone()
{ {
@ -298,6 +331,7 @@ class configuratorTest extends CoreTestAbstract
/** /**
* @depends testSetTimezone * @depends testSetTimezone
* @expectedException \FuzeWorks\Exception\InvalidArgumentException * @expectedException \FuzeWorks\Exception\InvalidArgumentException
* @covers ::setTimeZone
*/ */
public function testSetTimezoneInvalid() public function testSetTimezoneInvalid()
{ {
@ -306,6 +340,8 @@ class configuratorTest extends CoreTestAbstract
/** /**
* @depends testCreateContainer * @depends testCreateContainer
* @covers ::setParameters
* @covers ::createContainer
*/ */
public function testSetParameter() public function testSetParameter()
{ {
@ -317,6 +353,11 @@ class configuratorTest extends CoreTestAbstract
$this->assertEquals('fake_directory', Core::$tempDir); $this->assertEquals('fake_directory', Core::$tempDir);
} }
/**
* @depends testCreateContainer
* @covers ::setConfigOverride
* @covers ::createContainer
*/
public function testSetConfigOverride() public function testSetConfigOverride()
{ {
// Set an override that can be verified // Set an override that can be verified
@ -333,6 +374,9 @@ class configuratorTest extends CoreTestAbstract
/** /**
* @depends testCreateContainer * @depends testCreateContainer
* @covers ::enableDebugMode
* @covers ::isDebugMode
* @covers ::createContainer
*/ */
public function testEnableDebugMode() public function testEnableDebugMode()
{ {
@ -355,6 +399,9 @@ class configuratorTest extends CoreTestAbstract
/** /**
* @depends testEnableDebugMode * @depends testEnableDebugMode
* @covers ::enableDebugMode
* @covers ::isDebugMode
* @covers ::createContainer
*/ */
public function testDisableDebugMode() public function testDisableDebugMode()
{ {
@ -369,6 +416,9 @@ class configuratorTest extends CoreTestAbstract
/** /**
* @depends testEnableDebugMode * @depends testEnableDebugMode
* @covers ::setDebugAddress
* @covers ::enableDebugMode
* @covers ::isDebugMode
*/ */
public function testSetDebugAddress() public function testSetDebugAddress()
{ {
@ -422,6 +472,7 @@ class configuratorTest extends CoreTestAbstract
/** /**
* @depends testEnableDebugMode * @depends testEnableDebugMode
* @covers ::setDebugAddress
* @expectedException \FuzeWorks\Exception\InvalidArgumentException * @expectedException \FuzeWorks\Exception\InvalidArgumentException
*/ */
public function testSetDebugAddressInvalidArgument() public function testSetDebugAddressInvalidArgument()

View File

@ -40,6 +40,7 @@ use FuzeWorks\Core;
* Class CoreTest. * Class CoreTest.
* *
* Core testing suite, will test basic core functionality * Core testing suite, will test basic core functionality
* @coversDefaultClass \FuzeWorks\Core
*/ */
class coreTest extends CoreTestAbstract class coreTest extends CoreTestAbstract
{ {
@ -63,6 +64,9 @@ class coreTest extends CoreTestAbstract
$this->assertTrue(class_exists('FuzeWorks\Priority')); $this->assertTrue(class_exists('FuzeWorks\Priority'));
} }
/**
* @covers ::isPHP
*/
public function testIsPHP() public function testIsPHP()
{ {
$this->assertTrue(Core::isPHP('1.2.0')); $this->assertTrue(Core::isPHP('1.2.0'));

View File

@ -41,10 +41,14 @@ use FuzeWorks\Priority;
* Class EventTest. * Class EventTest.
* *
* This test will test the Event class * This test will test the Event class
* @coversDefaultClass \FuzeWorks\Event
*/ */
class eventTest extends CoreTestAbstract class eventTest extends CoreTestAbstract
{ {
/**
* @coversNothing
*/
public function testFireEvent() public function testFireEvent()
{ {
$event = Events::fireEvent('testEvent'); $event = Events::fireEvent('testEvent');
@ -52,6 +56,11 @@ class eventTest extends CoreTestAbstract
$this->assertInstanceOf('FuzeWorks\Event', $event); $this->assertInstanceOf('FuzeWorks\Event', $event);
} }
/**
* @depends testFireEvent
* @covers ::isCancelled
* @covers ::setCancelled
*/
public function testCancelEvent() public function testCancelEvent()
{ {
Events::addListener(array($this, 'listener_cancel'), 'testCancelEvent', Priority::NORMAL); Events::addListener(array($this, 'listener_cancel'), 'testCancelEvent', Priority::NORMAL);
@ -60,6 +69,11 @@ class eventTest extends CoreTestAbstract
$this->assertTrue($event->isCancelled()); $this->assertTrue($event->isCancelled());
} }
/**
* @depends testCancelEvent
* @covers ::setCancelled
* @covers ::isCancelled
*/
public function testUncancelEvent() public function testUncancelEvent()
{ {
Events::addListener(array($this, 'listener_cancel'), 'testUncancelEvent', Priority::HIGH); Events::addListener(array($this, 'listener_cancel'), 'testUncancelEvent', Priority::HIGH);

View File

@ -42,20 +42,26 @@ use FuzeWorks\Priority;
* Class EventTest. * Class EventTest.
* *
* This test will test Events * This test will test Events
* @coversDefaultClass \FuzeWorks\Events
*/ */
class eventsTest extends CoreTestAbstract class eventsTest extends CoreTestAbstract
{ {
/**
* @covers ::fireEvent
*/
public function testFireEvent() public function testFireEvent()
{ {
$mock = $this->getMockBuilder(Observer::class)->setMethods(['mockMethod'])->getMock(); $mock = $this->getMockBuilder(Observer::class)->setMethods(['mockListener'])->getMock();
$mock->expects($this->once())->method('mockMethod'); $mock->expects($this->once())->method('mockListener')->with($this->isInstanceOf('MockEvent'));
Events::addListener(array($mock, 'mockMethod'), 'mockEvent', Priority::NORMAL); Events::addListener(array($mock, 'mockListener'), 'mockEvent', Priority::NORMAL);
Events::fireEvent('mockEvent'); Events::fireEvent('mockEvent');
} }
/** /**
* @depends testFireEvent * @depends testFireEvent
* @covers ::fireEvent
*/ */
public function testObjectEvent() public function testObjectEvent()
{ {
@ -70,6 +76,7 @@ class eventsTest extends CoreTestAbstract
/** /**
* @depends testObjectEvent * @depends testObjectEvent
* @covers ::fireEvent
*/ */
public function testVariablePassing() public function testVariablePassing()
{ {
@ -86,6 +93,10 @@ class eventsTest extends CoreTestAbstract
Events::fireEvent($event); Events::fireEvent($event);
} }
/**
* @depends testFireEvent
* @covers ::fireEvent
*/
public function testEventArguments() public function testEventArguments()
{ {
// Prepare test argument // Prepare test argument
@ -101,6 +112,7 @@ class eventsTest extends CoreTestAbstract
/** /**
* @depends testVariablePassing * @depends testVariablePassing
* @covers ::fireEvent
*/ */
public function testVariableChanging() public function testVariableChanging()
{ {
@ -134,6 +146,7 @@ class eventsTest extends CoreTestAbstract
/** /**
* @depends testFireEvent * @depends testFireEvent
* @expectedException FuzeWorks\Exception\EventException * @expectedException FuzeWorks\Exception\EventException
* @covers ::fireEvent
*/ */
public function testInvalidTypeEvent() public function testInvalidTypeEvent()
{ {
@ -142,6 +155,7 @@ class eventsTest extends CoreTestAbstract
/** /**
* @depends testFireEvent * @depends testFireEvent
* @covers ::fireEvent
* @expectedException FuzeWorks\Exception\EventException * @expectedException FuzeWorks\Exception\EventException
*/ */
public function testInvalidClassEvent() public function testInvalidClassEvent()
@ -151,6 +165,8 @@ class eventsTest extends CoreTestAbstract
/** /**
* @depends testFireEvent * @depends testFireEvent
* @covers ::addListener
* @covers ::removeListener
*/ */
public function testAddAndRemoveListener() public function testAddAndRemoveListener()
{ {
@ -168,6 +184,7 @@ class eventsTest extends CoreTestAbstract
/** /**
* @depends testAddAndRemoveListener * @depends testAddAndRemoveListener
* @covers ::addListener
* @expectedException FuzeWorks\Exception\EventException * @expectedException FuzeWorks\Exception\EventException
*/ */
public function testAddInvalidPriorityListener() public function testAddInvalidPriorityListener()
@ -177,6 +194,7 @@ class eventsTest extends CoreTestAbstract
/** /**
* @depends testAddAndRemoveListener * @depends testAddAndRemoveListener
* @covers ::addListener
* @expectedException FuzeWorks\Exception\EventException * @expectedException FuzeWorks\Exception\EventException
*/ */
public function testAddInvalidNameListener() public function testAddInvalidNameListener()
@ -186,6 +204,7 @@ class eventsTest extends CoreTestAbstract
/** /**
* @depends testAddAndRemoveListener * @depends testAddAndRemoveListener
* @covers ::removeListener
* @expectedException FuzeWorks\Exception\EventException * @expectedException FuzeWorks\Exception\EventException
*/ */
public function testRemoveInvalidPriorityListener() public function testRemoveInvalidPriorityListener()
@ -195,6 +214,7 @@ class eventsTest extends CoreTestAbstract
/** /**
* @depends testAddAndRemoveListener * @depends testAddAndRemoveListener
* @covers ::removeListener
*/ */
public function testRemoveUnsetEventListener() public function testRemoveUnsetEventListener()
{ {
@ -203,6 +223,7 @@ class eventsTest extends CoreTestAbstract
/** /**
* @depends testAddAndRemoveListener * @depends testAddAndRemoveListener
* @covers ::removeListener
*/ */
public function testRemoveUnsetListener() public function testRemoveUnsetListener()
{ {
@ -212,6 +233,7 @@ class eventsTest extends CoreTestAbstract
/** /**
* @depends testAddAndRemoveListener * @depends testAddAndRemoveListener
* @covers ::addListener
*/ */
public function testListenerVariablePass() public function testListenerVariablePass()
{ {
@ -228,6 +250,11 @@ class eventsTest extends CoreTestAbstract
Events::fireEvent($event); Events::fireEvent($event);
} }
/**
* @depends testFireEvent
* @covers ::disable
* @covers ::fireEvent
*/
public function testDisable() public function testDisable()
{ {
// First add the listener, expect it to be never called // First add the listener, expect it to be never called
@ -242,6 +269,11 @@ class eventsTest extends CoreTestAbstract
Events::fireEvent('mockEvent'); Events::fireEvent('mockEvent');
} }
/**
* @depends testDisable
* @covers ::disable
* @covers ::enable
*/
public function testReEnable() public function testReEnable()
{ {
// First add the listener, expect it to be never called // First add the listener, expect it to be never called

View File

@ -41,9 +41,14 @@ use FuzeWorks\Exception\FactoryException;
* Class FactoryTest. * Class FactoryTest.
* *
* Will test the FuzeWorks Factory. * Will test the FuzeWorks Factory.
* @coversDefaultClass \FuzeWorks\Factory
*/ */
class factoryTest extends CoreTestAbstract class factoryTest extends CoreTestAbstract
{ {
/**
* @covers ::getInstance
*/
public function testCanLoadFactory() public function testCanLoadFactory()
{ {
$this->assertInstanceOf('FuzeWorks\Factory', Factory::getInstance()); $this->assertInstanceOf('FuzeWorks\Factory', Factory::getInstance());
@ -51,6 +56,7 @@ class factoryTest extends CoreTestAbstract
/** /**
* @depends testCanLoadFactory * @depends testCanLoadFactory
* @covers ::getInstance
*/ */
public function testLoadSameInstance() public function testLoadSameInstance()
{ {
@ -59,6 +65,8 @@ class factoryTest extends CoreTestAbstract
/** /**
* @depends testCanLoadFactory * @depends testCanLoadFactory
* @covers ::getInstance
* @covers ::cloneInstance
*/ */
public function testLoadDifferentInstance() public function testLoadDifferentInstance()
{ {
@ -71,6 +79,8 @@ class factoryTest extends CoreTestAbstract
/** /**
* @depends testCanLoadFactory * @depends testCanLoadFactory
* @covers ::getInstance
* @covers ::setInstance
*/ */
public function testObjectsSameInstance() public function testObjectsSameInstance()
{ {
@ -97,6 +107,9 @@ class factoryTest extends CoreTestAbstract
/** /**
* @depends testObjectsSameInstance * @depends testObjectsSameInstance
* @covers ::getInstance
* @covers ::setInstance
* @covers ::cloneInstance
*/ */
public function testObjectsDifferentInstance() public function testObjectsDifferentInstance()
{ {
@ -117,6 +130,9 @@ class factoryTest extends CoreTestAbstract
$factory3 = Factory::getInstance(true)->setInstance('Mock', $mock); $factory3 = Factory::getInstance(true)->setInstance('Mock', $mock);
$factory4 = Factory::getInstance(true)->setInstance('Mock', $mock); $factory4 = Factory::getInstance(true)->setInstance('Mock', $mock);
// Should be same for now
$this->assertSame($factory3->mock, $factory4->mock);
// Clone the instance in factory4 // Clone the instance in factory4
$factory4->cloneInstance('Mock'); $factory4->cloneInstance('Mock');
@ -125,6 +141,8 @@ class factoryTest extends CoreTestAbstract
} }
/** /**
* @depends testCanLoadFactory
* @covers ::cloneInstance
* @expectedException FuzeWorks\Exception\FactoryException * @expectedException FuzeWorks\Exception\FactoryException
*/ */
public function testCloneInstanceWrongClassname() public function testCloneInstanceWrongClassname()
@ -136,6 +154,13 @@ class factoryTest extends CoreTestAbstract
$factory->cloneInstance('fake'); $factory->cloneInstance('fake');
} }
/**
* @depends testCanLoadFactory
* @covers ::enableCloneInstances
* @covers ::disableCloneInstances
* @covers ::cloneInstance
* @covers ::getInstance
*/
public function testGlobalCloneInstance() public function testGlobalCloneInstance()
{ {
// First test without global cloning // First test without global cloning
@ -154,6 +179,11 @@ class factoryTest extends CoreTestAbstract
$this->assertSame(Factory::getInstance(), Factory::getInstance()); $this->assertSame(Factory::getInstance(), Factory::getInstance());
} }
/**
* @depends testCanLoadFactory
* @covers ::getInstance
* @covers ::newInstance
*/
public function testNewFactoryInstance() public function testNewFactoryInstance()
{ {
// Load the different factories // Load the different factories
@ -176,6 +206,8 @@ class factoryTest extends CoreTestAbstract
} }
/** /**
* @depends testNewFactoryInstance
* @covers ::newInstance
* @expectedException FuzeWorks\Exception\FactoryException * @expectedException FuzeWorks\Exception\FactoryException
*/ */
public function testFactoryNewInstanceNotExist() public function testFactoryNewInstanceNotExist()
@ -188,6 +220,8 @@ class factoryTest extends CoreTestAbstract
} }
/** /**
* @depends testNewFactoryInstance
* @covers ::newInstance
* @expectedException FuzeWorks\Exception\FactoryException * @expectedException FuzeWorks\Exception\FactoryException
*/ */
public function testFactoryNewInstanceWrongNamespace() public function testFactoryNewInstanceWrongNamespace()
@ -199,6 +233,11 @@ class factoryTest extends CoreTestAbstract
$factory->newInstance('helpers', 'Test\\'); $factory->newInstance('helpers', 'Test\\');
} }
/**
* @depends testNewFactoryInstance
* @covers ::setInstance
* @covers ::removeInstance
*/
public function testRemoveInstance() public function testRemoveInstance()
{ {
// Load the factory // Load the factory
@ -222,6 +261,8 @@ class factoryTest extends CoreTestAbstract
} }
/** /**
* @depends testRemoveInstance
* @covers ::removeInstance
* @expectedException FuzeWorks\Exception\FactoryException * @expectedException FuzeWorks\Exception\FactoryException
*/ */
public function testRemoveInstanceNotExist() public function testRemoveInstanceNotExist()
@ -233,6 +274,11 @@ class factoryTest extends CoreTestAbstract
$factory->removeInstance('fake'); $factory->removeInstance('fake');
} }
/**
* @depends testCanLoadFactory
* @covers ::instanceIsset
* @covers ::setInstance
*/
public function testInstanceIsset() public function testInstanceIsset()
{ {
// Load the factory // Load the factory

View File

@ -42,6 +42,7 @@ use FuzeWorks\Helpers;
* Class HelperTest. * Class HelperTest.
* *
* Helpers testing suite, will test basic loading of Helpers * Helpers testing suite, will test basic loading of Helpers
* @coversDefaultClass \FuzeWorks\Helpers
*/ */
class helperTest extends CoreTestAbstract class helperTest extends CoreTestAbstract
{ {
@ -58,13 +59,16 @@ class helperTest extends CoreTestAbstract
$this->helpers->setDirectories([3 => ['test' . DS . 'helpers']]); $this->helpers->setDirectories([3 => ['test' . DS . 'helpers']]);
} }
/**
* @coversNothing
*/
public function testGetHelpersClass() public function testGetHelpersClass()
{ {
$this->assertInstanceOf('FuzeWorks\Helpers', $this->helpers); $this->assertInstanceOf('FuzeWorks\Helpers', $this->helpers);
} }
/** /**
* @covers \FuzeWorks\Helpers::load * @covers ::load
*/ */
public function testLoadHelper() public function testLoadHelper()
{ {
@ -80,7 +84,7 @@ class helperTest extends CoreTestAbstract
/** /**
* @depends testLoadHelper * @depends testLoadHelper
* @covers \FuzeWorks\Helpers::load * @covers ::load
*/ */
public function testLoadHelperWithoutSubdirectory() public function testLoadHelperWithoutSubdirectory()
{ {
@ -96,7 +100,7 @@ class helperTest extends CoreTestAbstract
/** /**
* @depends testLoadHelper * @depends testLoadHelper
* @covers \FuzeWorks\Helpers::load * @covers ::load
*/ */
public function testLoadHelperWithAltDirectory() public function testLoadHelperWithAltDirectory()
{ {
@ -112,7 +116,7 @@ class helperTest extends CoreTestAbstract
/** /**
* @depends testLoadHelper * @depends testLoadHelper
* @covers \FuzeWorks\Helpers::load * @covers ::load
*/ */
public function testReloadHelper() public function testReloadHelper()
{ {
@ -134,7 +138,7 @@ class helperTest extends CoreTestAbstract
/** /**
* @depends testLoadHelper * @depends testLoadHelper
* @covers \FuzeWorks\Helpers::load * @covers ::load
*/ */
public function testCancelLoadHelper() public function testCancelLoadHelper()
{ {
@ -152,7 +156,7 @@ class helperTest extends CoreTestAbstract
/** /**
* @depends testLoadHelper * @depends testLoadHelper
* @covers \FuzeWorks\Helpers::get * @covers ::get
*/ */
public function testGetHelper() public function testGetHelper()
{ {

View File

@ -42,6 +42,7 @@ use FuzeWorks\Libraries;
* Class LibraryTest. * Class LibraryTest.
* *
* Libraries testing suite, will test basic loading of and management of Libraries * Libraries testing suite, will test basic loading of and management of Libraries
* @coversDefaultClass \FuzeWorks\Libraries
*/ */
class libraryTest extends CoreTestAbstract class libraryTest extends CoreTestAbstract
{ {
@ -60,6 +61,9 @@ class libraryTest extends CoreTestAbstract
$this->libraries->setDirectories([3 => ['test'.DS.'libraries']]); $this->libraries->setDirectories([3 => ['test'.DS.'libraries']]);
} }
/**
* @coversNothing
*/
public function testLibrariesClass() public function testLibrariesClass()
{ {
$this->assertInstanceOf('FuzeWorks\Libraries', $this->libraries); $this->assertInstanceOf('FuzeWorks\Libraries', $this->libraries);
@ -69,6 +73,8 @@ class libraryTest extends CoreTestAbstract
/** /**
* @depends testLibrariesClass * @depends testLibrariesClass
* @covers ::get
* @covers ::initLibrary
*/ */
public function testGetLibraryFromDirectory() public function testGetLibraryFromDirectory()
{ {
@ -77,6 +83,8 @@ class libraryTest extends CoreTestAbstract
/** /**
* @depends testGetLibraryFromDirectory * @depends testGetLibraryFromDirectory
* @covers ::get
* @covers ::initLibrary
*/ */
public function testGetLibraryFromSubdirectory() public function testGetLibraryFromSubdirectory()
{ {
@ -88,6 +96,8 @@ class libraryTest extends CoreTestAbstract
/** /**
* @depends testGetLibraryFromDirectory * @depends testGetLibraryFromDirectory
* @covers ::get
* @covers ::initLibrary
*/ */
public function testGetLibraryFromAltDirectory() public function testGetLibraryFromAltDirectory()
{ {
@ -97,6 +107,9 @@ class libraryTest extends CoreTestAbstract
} }
/** /**
* @depends testGetLibraryFromDirectory
* @covers ::get
* @covers ::initLibrary
* @expectedException FuzeWorks\Exception\LibraryException * @expectedException FuzeWorks\Exception\LibraryException
*/ */
public function testGetLibraryFail() public function testGetLibraryFail()
@ -105,6 +118,9 @@ class libraryTest extends CoreTestAbstract
} }
/** /**
* @depends testGetLibraryFromDirectory
* @covers ::get
* @covers ::initLibrary
* @expectedException FuzeWorks\Exception\LibraryException * @expectedException FuzeWorks\Exception\LibraryException
*/ */
public function testGetLibraryNoName() public function testGetLibraryNoName()
@ -113,6 +129,9 @@ class libraryTest extends CoreTestAbstract
} }
/** /**
* @depends testGetLibraryFromDirectory
* @covers ::get
* @covers ::initLibrary
* @expectedException FuzeWorks\Exception\LibraryException * @expectedException FuzeWorks\Exception\LibraryException
*/ */
public function testGetLibraryNoClass() public function testGetLibraryNoClass()
@ -120,6 +139,11 @@ class libraryTest extends CoreTestAbstract
$this->libraries->get('TestGetLibraryNoClass'); $this->libraries->get('TestGetLibraryNoClass');
} }
/**
* @depends testGetLibraryFromDirectory
* @covers ::get
* @covers ::initLibrary
*/
public function testGetLibraryParametersFromConfig() public function testGetLibraryParametersFromConfig()
{ {
// Prepare the config file // Prepare the config file
@ -137,6 +161,10 @@ class libraryTest extends CoreTestAbstract
/* ---------------------------------- Add libraries --------------------------------------------- */ /* ---------------------------------- Add libraries --------------------------------------------- */
/**
* @covers ::addLibraryObject
* @covers ::get
*/
public function testAddLibraryObject() public function testAddLibraryObject()
{ {
$this->libraries->addLibraryObject('TestAddLibraryObject', 5); $this->libraries->addLibraryObject('TestAddLibraryObject', 5);
@ -144,6 +172,10 @@ class libraryTest extends CoreTestAbstract
$this->assertEquals(5, $this->libraries->get('TestAddLibraryObject')); $this->assertEquals(5, $this->libraries->get('TestAddLibraryObject'));
} }
/**
* @covers ::addLibraryClass
* @covers ::get
*/
public function testAddLibraryClass() public function testAddLibraryClass()
{ {
require_once('test'.DS.'libraries'.DS.'TestAddLibraryClass'.DS.'TestAddLibraryClass.php'); require_once('test'.DS.'libraries'.DS.'TestAddLibraryClass'.DS.'TestAddLibraryClass.php');
@ -155,6 +187,7 @@ class libraryTest extends CoreTestAbstract
/** /**
* @depends testAddLibraryClass * @depends testAddLibraryClass
* @covers ::addLibraryClass
* @expectedException \FuzeWorks\Exception\LibraryException * @expectedException \FuzeWorks\Exception\LibraryException
*/ */
public function testAddLibraryClassFail() public function testAddLibraryClassFail()

View File

@ -43,6 +43,7 @@ use FuzeWorks\Exception\LoggerException;
* Class ModelTest. * Class ModelTest.
* *
* Will test the FuzeWorks Model System. * Will test the FuzeWorks Model System.
* @coversDefaultClass \FuzeWorks\Logger
*/ */
class loggerTest extends CoreTestAbstract class loggerTest extends CoreTestAbstract
{ {
@ -56,6 +57,9 @@ class loggerTest extends CoreTestAbstract
Logger::$logs = array(); Logger::$logs = array();
} }
/**
* @coversNothing
*/
public function testGetLogger() public function testGetLogger()
{ {
$this->assertInstanceOf('FuzeWorks\Logger', new Logger); $this->assertInstanceOf('FuzeWorks\Logger', new Logger);
@ -63,6 +67,9 @@ class loggerTest extends CoreTestAbstract
$this->assertInstanceOf('FuzeWorks\Logger', new Logger); $this->assertInstanceOf('FuzeWorks\Logger', new Logger);
} }
/**
* @covers ::errorHandler
*/
public function testErrorHandler() public function testErrorHandler()
{ {
Logger::errorHandler(E_ERROR, 'Example error', __FILE__, 1); Logger::errorHandler(E_ERROR, 'Example error', __FILE__, 1);
@ -77,6 +84,8 @@ class loggerTest extends CoreTestAbstract
/** /**
* @depends testErrorHandler * @depends testErrorHandler
* @covers ::errorHandler
* @covers ::getType
*/ */
public function testErrorHandlerTypes() public function testErrorHandlerTypes()
{ {
@ -114,6 +123,9 @@ class loggerTest extends CoreTestAbstract
} }
} }
/**
* @covers ::exceptionHandler
*/
public function testExceptionHandler() public function testExceptionHandler()
{ {
// Create the exception // Create the exception
@ -129,6 +141,9 @@ class loggerTest extends CoreTestAbstract
Logger::exceptionHandler($exception); Logger::exceptionHandler($exception);
} }
/**
* @covers ::log
*/
public function testLog() public function testLog()
{ {
// Log the message // Log the message
@ -147,6 +162,12 @@ class loggerTest extends CoreTestAbstract
/** /**
* @depends testLog * @depends testLog
* @covers ::newLevel
* @covers ::stopLevel
* @covers ::logError
* @covers ::logWarning
* @covers ::logDebug
* @covers ::mark
*/ */
public function testLogTypes() public function testLogTypes()
{ {
@ -174,6 +195,11 @@ class loggerTest extends CoreTestAbstract
} }
} }
/**
* @covers ::enable
* @covers ::disable
* @covers ::isEnabled
*/
public function testEnableDisable() public function testEnableDisable()
{ {
// First enable // First enable

View File

@ -42,6 +42,7 @@ use FuzeWorks\Plugins;
* Class PluginsTest. * Class PluginsTest.
* *
* Plugins testing suite, will test basic loading of and management of Plugins * Plugins testing suite, will test basic loading of and management of Plugins
* @coversDefaultClass \FuzeWorks\Plugins
*/ */
class pluginTest extends CoreTestAbstract class pluginTest extends CoreTestAbstract
{ {
@ -58,6 +59,9 @@ class pluginTest extends CoreTestAbstract
$this->plugins->loadHeadersFromPluginPaths(); $this->plugins->loadHeadersFromPluginPaths();
} }
/**
* @coversNothing
*/
public function testGetPluginsClass() public function testGetPluginsClass()
{ {
$this->assertInstanceOf('FuzeWorks\Plugins', $this->plugins); $this->assertInstanceOf('FuzeWorks\Plugins', $this->plugins);
@ -65,6 +69,7 @@ class pluginTest extends CoreTestAbstract
/** /**
* @depends testGetPluginsClass * @depends testGetPluginsClass
* @covers ::get
*/ */
public function testLoadPlugin() public function testLoadPlugin()
{ {
@ -73,6 +78,7 @@ class pluginTest extends CoreTestAbstract
/** /**
* @depends testLoadPlugin * @depends testLoadPlugin
* @covers ::get
*/ */
public function testReloadPlugin() public function testReloadPlugin()
{ {
@ -81,6 +87,7 @@ class pluginTest extends CoreTestAbstract
/** /**
* @depends testLoadPlugin * @depends testLoadPlugin
* @covers ::get
*/ */
public function testLoadHeader() public function testLoadHeader()
{ {
@ -97,6 +104,7 @@ class pluginTest extends CoreTestAbstract
/** /**
* @depends testLoadPlugin * @depends testLoadPlugin
* @covers ::get
* @expectedException FuzeWorks\Exception\PluginException * @expectedException FuzeWorks\Exception\PluginException
*/ */
public function testMissingHeader() public function testMissingHeader()
@ -106,6 +114,7 @@ class pluginTest extends CoreTestAbstract
/** /**
* @depends testLoadPlugin * @depends testLoadPlugin
* @covers ::get
*/ */
public function testGetPluginMethod() public function testGetPluginMethod()
{ {
@ -114,6 +123,7 @@ class pluginTest extends CoreTestAbstract
/** /**
* @depends testLoadPlugin * @depends testLoadPlugin
* @covers ::get
*/ */
public function testGetPluginWithClassFile() public function testGetPluginWithClassFile()
{ {
@ -122,6 +132,7 @@ class pluginTest extends CoreTestAbstract
/** /**
* @depends testLoadPlugin * @depends testLoadPlugin
* @covers ::get
* @expectedException FuzeWorks\Exception\PluginException * @expectedException FuzeWorks\Exception\PluginException
*/ */
public function testMissingPlugin() public function testMissingPlugin()
@ -131,18 +142,17 @@ class pluginTest extends CoreTestAbstract
/** /**
* @depends testMissingPlugin * @depends testMissingPlugin
* @covers ::get
* @expectedException FuzeWorks\Exception\PluginException * @expectedException FuzeWorks\Exception\PluginException
*/ */
public function testLoadHeaderNotIPluginHeader() public function testLoadHeaderNotIPluginHeader()
{ {
// Attempt to load all headers
$this->plugins->loadHeadersFromPluginPaths();
$this->plugins->get('TestLoadHeaderNotIPluginHeader'); $this->plugins->get('TestLoadHeaderNotIPluginHeader');
} }
/** /**
* @depends testLoadPlugin * @depends testLoadPlugin
* @covers ::get
* @expectedException FuzeWorks\Exception\PluginException * @expectedException FuzeWorks\Exception\PluginException
*/ */
public function testInvalidClass() public function testInvalidClass()
@ -151,6 +161,7 @@ class pluginTest extends CoreTestAbstract
} }
/** /**
* @covers ::get
* @expectedException FuzeWorks\Exception\PluginException * @expectedException FuzeWorks\Exception\PluginException
*/ */
public function testGetMissingName() public function testGetMissingName()
@ -160,6 +171,8 @@ class pluginTest extends CoreTestAbstract
/** /**
* @depends testLoadPlugin * @depends testLoadPlugin
* @covers ::get
* @covers ::loadHeadersFromPluginPaths
* @expectedException FuzeWorks\Exception\PluginException * @expectedException FuzeWorks\Exception\PluginException
*/ */
public function testDisabledPlugin() public function testDisabledPlugin()
@ -171,6 +184,8 @@ class pluginTest extends CoreTestAbstract
/** /**
* @depends testLoadPlugin * @depends testLoadPlugin
* @covers ::get
* @covers ::loadHeadersFromPluginPaths
* @expectedException FuzeWorks\Exception\PluginException * @expectedException FuzeWorks\Exception\PluginException
*/ */
public function testRunInvalidDirectory() public function testRunInvalidDirectory()

View File

@ -39,10 +39,14 @@ use FuzeWorks\Priority;
* Class priorityTest. * Class priorityTest.
* *
* This test will test the Priority class * This test will test the Priority class
* @coversDefaultClass \FuzeWorks\Priority
*/ */
class priorityTest extends CoreTestAbstract class priorityTest extends CoreTestAbstract
{ {
/**
* @coversNothing
*/
public function testPriorities() public function testPriorities()
{ {
$this->assertEquals(Priority::LOWEST, 5); $this->assertEquals(Priority::LOWEST, 5);
@ -53,6 +57,9 @@ class priorityTest extends CoreTestAbstract
$this->assertEquals(Priority::MONITOR, 0); $this->assertEquals(Priority::MONITOR, 0);
} }
/**
* @covers ::getPriority
*/
public function testGetPriority() public function testGetPriority()
{ {
$this->assertEquals(Priority::getPriority(5), 'Priority::LOWEST'); $this->assertEquals(Priority::getPriority(5), 'Priority::LOWEST');
@ -63,16 +70,25 @@ class priorityTest extends CoreTestAbstract
$this->assertEquals(Priority::getPriority(0), 'Priority::MONITOR'); $this->assertEquals(Priority::getPriority(0), 'Priority::MONITOR');
} }
/**
* @covers ::getPriority
*/
public function testGetInvalidPriority() public function testGetInvalidPriority()
{ {
$this->assertFalse(Priority::getPriority(99)); $this->assertFalse(Priority::getPriority(99));
} }
/**
* @covers ::getHighestPriority
*/
public function testHighestPriority() public function testHighestPriority()
{ {
$this->assertEquals(Priority::getHighestPriority(), Priority::MONITOR); $this->assertEquals(Priority::getHighestPriority(), Priority::MONITOR);
} }
/**
* @covers ::getLowestPriority
*/
public function testLowestPriority() public function testLowestPriority()
{ {
$this->assertEquals(Priority::getLowestPriority(), Priority::LOWEST); $this->assertEquals(Priority::getLowestPriority(), Priority::LOWEST);

View File

@ -52,7 +52,7 @@ class coreStartEventTest extends CoreTestAbstract
Events::addListener(array($mock, 'mockMethod'), 'coreStartEvent', Priority::NORMAL); Events::addListener(array($mock, 'mockMethod'), 'coreStartEvent', Priority::NORMAL);
$factory = new Factory; $factory = new Factory;
$factory->init(); $factory->initFactory();
} }
} }

View File

@ -1,136 +0,0 @@
<?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
*/
// This autoloader provide convinient way to working with mock object
// make the test looks natural. This autoloader support cascade file loading as well
// within mocks directory.
//
// Prototype :
//
// $mock_table = new Mock_Libraries_Table(); // Will load ./mocks/libraries/table.php
// $mock_database_driver = new Mock_Database_Driver(); // Will load ./mocks/database/driver.php
// and so on...
function autoload($class)
{
$dir = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR;
$fw_core = array(
'Benchmark',
'Config',
'Controller',
'Exceptions',
'Hooks',
'Input',
'Lang',
'Loader',
'Log',
'Model',
'Output',
'Router',
'Security',
'URI',
'Utf8'
);
$fw_libraries = array(
'Calendar',
'Cart',
'Driver_Library',
'Email',
'Encrypt',
'Encryption',
'Form_validation',
'Ftp',
'Image_lib',
'Javascript',
'Migration',
'Pagination',
'Parser',
'Profiler',
'Table',
'Trackback',
'Typography',
'Unit_test',
'Upload',
'User_agent',
'Xmlrpc',
'Zip'
);
$fw_drivers = array('Session', 'Cache');
if (strpos($class, 'Mock_') === 0)
{
$class = strtolower(str_replace(array('Mock_', '_'), array('', DIRECTORY_SEPARATOR), $class));
}
elseif (strpos($class, 'FW_') === 0)
{
$subclass = substr($class, 3);
if (in_array($subclass, $fw_core))
{
$dir = 'Core'.DIRECTORY_SEPARATOR.'System'.DIRECTORY_SEPARATOR;
$class = $subclass;
}
elseif (in_array($subclass, $fw_libraries))
{
$dir = 'Core'.DIRECTORY_SEPARATOR.'Libraries'.DIRECTORY_SEPARATOR;
$class = ($subclass === 'Driver_Library') ? 'Driver' : $subclass;
}
elseif (in_array($subclass, $fw_drivers))
{
$dir = 'Core'.DIRECTORY_SEPARATOR.'Libraries'.DIRECTORY_SEPARATOR.$subclass.DIRECTORY_SEPARATOR;
$class = $subclass;
}
elseif (in_array(($parent = strtok($subclass, '_')), $fw_drivers)) {
$dir = 'Core'.DIRECTORY_SEPARATOR.'Libraries'.DIRECTORY_SEPARATOR.$parent.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR;
$class = $subclass;
}
else
{
$class = strtolower($class);
}
}
$file = isset($file) ? $file : $dir.$class.'.php';
if ( ! file_exists($file))
{
return FALSE;
}
include_once($file);
}