libraries = new Libraries(); // And then set all paths $this->libraries->setDirectories(['test'.DS.'libraries']); } public function testLibrariesClass() { $this->assertInstanceOf('FuzeWorks\Libraries', $this->libraries); } /* ---------------------------------- LibraryPaths ---------------------------------------------- */ /** * @depends testLibrariesClass */ public function testSetDirectories() { // Test initial $initial = array_merge(Core::$appDirs, ['test'.DS.'libraries']); $this->assertEquals($initial, $this->libraries->getLibraryPaths()); // Add path $newPath = 'addPath'; $this->libraries->setDirectories([$newPath]); $initial[] = $newPath; $this->assertEquals($initial, $this->libraries->getLibraryPaths()); } /** * @expectedException FuzeWorks\Exception\LibraryException */ public function testAddLibraryPathFail() { // First test if the library is not loaded yet $this->assertFalse(class_exists('TestAddLibraryPathFail', false)); // Now test if the library can be loaded (hint: it can not) $this->libraries->get('TestAddLibraryPathFail'); } /** * @depends testAddLibraryPathFail */ public function testAddLibraryPath() { // Add the libraryPath $this->libraries->removeLibraryPath('test'.DS.'libraries'); $this->libraries->addLibraryPath('test'.DS.'libraries'.DS.'testAddLibraryPath'); // And try to load it again $this->assertInstanceOf('Application\Library\TestAddLibraryPath', $this->libraries->get('TestAddLibraryPath')); } public function testRemoveLibraryPath() { // Test if the path does NOT exist $this->assertFalse(in_array('test'.DS.'libraries'.DS.'testRemoveLibraryPath', $this->libraries->getLibraryPaths())); // Add it $this->libraries->addLibraryPath('test'.DS.'libraries'.DS.'testRemoveLibraryPath'); // Assert if it's there $this->assertTrue(in_array('test'.DS.'libraries'.DS.'testRemoveLibraryPath', $this->libraries->getLibraryPaths())); // Remove it $this->libraries->removeLibraryPath('test'.DS.'libraries'.DS.'testRemoveLibraryPath'); // And test if it's gone again $this->assertFalse(in_array('test'.DS.'libraries'.DS.'testRemoveLibraryPath', $this->libraries->getLibraryPaths())); } /* ---------------------------------- Load library from directories ------------------- */ /** * @depends testLibrariesClass */ public function testGetLibraryFromDirectory() { $this->assertInstanceOf('Application\Library\TestGetLibraryFromDirectory', $this->libraries->get('TestGetLibraryFromDirectory')); } /** * @depends testGetLibraryFromDirectory */ public function testGetLibraryFromSubdirectory() { // Add test directory path $this->libraries->addLibraryPath('test'.DS.'libraries'.DS.'testGetLibraryFromSubdirectory'); $this->assertInstanceOf('Application\Library\TestGetLibraryFromSubdirectory', $this->libraries->get('TestGetLibraryFromSubdirectory')); } /** * @depends testGetLibraryFromDirectory */ public function testGetLibraryFromAltDirectory() { // Simple test of loading a library and checking if it exists $this->assertInstanceOf('Application\Library\TestGetLibraryFromAltDirectory', $this->libraries->get('TestGetLibraryFromAltDirectory', [], ['test'.DS.'libraries'.DS.'testGetLibraryFromAltDirectory'])); } /** * @expectedException FuzeWorks\Exception\LibraryException */ public function testGetLibraryFail() { $this->libraries->get('FailLoadLibrary'); } /** * @expectedException FuzeWorks\Exception\LibraryException */ public function testGetLibraryNoName() { $this->libraries->get(''); } /** * @expectedException FuzeWorks\Exception\LibraryException */ public function testGetLibraryNoClass() { $this->libraries->get('TestGetLibraryNoClass'); } public function testGetLibraryParametersFromConfig() { // Prepare the config file $libraryName = 'TestGetLibraryParametersFromConfig'; $libraryDir = 'test'.DS.'libraries'.DS.'testGetLibraryParametersFromConfig'; $config = Factory::getInstance()->config->getConfig(strtolower($libraryName), [$libraryDir]); // Load the library $lib = $this->libraries->get('TestGetLibraryParametersFromConfig'); $this->assertInstanceOf('Application\Library\TestGetLibraryParametersFromConfig', $lib); // And check the parameters $this->assertEquals(5, $lib->parameters['provided']); } /* ---------------------------------- Add libraries --------------------------------------------- */ public function testAddLibraryObject() { $this->libraries->addLibraryObject('TestAddLibraryObject', 5); $this->assertEquals(5, $this->libraries->get('TestAddLibraryObject')); } public function testAddLibraryClass() { require_once('test'.DS.'libraries'.DS.'testAddLibraryClass'.DS.'TestAddLibraryClass.php'); $this->libraries->addLibraryClass('LibraryClass', '\Custom\Spaces\TestAddLibraryClass'); $this->assertInstanceOf('\Custom\Spaces\TestAddLibraryClass', $this->libraries->get('LibraryClass')); } /** * @depends testAddLibraryClass * @expectedException \FuzeWorks\Exception\LibraryException */ public function testAddLibraryClassFail() { $this->libraries->addLibraryClass('LibraryClassFail', '\Case\Not\Exist'); } public function tearDown() { Factory::getInstance()->config->getConfig('main')->revert(); } }