comparison vendor/sebastian/object-enumerator/tests/EnumeratorTest.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
children
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
1 <?php
2 /*
3 * This file is part of Object Enumerator.
4 *
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11 namespace SebastianBergmann\ObjectEnumerator;
12
13 use SebastianBergmann\ObjectEnumerator\Fixtures\ExceptionThrower;
14 use PHPUnit\Framework\TestCase;
15
16 /**
17 * @covers SebastianBergmann\ObjectEnumerator\Enumerator
18 */
19 class EnumeratorTest extends TestCase
20 {
21 /**
22 * @var Enumerator
23 */
24 private $enumerator;
25
26 protected function setUp()
27 {
28 $this->enumerator = new Enumerator;
29 }
30
31 public function testEnumeratesSingleObject()
32 {
33 $a = new \stdClass;
34
35 $objects = $this->enumerator->enumerate($a);
36
37 $this->assertCount(1, $objects);
38 $this->assertSame($a, $objects[0]);
39 }
40
41 public function testEnumeratesArrayWithSingleObject()
42 {
43 $a = new \stdClass;
44
45 $objects = $this->enumerator->enumerate([$a]);
46
47 $this->assertCount(1, $objects);
48 $this->assertSame($a, $objects[0]);
49 }
50
51 public function testEnumeratesArrayWithTwoReferencesToTheSameObject()
52 {
53 $a = new \stdClass;
54
55 $objects = $this->enumerator->enumerate([$a, $a]);
56
57 $this->assertCount(1, $objects);
58 $this->assertSame($a, $objects[0]);
59 }
60
61 public function testEnumeratesArrayOfObjects()
62 {
63 $a = new \stdClass;
64 $b = new \stdClass;
65
66 $objects = $this->enumerator->enumerate([$a, $b, null]);
67
68 $this->assertCount(2, $objects);
69 $this->assertSame($a, $objects[0]);
70 $this->assertSame($b, $objects[1]);
71 }
72
73 public function testEnumeratesObjectWithAggregatedObject()
74 {
75 $a = new \stdClass;
76 $b = new \stdClass;
77
78 $a->b = $b;
79 $a->c = null;
80
81 $objects = $this->enumerator->enumerate($a);
82
83 $this->assertCount(2, $objects);
84 $this->assertSame($a, $objects[0]);
85 $this->assertSame($b, $objects[1]);
86 }
87
88 public function testEnumeratesObjectWithAggregatedObjectsInArray()
89 {
90 $a = new \stdClass;
91 $b = new \stdClass;
92
93 $a->b = [$b];
94
95 $objects = $this->enumerator->enumerate($a);
96
97 $this->assertCount(2, $objects);
98 $this->assertSame($a, $objects[0]);
99 $this->assertSame($b, $objects[1]);
100 }
101
102 public function testEnumeratesObjectsWithCyclicReferences()
103 {
104 $a = new \stdClass;
105 $b = new \stdClass;
106
107 $a->b = $b;
108 $b->a = $a;
109
110 $objects = $this->enumerator->enumerate([$a, $b]);
111
112 $this->assertCount(2, $objects);
113 $this->assertSame($a, $objects[0]);
114 $this->assertSame($b, $objects[1]);
115 }
116
117 public function testEnumeratesClassThatThrowsException()
118 {
119 $thrower = new ExceptionThrower();
120
121 $objects = $this->enumerator->enumerate($thrower);
122
123 $this->assertSame($thrower, $objects[0]);
124 }
125
126 public function testExceptionIsRaisedForInvalidArgument()
127 {
128 $this->expectException(InvalidArgumentException::class);
129
130 $this->enumerator->enumerate(null);
131 }
132
133 public function testExceptionIsRaisedForInvalidArgument2()
134 {
135 $this->expectException(InvalidArgumentException::class);
136
137 $this->enumerator->enumerate([], '');
138 }
139 }