[Validator] Improved test coverage of CollectionValidator and reduced test code duplication
This commit is contained in:
parent
509c7bfb5b
commit
e6e3da5063
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Tests\Component\Validator\Constraints;
|
||||||
|
|
||||||
|
class CollectionValidatorArrayObjectTest extends CollectionValidatorTest
|
||||||
|
{
|
||||||
|
public function prepareTestData(array $contents)
|
||||||
|
{
|
||||||
|
return new \ArrayObject($contents);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Tests\Component\Validator\Constraints;
|
||||||
|
|
||||||
|
class CollectionValidatorArrayTest extends CollectionValidatorTest
|
||||||
|
{
|
||||||
|
public function prepareTestData(array $contents)
|
||||||
|
{
|
||||||
|
return $contents;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Tests\Component\Validator\Constraints;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is a hand written simplified version of PHP native `ArrayObject`
|
||||||
|
* class, to show that it behaves different than PHP native implementation.
|
||||||
|
*/
|
||||||
|
class CustomArrayObject implements \ArrayAccess, \IteratorAggregate, \Countable, \Serializable
|
||||||
|
{
|
||||||
|
private $array;
|
||||||
|
|
||||||
|
public function __construct(array $array = null)
|
||||||
|
{
|
||||||
|
$this->array = (array) ($array ?: array());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function offsetExists($offset)
|
||||||
|
{
|
||||||
|
return array_key_exists($offset, $this->array);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function offsetGet($offset)
|
||||||
|
{
|
||||||
|
return $this->array[$offset];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function offsetSet($offset, $value)
|
||||||
|
{
|
||||||
|
if (null === $offset) {
|
||||||
|
$this->array[] = $value;
|
||||||
|
} else {
|
||||||
|
$this->array[$offset] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function offsetUnset($offset)
|
||||||
|
{
|
||||||
|
if (array_key_exists($offset, $this->array)) {
|
||||||
|
unset($this->array[$offset]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getIterator()
|
||||||
|
{
|
||||||
|
return new \ArrayIterator($this->array);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function count()
|
||||||
|
{
|
||||||
|
return count($this->array);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function serialize()
|
||||||
|
{
|
||||||
|
return serialize($this->array);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function unserialize($serialized)
|
||||||
|
{
|
||||||
|
$this->array = (array) unserialize((string) $serialized);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class CollectionValidatorCustomArrayObjectTest extends CollectionValidatorTest
|
||||||
|
{
|
||||||
|
public function prepareTestData(array $contents)
|
||||||
|
{
|
||||||
|
return new CustomArrayObject($contents);
|
||||||
|
}
|
||||||
|
}
|
@ -20,67 +20,7 @@ use Symfony\Component\Validator\Constraints\Collection\Optional;
|
|||||||
use Symfony\Component\Validator\Constraints\Collection;
|
use Symfony\Component\Validator\Constraints\Collection;
|
||||||
use Symfony\Component\Validator\Constraints\CollectionValidator;
|
use Symfony\Component\Validator\Constraints\CollectionValidator;
|
||||||
|
|
||||||
/**
|
abstract class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
|
||||||
* This class is a hand written simplified version of PHP native `ArrayObject`
|
|
||||||
* class, to show that it behaves different than PHP native implementation.
|
|
||||||
*/
|
|
||||||
class TestArrayObject implements \ArrayAccess, \IteratorAggregate, \Countable, \Serializable
|
|
||||||
{
|
|
||||||
private $array;
|
|
||||||
|
|
||||||
public function __construct(array $array = null)
|
|
||||||
{
|
|
||||||
$this->array = (array) ($array ?: array());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function offsetExists($offset)
|
|
||||||
{
|
|
||||||
return array_key_exists($offset, $this->array);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function offsetGet($offset)
|
|
||||||
{
|
|
||||||
return $this->array[$offset];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function offsetSet($offset, $value)
|
|
||||||
{
|
|
||||||
if (null === $offset) {
|
|
||||||
$this->array[] = $value;
|
|
||||||
} else {
|
|
||||||
$this->array[$offset] = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function offsetUnset($offset)
|
|
||||||
{
|
|
||||||
if (array_key_exists($offset, $this->array)) {
|
|
||||||
unset($this->array[$offset]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getIterator()
|
|
||||||
{
|
|
||||||
return new \ArrayIterator($this->array);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function count()
|
|
||||||
{
|
|
||||||
return count($this->array);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function serialize()
|
|
||||||
{
|
|
||||||
return serialize($this->array);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function unserialize($serialized)
|
|
||||||
{
|
|
||||||
$this->array = (array) unserialize((string) $serialized);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
|
|
||||||
{
|
{
|
||||||
protected $validator;
|
protected $validator;
|
||||||
protected $walker;
|
protected $walker;
|
||||||
@ -104,6 +44,8 @@ class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->context = null;
|
$this->context = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract protected function prepareTestData(array $contents);
|
||||||
|
|
||||||
public function testNullIsValid()
|
public function testNullIsValid()
|
||||||
{
|
{
|
||||||
$this->assertTrue($this->validator->isValid(null, new Collection(array('fields' => array(
|
$this->assertTrue($this->validator->isValid(null, new Collection(array('fields' => array(
|
||||||
@ -113,13 +55,9 @@ class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testFieldsAsDefaultOption()
|
public function testFieldsAsDefaultOption()
|
||||||
{
|
{
|
||||||
$this->assertTrue($this->validator->isValid(array('foo' => 'foobar'), new Collection(array(
|
$data = $this->prepareTestData(array('foo' => 'foobar'));
|
||||||
'foo' => new Min(4),
|
|
||||||
))));
|
$this->assertTrue($this->validator->isValid($data, new Collection(array(
|
||||||
$this->assertTrue($this->validator->isValid(new \ArrayObject(array('foo' => 'foobar')), new Collection(array(
|
|
||||||
'foo' => new Min(4),
|
|
||||||
))));
|
|
||||||
$this->assertTrue($this->validator->isValid(new TestArrayObject(array('foo' => 'foobar')), new Collection(array(
|
|
||||||
'foo' => new Min(4),
|
'foo' => new Min(4),
|
||||||
))));
|
))));
|
||||||
}
|
}
|
||||||
@ -134,61 +72,66 @@ class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
))));
|
))));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function testWalkSingleConstraint()
|
||||||
* @dataProvider getValidArguments
|
|
||||||
*/
|
|
||||||
public function testWalkSingleConstraint($array)
|
|
||||||
{
|
{
|
||||||
$this->context->setGroup('MyGroup');
|
$this->context->setGroup('MyGroup');
|
||||||
$this->context->setPropertyPath('foo');
|
$this->context->setPropertyPath('foo');
|
||||||
|
|
||||||
$constraint = new Min(4);
|
$constraint = new Min(4);
|
||||||
|
|
||||||
|
$array = array('foo' => 3);
|
||||||
|
|
||||||
foreach ($array as $key => $value) {
|
foreach ($array as $key => $value) {
|
||||||
$this->walker->expects($this->once())
|
$this->walker->expects($this->once())
|
||||||
->method('walkConstraint')
|
->method('walkConstraint')
|
||||||
->with($this->equalTo($constraint), $this->equalTo($value), $this->equalTo('MyGroup'), $this->equalTo('foo['.$key.']'));
|
->with($this->equalTo($constraint), $this->equalTo($value), $this->equalTo('MyGroup'), $this->equalTo('foo['.$key.']'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertTrue($this->validator->isValid($array, new Collection(array(
|
$data = $this->prepareTestData($array);
|
||||||
|
|
||||||
|
$this->assertTrue($this->validator->isValid($data, new Collection(array(
|
||||||
'fields' => array(
|
'fields' => array(
|
||||||
'foo' => $constraint,
|
'foo' => $constraint,
|
||||||
),
|
),
|
||||||
))));
|
))));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function testWalkMultipleConstraints()
|
||||||
* @dataProvider getValidArguments
|
|
||||||
*/
|
|
||||||
public function testWalkMultipleConstraints($array)
|
|
||||||
{
|
{
|
||||||
$this->context->setGroup('MyGroup');
|
$this->context->setGroup('MyGroup');
|
||||||
$this->context->setPropertyPath('foo');
|
$this->context->setPropertyPath('foo');
|
||||||
|
|
||||||
$constraint = new Min(4);
|
$constraints = array(
|
||||||
// can only test for twice the same constraint because PHPUnits mocking
|
new Min(4),
|
||||||
// can't test method calls with different arguments
|
new NotNull(),
|
||||||
$constraints = array($constraint, $constraint);
|
);
|
||||||
|
$array = array('foo' => 3);
|
||||||
|
|
||||||
foreach ($array as $key => $value) {
|
foreach ($array as $key => $value) {
|
||||||
$this->walker->expects($this->exactly(2))
|
foreach ($constraints as $i => $constraint) {
|
||||||
|
$this->walker->expects($this->at($i))
|
||||||
->method('walkConstraint')
|
->method('walkConstraint')
|
||||||
->with($this->equalTo($constraint), $this->equalTo($value), $this->equalTo('MyGroup'), $this->equalTo('foo['.$key.']'));
|
->with($this->equalTo($constraint), $this->equalTo($value), $this->equalTo('MyGroup'), $this->equalTo('foo['.$key.']'));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->assertTrue($this->validator->isValid($array, new Collection(array(
|
$data = $this->prepareTestData($array);
|
||||||
|
|
||||||
|
$this->assertTrue($this->validator->isValid($data, new Collection(array(
|
||||||
'fields' => array(
|
'fields' => array(
|
||||||
'foo' => $constraints,
|
'foo' => $constraints,
|
||||||
)
|
)
|
||||||
))));
|
))));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function testExtraFieldsDisallowed()
|
||||||
* @dataProvider getArgumentsWithExtraFields
|
|
||||||
*/
|
|
||||||
public function testExtraFieldsDisallowed($array)
|
|
||||||
{
|
{
|
||||||
$this->assertFalse($this->validator->isValid($array, new Collection(array(
|
$data = $this->prepareTestData(array(
|
||||||
|
'foo' => 5,
|
||||||
|
'bar' => 6,
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertFalse($this->validator->isValid($data, new Collection(array(
|
||||||
'fields' => array(
|
'fields' => array(
|
||||||
'foo' => new Min(4),
|
'foo' => new Min(4),
|
||||||
),
|
),
|
||||||
@ -198,26 +141,24 @@ class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
// bug fix
|
// bug fix
|
||||||
public function testNullNotConsideredExtraField()
|
public function testNullNotConsideredExtraField()
|
||||||
{
|
{
|
||||||
$array = array(
|
$data = $this->prepareTestData(array(
|
||||||
'foo' => null,
|
'foo' => null,
|
||||||
);
|
));
|
||||||
$collection = new Collection(array(
|
$collection = new Collection(array(
|
||||||
'fields' => array(
|
'fields' => array(
|
||||||
'foo' => new Min(4),
|
'foo' => new Min(4),
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertTrue($this->validator->isValid($array, $collection));
|
$this->assertTrue($this->validator->isValid($data, $collection));
|
||||||
$this->assertTrue($this->validator->isValid(new \ArrayObject($array), $collection));
|
|
||||||
$this->assertTrue($this->validator->isValid(new TestArrayObject($array), $collection));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testExtraFieldsAllowed()
|
public function testExtraFieldsAllowed()
|
||||||
{
|
{
|
||||||
$array = array(
|
$data = $this->prepareTestData(array(
|
||||||
'foo' => 5,
|
'foo' => 5,
|
||||||
'bar' => 6,
|
'bar' => 6,
|
||||||
);
|
));
|
||||||
$collection = new Collection(array(
|
$collection = new Collection(array(
|
||||||
'fields' => array(
|
'fields' => array(
|
||||||
'foo' => new Min(4),
|
'foo' => new Min(4),
|
||||||
@ -225,24 +166,14 @@ class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
'allowExtraFields' => true,
|
'allowExtraFields' => true,
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertTrue($this->validator->isValid($array, $collection));
|
$this->assertTrue($this->validator->isValid($data, $collection));
|
||||||
$this->assertTrue($this->validator->isValid(new \ArrayObject($array), $collection));
|
|
||||||
$this->assertTrue($this->validator->isValid(new TestArrayObject($array), $collection));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMissingFieldsDisallowed()
|
public function testMissingFieldsDisallowed()
|
||||||
{
|
{
|
||||||
$this->assertFalse($this->validator->isValid(array(), new Collection(array(
|
$data = $this->prepareTestData(array());
|
||||||
'fields' => array(
|
|
||||||
'foo' => new Min(4),
|
$this->assertFalse($this->validator->isValid($data, new Collection(array(
|
||||||
),
|
|
||||||
))));
|
|
||||||
$this->assertFalse($this->validator->isValid(new \ArrayObject(array()), new Collection(array(
|
|
||||||
'fields' => array(
|
|
||||||
'foo' => new Min(4),
|
|
||||||
),
|
|
||||||
))));
|
|
||||||
$this->assertFalse($this->validator->isValid(new TestArrayObject(array()), new Collection(array(
|
|
||||||
'fields' => array(
|
'fields' => array(
|
||||||
'foo' => new Min(4),
|
'foo' => new Min(4),
|
||||||
),
|
),
|
||||||
@ -251,83 +182,32 @@ class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testMissingFieldsAllowed()
|
public function testMissingFieldsAllowed()
|
||||||
{
|
{
|
||||||
$this->assertTrue($this->validator->isValid(array(), new Collection(array(
|
$data = $this->prepareTestData(array());
|
||||||
|
|
||||||
|
$this->assertTrue($this->validator->isValid($data, new Collection(array(
|
||||||
'fields' => array(
|
'fields' => array(
|
||||||
'foo' => new Min(4),
|
'foo' => new Min(4),
|
||||||
),
|
),
|
||||||
'allowMissingFields' => true,
|
'allowMissingFields' => true,
|
||||||
))));
|
))));
|
||||||
$this->assertTrue($this->validator->isValid(new \ArrayObject(array()), new Collection(array(
|
|
||||||
'fields' => array(
|
|
||||||
'foo' => new Min(4),
|
|
||||||
),
|
|
||||||
'allowMissingFields' => true,
|
|
||||||
))));
|
|
||||||
$this->assertTrue($this->validator->isValid(new TestArrayObject(array()), new Collection(array(
|
|
||||||
'fields' => array(
|
|
||||||
'foo' => new Min(4),
|
|
||||||
),
|
|
||||||
'allowMissingFields' => true,
|
|
||||||
))));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testArrayAccessObject() {
|
|
||||||
$value = new TestArrayObject();
|
|
||||||
$value['foo'] = 12;
|
|
||||||
$value['asdf'] = 'asdfaf';
|
|
||||||
|
|
||||||
$this->assertTrue(isset($value['asdf']));
|
|
||||||
$this->assertTrue(isset($value['foo']));
|
|
||||||
$this->assertFalse(empty($value['asdf']));
|
|
||||||
$this->assertFalse(empty($value['foo']));
|
|
||||||
|
|
||||||
$result = $this->validator->isValid($value, new Collection(array(
|
|
||||||
'fields' => array(
|
|
||||||
'foo' => new NotBlank(),
|
|
||||||
'asdf' => new NotBlank()
|
|
||||||
)
|
|
||||||
)));
|
|
||||||
|
|
||||||
$this->assertTrue($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testArrayObject() {
|
|
||||||
$value = new \ArrayObject(array());
|
|
||||||
$value['foo'] = 12;
|
|
||||||
$value['asdf'] = 'asdfaf';
|
|
||||||
|
|
||||||
$this->assertTrue(isset($value['asdf']));
|
|
||||||
$this->assertTrue(isset($value['foo']));
|
|
||||||
$this->assertFalse(empty($value['asdf']));
|
|
||||||
$this->assertFalse(empty($value['foo']));
|
|
||||||
|
|
||||||
$result = $this->validator->isValid($value, new Collection(array(
|
|
||||||
'fields' => array(
|
|
||||||
'foo' => new NotBlank(),
|
|
||||||
'asdf' => new NotBlank()
|
|
||||||
)
|
|
||||||
)));
|
|
||||||
|
|
||||||
$this->assertTrue($result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testOptionalFieldPresent()
|
public function testOptionalFieldPresent()
|
||||||
{
|
{
|
||||||
$array = array(
|
$data = $this->prepareTestData(array(
|
||||||
'foo' => null,
|
'foo' => null,
|
||||||
);
|
));
|
||||||
|
|
||||||
$this->assertTrue($this->validator->isValid($array, new Collection(array(
|
$this->assertTrue($this->validator->isValid($data, new Collection(array(
|
||||||
'foo' => new Optional(),
|
'foo' => new Optional(),
|
||||||
))));
|
))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testOptionalFieldNotPresent()
|
public function testOptionalFieldNotPresent()
|
||||||
{
|
{
|
||||||
$array = array(
|
$data = $this->prepareTestData(array());
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertTrue($this->validator->isValid($array, new Collection(array(
|
$this->assertTrue($this->validator->isValid($data, new Collection(array(
|
||||||
'foo' => new Optional(),
|
'foo' => new Optional(),
|
||||||
))));
|
))));
|
||||||
}
|
}
|
||||||
@ -347,7 +227,9 @@ class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
->method('walkConstraint')
|
->method('walkConstraint')
|
||||||
->with($this->equalTo($constraint), $this->equalTo($array['foo']), $this->equalTo('MyGroup'), $this->equalTo('bar[foo]'));
|
->with($this->equalTo($constraint), $this->equalTo($array['foo']), $this->equalTo('MyGroup'), $this->equalTo('bar[foo]'));
|
||||||
|
|
||||||
$this->assertTrue($this->validator->isValid($array, new Collection(array(
|
$data = $this->prepareTestData($array);
|
||||||
|
|
||||||
|
$this->assertTrue($this->validator->isValid($data, new Collection(array(
|
||||||
'foo' => new Optional($constraint),
|
'foo' => new Optional($constraint),
|
||||||
))));
|
))));
|
||||||
}
|
}
|
||||||
@ -372,28 +254,29 @@ class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
->with($this->equalTo($constraint), $this->equalTo($array['foo']), $this->equalTo('MyGroup'), $this->equalTo('bar[foo]'));
|
->with($this->equalTo($constraint), $this->equalTo($array['foo']), $this->equalTo('MyGroup'), $this->equalTo('bar[foo]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertTrue($this->validator->isValid($array, new Collection(array(
|
$data = $this->prepareTestData($array);
|
||||||
|
|
||||||
|
$this->assertTrue($this->validator->isValid($data, new Collection(array(
|
||||||
'foo' => new Optional($constraints),
|
'foo' => new Optional($constraints),
|
||||||
))));
|
))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRequiredFieldPresent()
|
public function testRequiredFieldPresent()
|
||||||
{
|
{
|
||||||
$array = array(
|
$data = $this->prepareTestData(array(
|
||||||
'foo' => null,
|
'foo' => null,
|
||||||
);
|
));
|
||||||
|
|
||||||
$this->assertTrue($this->validator->isValid($array, new Collection(array(
|
$this->assertTrue($this->validator->isValid($data, new Collection(array(
|
||||||
'foo' => new Required(),
|
'foo' => new Required(),
|
||||||
))));
|
))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRequiredFieldNotPresent()
|
public function testRequiredFieldNotPresent()
|
||||||
{
|
{
|
||||||
$array = array(
|
$data = $this->prepareTestData(array());
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertFalse($this->validator->isValid($array, new Collection(array(
|
$this->assertFalse($this->validator->isValid($data, new Collection(array(
|
||||||
'foo' => new Required(),
|
'foo' => new Required(),
|
||||||
))));
|
))));
|
||||||
}
|
}
|
||||||
@ -413,7 +296,9 @@ class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
->method('walkConstraint')
|
->method('walkConstraint')
|
||||||
->with($this->equalTo($constraint), $this->equalTo($array['foo']), $this->equalTo('MyGroup'), $this->equalTo('bar[foo]'));
|
->with($this->equalTo($constraint), $this->equalTo($array['foo']), $this->equalTo('MyGroup'), $this->equalTo('bar[foo]'));
|
||||||
|
|
||||||
$this->assertTrue($this->validator->isValid($array, new Collection(array(
|
$data = $this->prepareTestData($array);
|
||||||
|
|
||||||
|
$this->assertTrue($this->validator->isValid($data, new Collection(array(
|
||||||
'foo' => new Required($constraint),
|
'foo' => new Required($constraint),
|
||||||
))));
|
))));
|
||||||
}
|
}
|
||||||
@ -438,6 +323,8 @@ class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
->with($this->equalTo($constraint), $this->equalTo($array['foo']), $this->equalTo('MyGroup'), $this->equalTo('bar[foo]'));
|
->with($this->equalTo($constraint), $this->equalTo($array['foo']), $this->equalTo('MyGroup'), $this->equalTo('bar[foo]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$data = $this->prepareTestData($array);
|
||||||
|
|
||||||
$this->assertTrue($this->validator->isValid($array, new Collection(array(
|
$this->assertTrue($this->validator->isValid($array, new Collection(array(
|
||||||
'foo' => new Required($constraints),
|
'foo' => new Required($constraints),
|
||||||
))));
|
))));
|
||||||
@ -458,34 +345,4 @@ class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
'foo' => 3
|
'foo' => 3
|
||||||
), (array) $value);
|
), (array) $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getValidArguments()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
// can only test for one entry, because PHPUnits mocking does not allow
|
|
||||||
// to expect multiple method calls with different arguments
|
|
||||||
array(array('foo' => 3)),
|
|
||||||
array(new \ArrayObject(array('foo' => 3))),
|
|
||||||
array(new TestArrayObject(array('foo' => 3))),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getArgumentsWithExtraFields()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
array(array(
|
|
||||||
'foo' => 5,
|
|
||||||
'bar' => 6,
|
|
||||||
)),
|
|
||||||
array(new \ArrayObject(array(
|
|
||||||
'foo' => 5,
|
|
||||||
'bar' => 6,
|
|
||||||
))),
|
|
||||||
array(new TestArrayObject(array(
|
|
||||||
'foo' => 5,
|
|
||||||
'bar' => 6,
|
|
||||||
)))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user