forked from splitbrain/php-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptionsTest.php
More file actions
65 lines (48 loc) · 1.88 KB
/
Copy pathOptionsTest.php
File metadata and controls
65 lines (48 loc) · 1.88 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
<?php
namespace splitbrain\phpcli\tests;
class Options extends \splitbrain\phpcli\Options {
public $args;
}
class OptionsTest extends \PHPUnit\Framework\TestCase {
function test_simpleshort() :void {
$options = new Options();
$options->registerOption( 'exclude', 'exclude files', 'x', 'file' );
$options->args = [ '-x', 'foo', 'bang' ];
$options->parseOptions();
$this->assertEquals( 'foo', $options->getOpt( 'exclude' ) );
$this->assertEquals( [ 'bang' ], $options->args );
$this->assertFalse( $options->getOpt( 'nothing' ) );
}
function test_simplelong1() :void {
$options = new Options();
$options->registerOption( 'exclude', 'exclude files', 'x', 'file' );
$options->args = [ '--exclude', 'foo', 'bang' ];
$options->parseOptions();
$this->assertEquals( 'foo', $options->getOpt( 'exclude' ) );
$this->assertEquals( [ 'bang' ], $options->args );
$this->assertFalse( $options->getOpt( 'nothing' ) );
}
function test_simplelong2() :void {
$options = new Options();
$options->registerOption( 'exclude', 'exclude files', 'x', 'file' );
$options->args = [ '--exclude=foo', 'bang' ];
$options->parseOptions();
$this->assertEquals( 'foo', $options->getOpt( 'exclude' ) );
$this->assertEquals( [ 'bang' ], $options->args );
$this->assertFalse( $options->getOpt( 'nothing' ) );
}
function test_complex() :void {
$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 = [ '-p', 'status', '--long', 'foo' ];
$options->parseOptions();
$this->assertEquals( 'status', $options->getCmd() );
$this->assertTrue( $options->getOpt( 'plugins' ) );
$this->assertTrue( $options->getOpt( 'long' ) );
$this->assertEquals( [ 'foo' ], $options->args );
}
}