-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathOptionsTest.php
More file actions
100 lines (82 loc) · 3.11 KB
/
OptionsTest.php
File metadata and controls
100 lines (82 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
namespace splitbrain\phpcli\tests;
class Options extends \splitbrain\phpcli\Options
{
public $args;
}
class OptionsTest extends \PHPUnit\Framework\TestCase
{
/**
* @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($option, $value, $argument);
$options->parseOptions();
$this->assertEquals($value, $options->getOpt('exclude'));
$this->assertEquals(array($argument), $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()
{
$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'));
}
function test_complex()
{
$options = new Options();
$options->registerOption('plugins', 'run on plugins only', 'p');
$options->registerCommand('status', 'display status info');
$options->registerOption('long', 'display long lines', 'l', false, 'status');
$options->args = array('-p', 'status', '--long', 'foo');
$options->parseOptions();
$this->assertEquals('status', $options->getCmd());
$this->assertTrue($options->getOpt('plugins'));
$this->assertTrue($options->getOpt('long'));
$this->assertEquals(array('foo'), $options->args);
}
function test_multiple()
{
$options = new Options();
$options->registerOption('multiple', 'this option can be specified multiple times', 'm', true, '', true);
$options->args = array('-m', 'first', '--multiple', 'second', '-m', 'third', '--multiple', 'fourth');
$options->parseOptions();
$this->assertEquals(array("first", "second", "third", "fourth"), $options->getOpt('multiple'));
}
function test_commandhelp()
{
$options = new Options();
$options->registerCommand('cmd', 'a command');
$this->assertStringContainsString('accepts a command as first parameter', $options->help());
$options->setCommandHelp('foooooobaar');
$this->assertStringNotContainsString('accepts a command as first parameter', $options->help());
$this->assertStringContainsString('foooooobaar', $options->help());
}
}