-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a583ef8
commit 3e16c07
Showing
3 changed files
with
169 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,20 @@ | |
|
||
use HGG\ParameterValidator\Parameter\Validator\TextValidator; | ||
|
||
/** | ||
* TextParameter | ||
* | ||
* @uses Parameter | ||
* @author Henning Glatter-Götz <[email protected]> | ||
*/ | ||
class TextParameter extends Parameter | ||
{ | ||
/** | ||
* getDefaultValidator | ||
* | ||
* @access protected | ||
* @return void | ||
*/ | ||
protected function getDefaultValidator() | ||
{ | ||
return new TextValidator(); | ||
|
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 |
---|---|---|
|
@@ -5,16 +5,34 @@ | |
use HGG\ParameterValidator\Parameter\Parameter; | ||
use HGG\ParameterValidator\Parameter\NumberParameter; | ||
use HGG\ParameterValidator\Parameter\TextParameter; | ||
use HGG\ParameterValidator\Parameter\TextArrayParameter; | ||
use HGG\ParameterValidator\Parameter\DateParameter; | ||
use HGG\ParameterValidator\Parameter\DatetimeParameter; | ||
use HGG\ParameterValidator\Parameter\BooleanParameter; | ||
use HGG\ParameterValidator\ParameterDefinition; | ||
use HGG\ParameterValidator\Input; | ||
|
||
/** | ||
* InputTest | ||
* | ||
* @author Henning Glatter-Götz <[email protected]> | ||
*/ | ||
class InputTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* def | ||
* | ||
* @var mixed | ||
* @access protected | ||
*/ | ||
protected $def; | ||
|
||
/** | ||
* setUp | ||
* | ||
* @access protected | ||
* @return void | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->def = new ParameterDefinition(); | ||
|
@@ -35,6 +53,14 @@ protected function setUp() | |
'Some more details could go here' | ||
) | ||
) | ||
->addParameter( | ||
new TextParameter( | ||
'opt-txt-array', | ||
Parameter::OPTIONAL, | ||
'This is an optional text array parameter', | ||
'Some more details could go here' | ||
) | ||
) | ||
->addParameter( | ||
new DateParameter( | ||
'opt-date', | ||
|
@@ -61,12 +87,23 @@ protected function setUp() | |
); | ||
} | ||
|
||
/** | ||
* tearDown | ||
* | ||
* @access protected | ||
* @return void | ||
*/ | ||
protected function tearDown() | ||
{} | ||
|
||
/** | ||
* testParamterAlreadyExists | ||
* | ||
* @expectedException Exception | ||
* @expectedExceptionMessage Parameter with name 'req-num' already exists! | ||
* | ||
* @access public | ||
* @return void | ||
*/ | ||
public function testParamterAlreadyExists() | ||
{ | ||
|
@@ -81,6 +118,12 @@ public function testParamterAlreadyExists() | |
); | ||
} | ||
|
||
/** | ||
* testParameterGetters | ||
* | ||
* @access public | ||
* @return void | ||
*/ | ||
public function testParameterGetters() | ||
{ | ||
$numberParameter = new NumberParameter( | ||
|
@@ -96,14 +139,21 @@ public function testParameterGetters() | |
$this->assertEquals('RandomValidatorClass', $numberParameter->getValidator()); | ||
} | ||
|
||
/** | ||
* testSunnyDay | ||
* | ||
* @access public | ||
* @return void | ||
*/ | ||
public function testSunnyDay() | ||
{ | ||
$parameters = array( | ||
'req-num' => 1234, | ||
'opt-txt' => 'Some text value', | ||
'opt-date' => '2000-01-01', | ||
'opt-datetime' => '2000-01-01 23:00:00', | ||
'opt-bool' => true | ||
'req-num' => 1234, | ||
'opt-txt' => 'Some text value', | ||
'opt-txt-array' => array('type' => 'Some text value on index 0'), | ||
'opt-date' => '2000-01-01', | ||
'opt-datetime' => '2000-01-01 23:00:00', | ||
'opt-bool' => true | ||
); | ||
|
||
$input = new Input($parameters, $this->def); | ||
|
@@ -113,6 +163,12 @@ public function testSunnyDay() | |
$this->assertEquals($expected, $result); | ||
} | ||
|
||
/** | ||
* testOmitOptionalParameter | ||
* | ||
* @access public | ||
* @return void | ||
*/ | ||
public function testOmitOptionalParameter() | ||
{ | ||
$parameters = array( | ||
|
@@ -127,8 +183,13 @@ public function testOmitOptionalParameter() | |
} | ||
|
||
/** | ||
* testOmitRequiredParameter | ||
* | ||
* @expectedException Exception | ||
* @expectedExceptionMessage The required parameter 'req-num' is missing | ||
* | ||
* @access public | ||
* @return void | ||
*/ | ||
public function testOmitRequiredParameter() | ||
{ | ||
|
@@ -140,8 +201,13 @@ public function testOmitRequiredParameter() | |
} | ||
|
||
/** | ||
* testOmitRequiredParameters | ||
* | ||
* @expectedException Exception | ||
* @expectedExceptionMessage The required parameters 'req-num', 'req-num-2' are missing | ||
* | ||
* @access public | ||
* @return void | ||
*/ | ||
public function testOmitRequiredParameters() | ||
{ | ||
|
@@ -162,8 +228,13 @@ public function testOmitRequiredParameters() | |
} | ||
|
||
/** | ||
* testAddUndefinedParameter | ||
* | ||
* @expectedException Exception | ||
* @expectedExceptionMessage The parameter 'not-defined' is not valid | ||
* | ||
* @access public | ||
* @return void | ||
*/ | ||
public function testAddUndefinedParameter() | ||
{ | ||
|
@@ -176,8 +247,13 @@ public function testAddUndefinedParameter() | |
} | ||
|
||
/** | ||
* testAddUndefinedParameters | ||
* | ||
* @expectedException Exception | ||
* @expectedExceptionMessage The parameters 'not-defined', 'not-defined-2', 'not-defined-3' are not valid | ||
* | ||
* @access public | ||
* @return void | ||
*/ | ||
public function testAddUndefinedParameters() | ||
{ | ||
|
@@ -191,62 +267,103 @@ public function testAddUndefinedParameters() | |
$input = new Input($parameters, $this->def); | ||
} | ||
|
||
/** | ||
* testIncorrectParameterTypeNumber | ||
* | ||
* @expectedException Exception | ||
* | ||
* @access public | ||
* @return void | ||
*/ | ||
public function testIncorrectParameterTypeNumber() | ||
{ | ||
$parameters = array( | ||
'req-num' => 'this-is-not-a-number' | ||
); | ||
|
||
$this->setExpectedException('Exception'); | ||
$input = new Input($parameters, $this->def); | ||
} | ||
|
||
/** | ||
* testIncorrectParameterTypeText | ||
* | ||
* @expectedException Exception | ||
* | ||
* @access public | ||
* @return void | ||
*/ | ||
public function testIncorrectParameterTypeText() | ||
{ | ||
$parameters = array( | ||
'req-num' => 1234, | ||
'opt-txt' => true | ||
); | ||
|
||
$this->setExpectedException('Exception'); | ||
$input = new Input($parameters, $this->def); | ||
} | ||
|
||
/** | ||
* testIncorrectParameterTypeDate | ||
* | ||
* @expectedException Exception | ||
* | ||
* @access public | ||
* @return void | ||
*/ | ||
public function testIncorrectParameterTypeDate() | ||
{ | ||
$parameters = array( | ||
'req-num' => 1234, | ||
'opt-date' => 'this is not a date' | ||
); | ||
|
||
$this->setExpectedException('Exception'); | ||
$input = new Input($parameters, $this->def); | ||
} | ||
|
||
/** | ||
* testIncorrectParameterTypeDateTime | ||
* | ||
* @expectedException Exception | ||
* | ||
* @access public | ||
* @return void | ||
*/ | ||
public function testIncorrectParameterTypeDateTime() | ||
{ | ||
$parameters = array( | ||
'req-num' => 1234, | ||
'opt-datetime' => 'this is not a datetime' | ||
); | ||
|
||
$this->setExpectedException('Exception'); | ||
$input = new Input($parameters, $this->def); | ||
} | ||
|
||
/** | ||
* testIncorrectParameterTypeBoolean | ||
* | ||
* @expectedException Exception | ||
* | ||
* @access public | ||
* @return void | ||
*/ | ||
public function testIncorrectParameterTypeBoolean() | ||
{ | ||
$parameters = array( | ||
'req-num' => 1234, | ||
'opt-bool' => 'this is not a boolean' | ||
); | ||
|
||
$this->setExpectedException('Exception'); | ||
$input = new Input($parameters, $this->def); | ||
} | ||
|
||
/** | ||
* testAllTrueBooleanPrameterValues | ||
* | ||
* @dataProvider allTrueBooleanDataProvider | ||
* | ||
* @param mixed $parameters | ||
* @access public | ||
* @return void | ||
*/ | ||
public function testAllTrueBooleanPrameterValues($parameters) | ||
{ | ||
|
@@ -264,6 +381,12 @@ public function testAllTrueBooleanPrameterValues($parameters) | |
$this->assertEquals($expected, $result); | ||
} | ||
|
||
/** | ||
* allTrueBooleanDataProvider | ||
* | ||
* @access public | ||
* @return void | ||
*/ | ||
public function allTrueBooleanDataProvider() | ||
{ | ||
$data = array( | ||
|
@@ -287,7 +410,13 @@ public function allTrueBooleanDataProvider() | |
} | ||
|
||
/** | ||
* testAllFalseBooleanPrameterValues | ||
* | ||
* @dataProvider allFalseBooleanDataProvider | ||
* | ||
* @param mixed $parameters | ||
* @access public | ||
* @return void | ||
*/ | ||
public function testAllFalseBooleanPrameterValues($parameters) | ||
{ | ||
|
@@ -305,6 +434,12 @@ public function testAllFalseBooleanPrameterValues($parameters) | |
$this->assertEquals($expected, $result); | ||
} | ||
|
||
/** | ||
* allFalseBooleanDataProvider | ||
* | ||
* @access public | ||
* @return void | ||
*/ | ||
public function allFalseBooleanDataProvider() | ||
{ | ||
$data = array( | ||
|