Skip to content

Commit d11dffc

Browse files
committed
Fix for issue described in PR #6
1 parent e156d36 commit d11dffc

4 files changed

Lines changed: 29 additions & 7 deletions

File tree

src/docopt.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,17 +489,18 @@ class Option extends LeafPattern
489489

490490
public function __construct($short=null, $long=null, $argcount=0, $value=false)
491491
{
492-
if ($argcount != 0 && $argcount != 1)
492+
if ($argcount != 0 && $argcount != 1) {
493493
throw new \InvalidArgumentException();
494+
}
494495

495496
$this->short = $short;
496497
$this->long = $long;
497498
$this->argcount = $argcount;
498499
$this->value = $value;
499500

500-
// Python checks "value is False". maybe we should check "$value === false"
501-
if (!$value && $argcount)
501+
if ($value === false && $argcount) {
502502
$this->value = null;
503+
}
503504
}
504505

505506
public static function parse($optionDescription)

test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
$suite = new PHPUnit_Framework_TestSuite();
2424
$suite->addTest(new PHPUnit_Framework_TestSuite('Docopt\Test\PythonPortedTest'));
2525
$suite->addTest(Docopt\Test\LanguageAgnosticTest::createSuite($pyTestFile));
26+
$suite->addTest(Docopt\Test\LanguageAgnosticTest::createSuite("$basePath/test/extra.docopt"));
2627

2728
$runner = new PHPUnit_TextUI_TestRunner();
2829
$runner->doRun($suite, array(

test/extra.docopt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
r"""Usage: prog [-a <foo>]
2+
3+
Options: -a <foo> An option [default: 0].
4+
5+
"""
6+
$ prog
7+
{"-a": "0"}
8+
9+
10+
r"""Usage: prog [-a <foo>]
11+
12+
Options: -a <foo> An option [default: ].
13+
14+
"""
15+
$ prog
16+
{"-a": ""}
17+

test/lib/LanguageAgnosticTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ class LanguageAgnosticTest implements \PHPUnit_Framework_Test, \PHPUnit_Framewor
55
{
66
public static function createSuite($testFile)
77
{
8-
if (!file_exists($testFile))
8+
if (!file_exists($testFile)) {
99
throw new \InvalidArgumentException("Test file $testFile does not exist");
10+
}
1011

1112
$suite = new \PHPUnit_Framework_TestSuite;
1213

@@ -37,23 +38,25 @@ public static function createSuite($testFile)
3738
$argv = isset($argx[1]) ? $argx[1] : "";
3839

3940
$tName = $name ? ($name.$nIdx) : 'unnamed'.$idx;
40-
$suite->addTest(new static($tName, $doc, $prog, $argv, $expect));
41+
$test = new static($tName, $doc, $prog, $argv, $expect);
42+
$suite->addTest($test);
4143
$idx++;
4244
}
4345
}
4446

4547
return $suite;
4648
}
47-
49+
4850
public function __construct($name, $doc, $prog, $argv, $expect)
4951
{
5052
$this->doc = $doc;
5153
$this->name = $name;
5254
$this->prog = $prog;
5355
$this->argv = $argv;
5456

55-
if ($expect == "user-error")
57+
if ($expect == "user-error") {
5658
$expect = array('user-error');
59+
}
5760

5861
$this->expect = $expect;
5962
}

0 commit comments

Comments
 (0)