public function testAddOption() { $this->initializeOptions(); $definition = new InputDefinition(); $definition->addOption($this->foo); $this->assertEquals($definition->getOptions(), array('foo' => $this->foo), '->addOption() adds a InputOption object'); $definition->addOption($this->bar); $this->assertEquals($definition->getOptions(), array('foo' => $this->foo, 'bar' => $this->bar), '->addOption() adds a InputOption object'); try { $definition->addOption($this->foo2); $this->fail('->addOption() throws a Exception if the another option is already registered with the same name'); } catch (\Exception $e) { } try { $definition->addOption($this->foo1); $this->fail('->addOption() throws a Exception if the another option is already registered with the same shortcut'); } catch (\Exception $e) { } }
catch (\Exception $e) { $t->pass('->setOptions() clears all InputOption objects'); } // ->addOptions() $t->diag('->addOptions()'); $definition = new InputDefinition(array($foo)); $t->is($definition->getOptions(), array('foo' => $foo), '->addOptions() adds an array of InputOption objects'); $definition->addOptions(array($bar)); $t->is($definition->getOptions(), array('foo' => $foo, 'bar' => $bar), '->addOptions() does not clear existing InputOption objects'); // ->addOption() $t->diag('->addOption()'); $definition = new InputDefinition(); $definition->addOption($foo); $t->is($definition->getOptions(), array('foo' => $foo), '->addOption() adds a InputOption object'); $definition->addOption($bar); $t->is($definition->getOptions(), array('foo' => $foo, 'bar' => $bar), '->addOption() adds a InputOption object'); try { $definition->addOption($foo2); $t->fail('->addOption() throws a Exception if the another option is already registered with the same name'); } catch (\Exception $e) { $t->pass('->addOption() throws a Exception if the another option is already registered with the same name'); } try { $definition->addOption($foo1);
public function testAddOption() { $this->initializeOptions(); $definition = new InputDefinition(); $definition->addOption($this->foo); $this->assertEquals(array('foo' => $this->foo), $definition->getOptions(), '->addOption() adds a InputOption object'); $definition->addOption($this->bar); $this->assertEquals(array('foo' => $this->foo, 'bar' => $this->bar), $definition->getOptions(), '->addOption() adds a InputOption object'); try { $definition->addOption($this->foo2); $this->fail('->addOption() throws a Exception if the another option is already registered with the same name'); } catch (\Exception $e) { $this->assertInstanceOf('\\Exception', $e, '->addOption() throws a Exception if the another option is already registered with the same name'); $this->assertEquals('An option named "foo" already exist.', $e->getMessage()); } try { $definition->addOption($this->foo1); $this->fail('->addOption() throws a Exception if the another option is already registered with the same shortcut'); } catch (\Exception $e) { $this->assertInstanceOf('\\Exception', $e, '->addOption() throws a Exception if the another option is already registered with the same shortcut'); $this->assertEquals('An option with shortcut "f" already exist.', $e->getMessage()); } }