Navigation Menu

Skip to content

Commit

Permalink
Change to dataprovider for duplicate type setting test for NotEmpty v…
Browse files Browse the repository at this point in the history
…alidator
  • Loading branch information
David Stockton committed Feb 26, 2014
1 parent 0c0c19b commit 447a376
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 deletions tests/ZendTest/Validator/NotEmptyTest.php
Expand Up @@ -414,30 +414,44 @@ public function testStringNotation()
* Ensures that the validator follows expected behavior so if a string is specified more than once, it doesn't
* cause different validations to run
*
* @param string $string Array of string type values
* @param integer $expected Expected type setting value
*
* @return void
*
* @dataProvider duplicateStringSettingProvider
*/
public function testStringNotationWithDuplicate()
public function testStringNotationWithDuplicate($string, $expected)
{
$filter = new NotEmpty(
array(
// Should only count as 'boolean'
'type' => array('boolean', 'boolean')
)
);
$type = array($string, $string);
$this->validator->setType($type);

$this->assertFalse($filter->isValid(false));
$this->assertTrue($filter->isValid(true));
$this->assertTrue($filter->isValid(0));
$this->assertTrue($filter->isValid(1));
$this->assertTrue($filter->isValid((float) 0.0));
$this->assertTrue($filter->isValid((float) 1.0));
$this->assertTrue($filter->isValid(''));
$this->assertTrue($filter->isValid('abc'));
$this->assertTrue($filter->isValid('0'));
$this->assertTrue($filter->isValid('1'));
$this->assertTrue($filter->isValid(array()));
$this->assertTrue($filter->isValid(array('xxx')));
$this->assertTrue($filter->isValid(null));
$this->assertEquals($expected, $this->validator->getType());

This comment has been minimized.

Copy link
@Maks3w

Maks3w Feb 26, 2014

This don't test isValid method.

This comment has been minimized.

Copy link
@dstockto

dstockto Feb 26, 2014

Owner

All the other tests do test that. The issue was that the type was being set incorrectly if a string type was set more than once.

}

/**
* Data provider for testStringNotationWithDuplicate method. Provides a string which will be duplicated. The test
* ensures that setting a string value more than once only turns on the appropriate bit once
*
* @return array
*/
public function duplicateStringSettingProvider()
{
return array(
array('boolean', NotEmpty::BOOLEAN),
array('integer', NotEmpty::INTEGER),
array('float', NotEmpty::FLOAT),
array('string', NotEmpty::STRING),
array('zero', NotEmpty::ZERO),
array('array', NotEmpty::EMPTY_ARRAY),
array('null', NotEmpty::NULL),
array('php', NotEmpty::PHP),
array('space', NotEmpty::SPACE),
array('object', NotEmpty::OBJECT),
array('objectstring', NotEmpty::OBJECT_STRING),
array('objectcount', NotEmpty::OBJECT_COUNT),
array('all', NotEmpty::ALL),
);
}

/**
Expand Down

0 comments on commit 447a376

Please sign in to comment.