-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfixed in check required parameters
- Loading branch information
1 parent
5a55fe3
commit f8a0dd0
Showing
7 changed files
with
136 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -19,7 +19,6 @@ | |
*/ | ||
class CommandConfig | ||
{ | ||
|
||
/** | ||
* @var string | ||
*/ | ||
|
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
/** | ||
* Impero: Command manager | ||
* Copyright (c) NewClass (http://newclass.pl) | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the file LICENSE | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Copyright (c) NewClass (http://newclass.pl) | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
|
||
namespace Test\Impero; | ||
|
||
use Impero\CommandConfig; | ||
use Impero\InputStream; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Class CommandConfigTest | ||
* @author Michal Tomczak ([email protected]) | ||
*/ | ||
class CommandConfigTest extends TestCase | ||
{ | ||
|
||
/** | ||
* | ||
*/ | ||
public function testGetOption() | ||
{ | ||
$config = new CommandConfig(); | ||
$config->addOption('first','def',false); | ||
$option=$config->getOption('first'); | ||
$this->assertEquals('first', $option->getName()); | ||
$this->assertEquals('def', $option->getDefault()); | ||
$this->assertEquals(false, $option->isRequired()); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function testGetOptionUnknownOptionException() | ||
{ | ||
$this->expectExceptionMessage('Unknow option last'); | ||
$config = new CommandConfig(); | ||
$config->addOption('first','def',false); | ||
$option=$config->getOption('last'); | ||
} | ||
|
||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
/** | ||
* Impero: Command manager | ||
* Copyright (c) NewClass (http://newclass.pl) | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the file LICENSE | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Copyright (c) NewClass (http://newclass.pl) | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
|
||
namespace Test\Impero; | ||
|
||
use Impero\CommandConfig; | ||
use Impero\InputStream; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Class InputStreamTest | ||
* @author Michal Tomczak ([email protected]) | ||
*/ | ||
class InputStreamTest extends TestCase | ||
{ | ||
|
||
/** | ||
* | ||
*/ | ||
public function testParse() | ||
{ | ||
$config = new CommandConfig(); | ||
$config->addParameter('first') | ||
->addParameter('second_optional', null, false) | ||
->addParameter('last_default', true) | ||
->addOption('opt1') | ||
->addOption('opt2', null, false); | ||
|
||
$input = new InputStream([ | ||
'test', | ||
'-opt1="wow"' | ||
], $config); | ||
|
||
$this->assertEquals('test', $input->getValue('first')); | ||
$this->assertEquals(true, $input->getValue('last_default')); | ||
$this->assertEquals('wow', $input->getValue('opt1')); | ||
|
||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function testParseRequiredParameterException() | ||
{ | ||
$config = new CommandConfig(); | ||
$config->addParameter('first') | ||
->addParameter('second_optional', null, false) | ||
->addParameter('last_default', true) | ||
->addOption('opt1') | ||
->addOption('opt2', null, false); | ||
|
||
$this->expectExceptionMessage('Required parameter first'); | ||
$input = new InputStream([ | ||
'-opt1="wow"', | ||
'-opt2', | ||
'unknown' | ||
], $config); | ||
|
||
} | ||
} |