Skip to content

Commit

Permalink
Merge pull request #1 from aranw/master
Browse files Browse the repository at this point in the history
Updated tests
  • Loading branch information
hglattergotz committed Nov 25, 2015
2 parents c899dde + 3445381 commit f12c6b3
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/HGG/ParameterValidator/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private function handleUndefinedParameters()
if (1 == $leftover) {
$msg = 'The parameter \'%s\' is not valid';
} else {
$msg = 'The parameters \'%s\' are not valied';
$msg = 'The parameters \'%s\' are not valid';
}

throw new \Exception(sprintf($msg, implode('\', \'', array_keys($this->rawParams))));
Expand Down
81 changes: 78 additions & 3 deletions tests/HGG/ParameterValidator/Test/InputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,38 @@ protected function setUp()
protected function tearDown()
{}

/**
* @expectedException Exception
* @expectedExceptionMessage Parameter with name 'req-num' already exists!
*/
public function testParamterAlreadyExists()
{
$def = $this->def
->addParameter(
new NumberParameter(
'req-num',
Parameter::REQUIRED,
'This is a required numeric parameter',
'Some more details could go here'
)
);
}

public function testParameterGetters()
{
$numberParameter = new NumberParameter(
'req-num',
Parameter::REQUIRED,
'This is a required numeric parameter',
'Some more details could go here',
'RandomValidatorClass'
);

$this->assertEquals('This is a required numeric parameter', $numberParameter->getSummary());
$this->assertEquals('Some more details could go here', $numberParameter->getDescription());
$this->assertEquals('RandomValidatorClass', $numberParameter->getValidator());
}

public function testSunnyDay()
{
$parameters = array(
Expand Down Expand Up @@ -94,24 +126,68 @@ public function testOmitOptionalParameter()
$this->assertEquals($expected, $result);
}

/**
* @expectedException Exception
* @expectedExceptionMessage The required parameter 'req-num' is missing
*/
public function testOmitRequiredParameter()
{
$parameters = array(
'opt-txt' => 'Some text value'
);

$this->setExpectedException('Exception');
$input = new Input($parameters, $this->def);
}

/**
* @expectedException Exception
* @expectedExceptionMessage The required parameters 'req-num', 'req-num-2' are missing
*/
public function testOmitRequiredParameters()
{
$def = $this->def->addParameter(
new NumberParameter(
'req-num-2',
Parameter::REQUIRED,
'This is a required numeric parameter',
'Some more details could go here'
)
);

$parameters = array(
'opt-txt' => 'Some text value'
);

$input = new Input($parameters, $this->def);
}

/**
* @expectedException Exception
* @expectedExceptionMessage The parameter 'not-defined' is not valid
*/
public function testAddUndefinedParameter()
{
$parameters = array(
'req-num' => 1234,
'not-defined' => 12
);

$this->setExpectedException('Exception');
$input = new Input($parameters, $this->def);
}

/**
* @expectedException Exception
* @expectedExceptionMessage The parameters 'not-defined', 'not-defined-2', 'not-defined-3' are not valid
*/
public function testAddUndefinedParameters()
{
$parameters = array(
'req-num' => 1234,
'not-defined' => 12,
'not-defined-2' => 12,
'not-defined-3' => 12
);

$input = new Input($parameters, $this->def);
}

Expand Down Expand Up @@ -251,4 +327,3 @@ public function allFalseBooleanDataProvider()
return $result;
}
}

0 comments on commit f12c6b3

Please sign in to comment.