Added PhpUnit tests
This commit is contained in:
parent
7d1c11c051
commit
81ab2fdf77
2 changed files with 75 additions and 0 deletions
5
.idea/php.xml
generated
5
.idea/php.xml
generated
|
@ -20,6 +20,11 @@
|
||||||
<component name="PhpStanOptionsConfiguration">
|
<component name="PhpStanOptionsConfiguration">
|
||||||
<option name="transferred" value="true" />
|
<option name="transferred" value="true" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="PhpUnit">
|
||||||
|
<phpunit_settings>
|
||||||
|
<PhpUnitSettings load_method="PHPUNIT_PHAR" custom_loader_path="" phpunit_phar_path="$USER_HOME$/phpunit.phar" />
|
||||||
|
</phpunit_settings>
|
||||||
|
</component>
|
||||||
<component name="PsalmOptionsConfiguration">
|
<component name="PsalmOptionsConfiguration">
|
||||||
<option name="transferred" value="true" />
|
<option name="transferred" value="true" />
|
||||||
</component>
|
</component>
|
||||||
|
|
70
tests/OptsLib/ParseTest.php
Normal file
70
tests/OptsLib/ParseTest.php
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace OptsLib;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class ParseTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Testing parseArgument method when input is a string type, also testing different flag pattern
|
||||||
|
*/
|
||||||
|
public function testParseArgumentWithStringInput()
|
||||||
|
{
|
||||||
|
$input = '--flag1=value1 -f value2 unmatched_string';
|
||||||
|
$expected_result = [
|
||||||
|
'flag1' => 'value1',
|
||||||
|
'f' => 'value2',
|
||||||
|
'unmatched_string' => true,
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->assertEquals($expected_result, Parse::parseArgument($input));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testing parseArgument method when input is an array type
|
||||||
|
*/
|
||||||
|
public function testParseArgumentWithArrayInput()
|
||||||
|
{
|
||||||
|
// Array argument will be transformed into '--flag1 value1 "-"f" value2" unmatched_string'
|
||||||
|
$input = ['--flag1', 'value1', '-', 'f', 'value2', 'unmatched_string'];
|
||||||
|
$expected_result = [
|
||||||
|
'flag1' => 'value1',
|
||||||
|
'unmatched_string' => true,
|
||||||
|
'f' => true,
|
||||||
|
'value2' => true
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->assertEquals($expected_result, Parse::parseArgument($input));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testing parseArgument method when input contains escaped quotes in a string argument
|
||||||
|
*/
|
||||||
|
public function testParseArgumentWithEscapedQuotes()
|
||||||
|
{
|
||||||
|
$input = "--flag1=\"value1 with some \\\"escaped quotes\\\"\" -f 'value2 with some \\'escaped quotes\\'' unmatched_string";
|
||||||
|
$expected_result = [
|
||||||
|
'flag1' => 'value1 with some "escaped quotes"',
|
||||||
|
'f' => 'value2 with some \'escaped quotes\'',
|
||||||
|
'unmatched_string' => true,
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->assertEquals($expected_result, Parse::parseArgument($input));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testing parseArgument method only takes maximum number of arguments specified
|
||||||
|
*/
|
||||||
|
public function testParseArgumentWithMaxArguments()
|
||||||
|
{
|
||||||
|
$input = '--flag1=value1 -f value2 unmatched_string1 unmatched_string2';
|
||||||
|
$expected_result = [
|
||||||
|
'flag1' => 'value1',
|
||||||
|
'f' => 'value2',
|
||||||
|
'unmatched_string1' => true
|
||||||
|
]; // It should only parse maximum 3 arguments
|
||||||
|
|
||||||
|
$this->assertEquals($expected_result, Parse::parseArgument($input, 2));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue