Chris@0
|
1 <?php
|
Chris@0
|
2 /*
|
Chris@14
|
3 * This file is part of sebastian/comparator.
|
Chris@0
|
4 *
|
Chris@0
|
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
|
Chris@0
|
6 *
|
Chris@0
|
7 * For the full copyright and license information, please view the LICENSE
|
Chris@0
|
8 * file that was distributed with this source code.
|
Chris@0
|
9 */
|
Chris@0
|
10
|
Chris@0
|
11 namespace SebastianBergmann\Comparator;
|
Chris@0
|
12
|
Chris@0
|
13 /**
|
Chris@0
|
14 * Compares \SplObjectStorage instances for equality.
|
Chris@0
|
15 */
|
Chris@0
|
16 class SplObjectStorageComparator extends Comparator
|
Chris@0
|
17 {
|
Chris@0
|
18 /**
|
Chris@0
|
19 * Returns whether the comparator can compare two values.
|
Chris@0
|
20 *
|
Chris@14
|
21 * @param mixed $expected The first value to compare
|
Chris@14
|
22 * @param mixed $actual The second value to compare
|
Chris@14
|
23 *
|
Chris@0
|
24 * @return bool
|
Chris@0
|
25 */
|
Chris@0
|
26 public function accepts($expected, $actual)
|
Chris@0
|
27 {
|
Chris@0
|
28 return $expected instanceof \SplObjectStorage && $actual instanceof \SplObjectStorage;
|
Chris@0
|
29 }
|
Chris@0
|
30
|
Chris@0
|
31 /**
|
Chris@0
|
32 * Asserts that two values are equal.
|
Chris@0
|
33 *
|
Chris@0
|
34 * @param mixed $expected First value to compare
|
Chris@0
|
35 * @param mixed $actual Second value to compare
|
Chris@0
|
36 * @param float $delta Allowed numerical distance between two values to consider them equal
|
Chris@0
|
37 * @param bool $canonicalize Arrays are sorted before comparison when set to true
|
Chris@0
|
38 * @param bool $ignoreCase Case is ignored when set to true
|
Chris@0
|
39 *
|
Chris@0
|
40 * @throws ComparisonFailure
|
Chris@0
|
41 */
|
Chris@0
|
42 public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false)
|
Chris@0
|
43 {
|
Chris@0
|
44 foreach ($actual as $object) {
|
Chris@0
|
45 if (!$expected->contains($object)) {
|
Chris@0
|
46 throw new ComparisonFailure(
|
Chris@0
|
47 $expected,
|
Chris@0
|
48 $actual,
|
Chris@0
|
49 $this->exporter->export($expected),
|
Chris@0
|
50 $this->exporter->export($actual),
|
Chris@0
|
51 false,
|
Chris@0
|
52 'Failed asserting that two objects are equal.'
|
Chris@0
|
53 );
|
Chris@0
|
54 }
|
Chris@0
|
55 }
|
Chris@0
|
56
|
Chris@0
|
57 foreach ($expected as $object) {
|
Chris@0
|
58 if (!$actual->contains($object)) {
|
Chris@0
|
59 throw new ComparisonFailure(
|
Chris@0
|
60 $expected,
|
Chris@0
|
61 $actual,
|
Chris@0
|
62 $this->exporter->export($expected),
|
Chris@0
|
63 $this->exporter->export($actual),
|
Chris@0
|
64 false,
|
Chris@0
|
65 'Failed asserting that two objects are equal.'
|
Chris@0
|
66 );
|
Chris@0
|
67 }
|
Chris@0
|
68 }
|
Chris@0
|
69 }
|
Chris@0
|
70 }
|