protected function loadPhixCommands(Context $context, ParsedSwitches $ParsedSwitches) { // create something to find the commands $commandsFinder = new CommandsFinder(); // seed the commandsFinder with a list of where to look // if the user has given us any hints if ($ParsedSwitches->testHasSwitch("include")) { $switch = $ParsedSwitches->getSwitch("include"); $args = $ParsedSwitches->getArgsForSwitch("include"); foreach ($args as $path) { $commandsFinder->addFolderToSearch($path); } } // alright, let's thrash that hard disk // hope you have an SSD ;-) $commandsList = $commandsFinder->findCommands(); // all done return $commandsList; }
public function testCanGetSwitchByName() { // define the options we are expecting $expectedOptions = new DefinedSwitches(); // create the switches to add $switchName1 = 'fred'; $switchDesc1 = 'trout'; $expectedOptions->addSwitch($switchName1, $switchDesc1); $switch1 = $expectedOptions->getSwitchByName($switchName1); $switchName2 = 'harry'; $switchDesc2 = 'salmon'; $expectedOptions->addSwitch($switchName2, $switchDesc2); $switch2 = $expectedOptions->getSwitchByName($switchName2); // create the ParsedSwitches object $ParsedSwitches = new ParsedSwitches($expectedOptions); $ParsedSwitches->addSwitch($expectedOptions, $switchName1); $ParsedSwitches->addSwitch($expectedOptions, $switchName2); // did it work? $retrievedSwitch1 = $ParsedSwitches->getSwitch($switchName1); $retrievedSwitch2 = $ParsedSwitches->getSwitch($switchName2); $this->assertTrue($retrievedSwitch1 instanceof ParsedSwitch); $this->assertEquals($switch1->name, $retrievedSwitch1->name); $this->assertSame($switch1, $retrievedSwitch1->definition); $this->assertTrue($retrievedSwitch2 instanceof ParsedSwitch); $this->assertEquals($switch2->name, $retrievedSwitch2->name); $this->assertSame($switch2, $retrievedSwitch2->definition); // and if the switch is not there? $caughtException = false; try { $ParsedSwitches->getSwitch('notdefined'); } catch (\Exception $e) { $caughtException = true; } $this->assertTrue($caughtException); }