Skip to content

Commit fb4f888

Browse files
authored
Merge pull request #16 from usox/php74-compat
Ensure php7.4 compatibility
2 parents b7be372 + c018124 commit fb4f888

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

src/Options.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,13 @@ public function parseOptions()
216216
}
217217

218218
// first non-option
219-
if ($arg{0} != '-') {
219+
if ($arg[0] != '-') {
220220
$non_opts = array_merge($non_opts, array_slice($this->args, $i));
221221
break;
222222
}
223223

224224
// long option
225-
if (strlen($arg) > 1 && $arg{1} == '-') {
225+
if (strlen($arg) > 1 && $arg[1] === '-') {
226226
$arg = explode('=', substr($arg, 2), 2);
227227
$opt = array_shift($arg);
228228
$val = array_shift($arg);

tests/OptionsTest.php

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,41 @@ class Options extends \splitbrain\phpcli\Options
1111
class OptionsTest extends \PHPUnit_Framework_TestCase
1212
{
1313

14-
function test_simpleshort()
15-
{
14+
/**
15+
* @dataProvider optionDataProvider
16+
*
17+
* @param string $option
18+
* @param string $value
19+
* @param string $argument
20+
*/
21+
function test_optionvariants(
22+
$option,
23+
$value,
24+
$argument
25+
) {
1626
$options = new Options();
1727
$options->registerOption('exclude', 'exclude files', 'x', 'file');
1828

19-
$options->args = array('-x', 'foo', 'bang');
29+
$options->args = array($option, $value, $argument);
2030
$options->parseOptions();
2131

22-
$this->assertEquals('foo', $options->getOpt('exclude'));
23-
$this->assertEquals(array('bang'), $options->args);
32+
$this->assertEquals($value, $options->getOpt('exclude'));
33+
$this->assertEquals(array($argument), $options->args);
2434
$this->assertFalse($options->getOpt('nothing'));
2535
}
2636

27-
function test_simplelong1()
28-
{
29-
$options = new Options();
30-
$options->registerOption('exclude', 'exclude files', 'x', 'file');
31-
32-
$options->args = array('--exclude', 'foo', 'bang');
33-
$options->parseOptions();
34-
35-
$this->assertEquals('foo', $options->getOpt('exclude'));
36-
$this->assertEquals(array('bang'), $options->args);
37-
$this->assertFalse($options->getOpt('nothing'));
37+
/**
38+
* @return array
39+
*/
40+
public function optionDataProvider() {
41+
return array(
42+
array('-x', 'foo', 'bang'),
43+
array('--exclude', 'foo', 'bang'),
44+
array('-x', 'foo-bar', 'bang'),
45+
array('--exclude', 'foo-bar', 'bang'),
46+
array('-x', 'foo', 'bang--bang'),
47+
array('--exclude', 'foo', 'bang--bang'),
48+
);
3849
}
3950

4051
function test_simplelong2()

0 commit comments

Comments
 (0)