public function testErrors() { $helper = new CliUserInterfaceHelper('test script', 'test.php'); try { $helper->getUsageOutput(); $this->fail('No Exception is thrown when getting usage without any defined usages'); } catch (Exception $e) { } $testUsage = $helper->addUsage('test'); $helper->addSwitch('a', 'test', 'Test', null); try { $helper->addSwitch(null, null, 'Test', null); $this->fail('No Exception is thrown when adding a switch with neither short nor long name'); } catch (Exception $e) { } try { $helper->addSwitch('a', null, 'Test', null); $this->fail('No exception is thrown when adding a duplicate short switch'); } catch (Exception $e) { } try { $helper->addSwitch(null, 'test', 'Test', null); $this->fail('No exception is thrown when adding a duplicate long switch'); } catch (Exception $e) { } try { $helper->addSwitch('b', null, 'test', $testUsage + 1); $this->fail('No exception is thrown when adding a switch to an invalid usage'); } catch (Exception $e) { } try { $helper->addSwitch('c', null, 'test', array($testUsage, $testUsage + 1)); $this->fail('No exception is thrown when adding a switch to an invalid usage with an array'); } catch (Exception $e) { } }
/** * Sets the switches used by the script * * @return void */ protected function prepareSwitches() { $this->usageIndexes[self::HELP_USAGE] = $this->cliHelper->addUsage('Help'); $this->cliHelper->addSwitch(null, 'help', 'Shows the help', $this->usageIndexes[self::HELP_USAGE]); }