|
10 | 10 |
|
11 | 11 | namespace Lunr\Shadow\Tests; |
12 | 12 |
|
| 13 | +use UnexpectedValueException; |
| 14 | + |
13 | 15 | /** |
14 | 16 | * This class contains test methods for parse() in the LunrCliParser class. |
15 | 17 | * |
|
18 | 20 | class LunrCliParserParseTest extends LunrCliParserTest |
19 | 21 | { |
20 | 22 |
|
| 23 | + /** |
| 24 | + * Test that parsing with an invalid argv throws an exception. |
| 25 | + * |
| 26 | + * @covers Lunr\Shadow\LunrCliParser::parse |
| 27 | + */ |
| 28 | + public function testParseArgvWithArgvAsString(): void |
| 29 | + { |
| 30 | + $_SERVER['argv'] = 'script.php'; |
| 31 | + |
| 32 | + $this->expectException(UnexpectedValueException::class); |
| 33 | + $this->expectExceptionMessage('Command line arguments are not stored in an array!'); |
| 34 | + |
| 35 | + $value = $this->class->parse(); |
| 36 | + |
| 37 | + $this->assertArrayEmpty($value); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Test that parsing with an invalid argv throws an exception. |
| 42 | + * |
| 43 | + * @covers Lunr\Shadow\LunrCliParser::parse |
| 44 | + */ |
| 45 | + public function testParseArgvWithArgvAsAssociativeArray(): void |
| 46 | + { |
| 47 | + $_SERVER['argv'] = [ 1 => 'script.php' ]; |
| 48 | + |
| 49 | + $this->expectException(UnexpectedValueException::class); |
| 50 | + $this->expectExceptionMessage('Command line arguments are not stored as a list!'); |
| 51 | + |
| 52 | + $value = $this->class->parse(); |
| 53 | + |
| 54 | + $this->assertArrayEmpty($value); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Test that parsing with an invalid argv throws an exception. |
| 59 | + * |
| 60 | + * @covers Lunr\Shadow\LunrCliParser::parse |
| 61 | + */ |
| 62 | + public function testParseArgvWithArgvAsIntArray(): void |
| 63 | + { |
| 64 | + $_SERVER['argv'] = [ 1, 'script.php' ]; |
| 65 | + |
| 66 | + $this->expectException(UnexpectedValueException::class); |
| 67 | + $this->expectExceptionMessage('Command line argument 0 is not a string!'); |
| 68 | + |
| 69 | + $value = $this->class->parse(); |
| 70 | + |
| 71 | + $this->assertArrayEmpty($value); |
| 72 | + } |
| 73 | + |
21 | 74 | /** |
22 | 75 | * Test that parsing no arguments returns an empty array. |
23 | 76 | * |
|
0 commit comments