|
@@ -268,42 +268,72 @@ class Zend_Console_GetoptTest extends PHPUnit_Framework_TestCase
|
|
|
unset($opts->a);
|
|
unset($opts->a);
|
|
|
$this->assertFalse(isset($opts->a));
|
|
$this->assertFalse(isset($opts->a));
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @group GH-377
|
|
|
|
|
+ */
|
|
|
public function testVerifyRequiredArgument()
|
|
public function testVerifyRequiredArgument()
|
|
|
{
|
|
{
|
|
|
- $opts = new Zend_Console_Getopt(array('apple|a=s' => "First required argument"));
|
|
|
|
|
- try {
|
|
|
|
|
|
|
+ $opts = new Zend_Console_Getopt(
|
|
|
|
|
+ array('apple|a=s' => "First required argument")
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
$opts->parse();
|
|
$opts->parse();
|
|
|
$opts->checkRequiredArguments();
|
|
$opts->checkRequiredArguments();
|
|
|
$this->fail('Expected to catch a Zend_Console_Getopt_Exception');
|
|
$this->fail('Expected to catch a Zend_Console_Getopt_Exception');
|
|
|
|
|
+ } catch (Zend_Exception $e) {
|
|
|
|
|
+ $this->assertTrue(
|
|
|
|
|
+ $e instanceof Zend_Console_Getopt_Exception,
|
|
|
|
|
+ 'Expected Zend_Console_Getopt_Exception, got ' . get_class($e)
|
|
|
|
|
+ );
|
|
|
|
|
+ $this->assertEquals(
|
|
|
|
|
+ 'Option "a" requires a parameter.', $e->getMessage()
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
- catch (Zend_Exception $e){
|
|
|
|
|
- $this->assertTrue($e instanceof Zend_Console_Getopt_Exception,
|
|
|
|
|
- 'Expected Zend_Console_Getopt_Exception, got '. get_class($e));
|
|
|
|
|
- $this->assertEquals('Option "a" requires a parameter.' , $e->getMessage());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- $opts->addArguments(array( "-a", "apple") );
|
|
|
|
|
|
|
+
|
|
|
|
|
+ $opts->addArguments(
|
|
|
|
|
+ array(
|
|
|
|
|
+ "-a",
|
|
|
|
|
+ "apple"
|
|
|
|
|
+ )
|
|
|
|
|
+ );
|
|
|
$opts->parse();
|
|
$opts->parse();
|
|
|
$opts->checkRequiredArguments();//-> no Exception here
|
|
$opts->checkRequiredArguments();//-> no Exception here
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @group GH-377
|
|
|
|
|
+ */
|
|
|
public function testEmptyRequiredOption()
|
|
public function testEmptyRequiredOption()
|
|
|
- {
|
|
|
|
|
- $opts = new Zend_Console_Getopt(array(
|
|
|
|
|
- 'apple|a=s' =>"First required argument",
|
|
|
|
|
- 'banana|b=i' =>"Second required argument"
|
|
|
|
|
- ));
|
|
|
|
|
- $opts->addArguments(array("-a","-b","123"));
|
|
|
|
|
- try {
|
|
|
|
|
|
|
+ {
|
|
|
|
|
+ $opts = new Zend_Console_Getopt(
|
|
|
|
|
+ array(
|
|
|
|
|
+ 'apple|a=s' => "First required argument",
|
|
|
|
|
+ 'banana|b=i' => "Second required argument"
|
|
|
|
|
+ )
|
|
|
|
|
+ );
|
|
|
|
|
+ $opts->addArguments(
|
|
|
|
|
+ array(
|
|
|
|
|
+ "-a",
|
|
|
|
|
+ "-b",
|
|
|
|
|
+ "123"
|
|
|
|
|
+ )
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
$opts->parse();
|
|
$opts->parse();
|
|
|
$opts->checkRequiredArguments();
|
|
$opts->checkRequiredArguments();
|
|
|
- $this->fail('Expected to catch a Zend_Console_Getopt_Exception');
|
|
|
|
|
- } catch (Zend_Exception $e) {
|
|
|
|
|
- $this->assertTrue($e instanceof Zend_Console_Getopt_Exception,
|
|
|
|
|
- 'Expected Zend_Console_Getopt_Exception, got '. get_class($e));
|
|
|
|
|
- $this->assertEquals('Option "a" requires a parameter.' , $e->getMessage());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ $this->fail('Expected to catch a Zend_Console_Getopt_Exception');
|
|
|
|
|
+ } catch (Zend_Exception $e) {
|
|
|
|
|
+ $this->assertTrue(
|
|
|
|
|
+ $e instanceof Zend_Console_Getopt_Exception,
|
|
|
|
|
+ 'Expected Zend_Console_Getopt_Exception, got ' . get_class($e)
|
|
|
|
|
+ );
|
|
|
|
|
+ $this->assertEquals(
|
|
|
|
|
+ 'Option "a" requires a parameter.', $e->getMessage()
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|