FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Ensure php7.4 compatibility by usox · Pull Request #16 · splitbrain/php-cli · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .php  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 2 additions & 2 deletions src/Options.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,13 @@ public function parseOptions()
}

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

// long option
if (strlen($arg) > 1 && $arg{1} == '-') {
if (strlen($arg) > 1 && $arg[1] === '-') {
$arg = explode('=', substr($arg, 2), 2);
$opt = array_shift($arg);
$val = array_shift($arg);
Expand Down
43 changes: 27 additions & 16 deletions tests/OptionsTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,41 @@ class Options extends \splitbrain\phpcli\Options
class OptionsTest extends \PHPUnit_Framework_TestCase
{

function test_simpleshort()
{
/**
* @dataProvider optionDataProvider
*
* @param string $option
* @param string $value
* @param string $argument
*/
function test_optionvariants(
$option,
$value,
$argument
) {
$options = new Options();
$options->registerOption('exclude', 'exclude files', 'x', 'file');

$options->args = array('-x', 'foo', 'bang');
$options->args = array($option, $value, $argument);
$options->parseOptions();

$this->assertEquals('foo', $options->getOpt('exclude'));
$this->assertEquals(array('bang'), $options->args);
$this->assertEquals($value, $options->getOpt('exclude'));
$this->assertEquals(array($argument), $options->args);
$this->assertFalse($options->getOpt('nothing'));
}

function test_simplelong1()
{
$options = new Options();
$options->registerOption('exclude', 'exclude files', 'x', 'file');

$options->args = array('--exclude', 'foo', 'bang');
$options->parseOptions();

$this->assertEquals('foo', $options->getOpt('exclude'));
$this->assertEquals(array('bang'), $options->args);
$this->assertFalse($options->getOpt('nothing'));
/**
* @return array
*/
public function optionDataProvider() {
return array(
array('-x', 'foo', 'bang'),
array('--exclude', 'foo', 'bang'),
array('-x', 'foo-bar', 'bang'),
array('--exclude', 'foo-bar', 'bang'),
array('-x', 'foo', 'bang--bang'),
array('--exclude', 'foo', 'bang--bang'),
);
}

function test_simplelong2()
Expand Down

Back | FazBrowse Home | New Git URL