Mercurial > hg > isophonics-drupal-site
comparison vendor/sebastian/comparator/src/ObjectComparator.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
1 <?php | 1 <?php |
2 /* | 2 /* |
3 * This file is part of the Comparator package. | 3 * This file is part of sebastian/comparator. |
4 * | 4 * |
5 * (c) Sebastian Bergmann <sebastian@phpunit.de> | 5 * (c) Sebastian Bergmann <sebastian@phpunit.de> |
6 * | 6 * |
7 * For the full copyright and license information, please view the LICENSE | 7 * For the full copyright and license information, please view the LICENSE |
8 * file that was distributed with this source code. | 8 * file that was distributed with this source code. |
16 class ObjectComparator extends ArrayComparator | 16 class ObjectComparator extends ArrayComparator |
17 { | 17 { |
18 /** | 18 /** |
19 * Returns whether the comparator can compare two values. | 19 * Returns whether the comparator can compare two values. |
20 * | 20 * |
21 * @param mixed $expected The first value to compare | 21 * @param mixed $expected The first value to compare |
22 * @param mixed $actual The second value to compare | 22 * @param mixed $actual The second value to compare |
23 * | |
23 * @return bool | 24 * @return bool |
24 */ | 25 */ |
25 public function accepts($expected, $actual) | 26 public function accepts($expected, $actual) |
26 { | 27 { |
27 return is_object($expected) && is_object($actual); | 28 return \is_object($expected) && \is_object($actual); |
28 } | 29 } |
29 | 30 |
30 /** | 31 /** |
31 * Asserts that two values are equal. | 32 * Asserts that two values are equal. |
32 * | 33 * |
37 * @param bool $ignoreCase Case is ignored when set to true | 38 * @param bool $ignoreCase Case is ignored when set to true |
38 * @param array $processed List of already processed elements (used to prevent infinite recursion) | 39 * @param array $processed List of already processed elements (used to prevent infinite recursion) |
39 * | 40 * |
40 * @throws ComparisonFailure | 41 * @throws ComparisonFailure |
41 */ | 42 */ |
42 public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false, array &$processed = array()) | 43 public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false, array &$processed = []) |
43 { | 44 { |
44 if (get_class($actual) !== get_class($expected)) { | 45 if (\get_class($actual) !== \get_class($expected)) { |
45 throw new ComparisonFailure( | 46 throw new ComparisonFailure( |
46 $expected, | 47 $expected, |
47 $actual, | 48 $actual, |
48 $this->exporter->export($expected), | 49 $this->exporter->export($expected), |
49 $this->exporter->export($actual), | 50 $this->exporter->export($actual), |
50 false, | 51 false, |
51 sprintf( | 52 \sprintf( |
52 '%s is not instance of expected class "%s".', | 53 '%s is not instance of expected class "%s".', |
53 $this->exporter->export($actual), | 54 $this->exporter->export($actual), |
54 get_class($expected) | 55 \get_class($expected) |
55 ) | 56 ) |
56 ); | 57 ); |
57 } | 58 } |
58 | 59 |
59 // don't compare twice to allow for cyclic dependencies | 60 // don't compare twice to allow for cyclic dependencies |
60 if (in_array(array($actual, $expected), $processed, true) || | 61 if (\in_array([$actual, $expected], $processed, true) || |
61 in_array(array($expected, $actual), $processed, true)) { | 62 \in_array([$expected, $actual], $processed, true)) { |
62 return; | 63 return; |
63 } | 64 } |
64 | 65 |
65 $processed[] = array($actual, $expected); | 66 $processed[] = [$actual, $expected]; |
66 | 67 |
67 // don't compare objects if they are identical | 68 // don't compare objects if they are identical |
68 // this helps to avoid the error "maximum function nesting level reached" | 69 // this helps to avoid the error "maximum function nesting level reached" |
69 // CAUTION: this conditional clause is not tested | 70 // CAUTION: this conditional clause is not tested |
70 if ($actual !== $expected) { | 71 if ($actual !== $expected) { |
80 } catch (ComparisonFailure $e) { | 81 } catch (ComparisonFailure $e) { |
81 throw new ComparisonFailure( | 82 throw new ComparisonFailure( |
82 $expected, | 83 $expected, |
83 $actual, | 84 $actual, |
84 // replace "Array" with "MyClass object" | 85 // replace "Array" with "MyClass object" |
85 substr_replace($e->getExpectedAsString(), get_class($expected) . ' Object', 0, 5), | 86 \substr_replace($e->getExpectedAsString(), \get_class($expected) . ' Object', 0, 5), |
86 substr_replace($e->getActualAsString(), get_class($actual) . ' Object', 0, 5), | 87 \substr_replace($e->getActualAsString(), \get_class($actual) . ' Object', 0, 5), |
87 false, | 88 false, |
88 'Failed asserting that two objects are equal.' | 89 'Failed asserting that two objects are equal.' |
89 ); | 90 ); |
90 } | 91 } |
91 } | 92 } |
93 | 94 |
94 /** | 95 /** |
95 * Converts an object to an array containing all of its private, protected | 96 * Converts an object to an array containing all of its private, protected |
96 * and public properties. | 97 * and public properties. |
97 * | 98 * |
98 * @param object $object | 99 * @param object $object |
100 * | |
99 * @return array | 101 * @return array |
100 */ | 102 */ |
101 protected function toArray($object) | 103 protected function toArray($object) |
102 { | 104 { |
103 return $this->exporter->toArray($object); | 105 return $this->exporter->toArray($object); |