Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e6e3da5

Browse files
committed
[Validator] Improved test coverage of CollectionValidator and reduced test code duplication
1 parent 509c7bf commit e6e3da5

File tree

4 files changed

+192
-215
lines changed

4 files changed

+192
-215
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Tests\Component\Validator\Constraints;
13+
14+
class CollectionValidatorArrayObjectTest extends CollectionValidatorTest
15+
{
16+
public function prepareTestData(array $contents)
17+
{
18+
return new \ArrayObject($contents);
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Tests\Component\Validator\Constraints;
13+
14+
class CollectionValidatorArrayTest extends CollectionValidatorTest
15+
{
16+
public function prepareTestData(array $contents)
17+
{
18+
return $contents;
19+
}
20+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Tests\Component\Validator\Constraints;
13+
14+
/**
15+
* This class is a hand written simplified version of PHP native `ArrayObject`
16+
* class, to show that it behaves different than PHP native implementation.
17+
*/
18+
class CustomArrayObject implements \ArrayAccess, \IteratorAggregate, \Countable, \Serializable
19+
{
20+
private $array;
21+
22+
public function __construct(array $array = null)
23+
{
24+
$this->array = (array) ($array ?: array());
25+
}
26+
27+
public function offsetExists($offset)
28+
{
29+
return array_key_exists($offset, $this->array);
30+
}
31+
32+
public function offsetGet($offset)
33+
{
34+
return $this->array[$offset];
35+
}
36+
37+
public function offsetSet($offset, $value)
38+
{
39+
if (null === $offset) {
40+
$this->array[] = $value;
41+
} else {
42+
$this->array[$offset] = $value;
43+
}
44+
}
45+
46+
public function offsetUnset($offset)
47+
{
48+
if (array_key_exists($offset, $this->array)) {
49+
unset($this->array[$offset]);
50+
}
51+
}
52+
53+
public function getIterator()
54+
{
55+
return new \ArrayIterator($this->array);
56+
}
57+
58+
public function count()
59+
{
60+
return count($this->array);
61+
}
62+
63+
public function serialize()
64+
{
65+
return serialize($this->array);
66+
}
67+
68+
public function unserialize($serialized)
69+
{
70+
$this->array = (array) unserialize((string) $serialized);
71+
}
72+
}
73+
74+
class CollectionValidatorCustomArrayObjectTest extends CollectionValidatorTest
75+
{
76+
public function prepareTestData(array $contents)
77+
{
78+
return new CustomArrayObject($contents);
79+
}
80+
}

0 commit comments

Comments
 (0)