Mercurial > hg > isophonics-drupal-site
comparison core/tests/Drupal/Tests/Component/Utility/ArgumentsResolverTest.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 | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
94 | 94 |
95 /** | 95 /** |
96 * Tests getArgument() with a Route, Request, and Account object. | 96 * Tests getArgument() with a Route, Request, and Account object. |
97 */ | 97 */ |
98 public function testGetArgumentOrder() { | 98 public function testGetArgumentOrder() { |
99 $a1 = $this->getMock('\Drupal\Tests\Component\Utility\Test1Interface'); | 99 $a1 = $this->getMockBuilder('\Drupal\Tests\Component\Utility\Test1Interface')->getMock(); |
100 $a2 = $this->getMock('\Drupal\Tests\Component\Utility\TestClass'); | 100 $a2 = $this->getMockBuilder('\Drupal\Tests\Component\Utility\TestClass')->getMock(); |
101 $a3 = $this->getMock('\Drupal\Tests\Component\Utility\Test2Interface'); | 101 $a3 = $this->getMockBuilder('\Drupal\Tests\Component\Utility\Test2Interface')->getMock(); |
102 | 102 |
103 $objects = [ | 103 $objects = [ |
104 't1' => $a1, | 104 't1' => $a1, |
105 'tc' => $a2, | 105 'tc' => $a2, |
106 ]; | 106 ]; |
121 * Tests getArgument() with a wildcard parameter with no typehint. | 121 * Tests getArgument() with a wildcard parameter with no typehint. |
122 * | 122 * |
123 * Without the typehint, the wildcard object will not be passed to the callable. | 123 * Without the typehint, the wildcard object will not be passed to the callable. |
124 */ | 124 */ |
125 public function testGetWildcardArgumentNoTypehint() { | 125 public function testGetWildcardArgumentNoTypehint() { |
126 $a = $this->getMock('\Drupal\Tests\Component\Utility\Test1Interface'); | 126 $a = $this->getMockBuilder('\Drupal\Tests\Component\Utility\Test1Interface')->getMock(); |
127 $wildcards = [$a]; | 127 $wildcards = [$a]; |
128 $resolver = new ArgumentsResolver([], [], $wildcards); | 128 $resolver = new ArgumentsResolver([], [], $wildcards); |
129 | 129 |
130 $callable = function ($route) {}; | 130 $callable = function ($route) {}; |
131 $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$route" argument.'); | 131 if (method_exists($this, 'expectException')) { |
132 $this->expectException(\RuntimeException::class); | |
133 $this->expectExceptionMessage('requires a value for the "$route" argument.'); | |
134 } | |
135 else { | |
136 $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$route" argument.'); | |
137 } | |
132 $resolver->getArguments($callable); | 138 $resolver->getArguments($callable); |
133 } | 139 } |
134 | 140 |
135 /** | 141 /** |
136 * Tests getArgument() with a named parameter with no typehint and a value. | 142 * Tests getArgument() with a named parameter with no typehint and a value. |
154 $objects = ['foo' => 'bar']; | 160 $objects = ['foo' => 'bar']; |
155 $scalars = ['foo' => 'baz']; | 161 $scalars = ['foo' => 'baz']; |
156 $resolver = new ArgumentsResolver($scalars, $objects, []); | 162 $resolver = new ArgumentsResolver($scalars, $objects, []); |
157 | 163 |
158 $callable = function (\stdClass $foo) {}; | 164 $callable = function (\stdClass $foo) {}; |
159 $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$foo" argument.'); | 165 if (method_exists($this, 'expectException')) { |
166 $this->expectException(\RuntimeException::class); | |
167 $this->expectExceptionMessage('requires a value for the "$foo" argument.'); | |
168 } | |
169 else { | |
170 $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$foo" argument.'); | |
171 } | |
160 $resolver->getArguments($callable); | 172 $resolver->getArguments($callable); |
161 } | 173 } |
162 | 174 |
163 /** | 175 /** |
164 * Tests handleUnresolvedArgument() for missing arguments. | 176 * Tests handleUnresolvedArgument() for missing arguments. |
165 * | 177 * |
166 * @dataProvider providerTestHandleUnresolvedArgument | 178 * @dataProvider providerTestHandleUnresolvedArgument |
167 */ | 179 */ |
168 public function testHandleUnresolvedArgument($callable) { | 180 public function testHandleUnresolvedArgument($callable) { |
169 $resolver = new ArgumentsResolver([], [], []); | 181 $resolver = new ArgumentsResolver([], [], []); |
170 $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$foo" argument.'); | 182 if (method_exists($this, 'expectException')) { |
183 $this->expectException(\RuntimeException::class); | |
184 $this->expectExceptionMessage('requires a value for the "$foo" argument.'); | |
185 } | |
186 else { | |
187 $this->setExpectedException(\RuntimeException::class, 'requires a value for the "$foo" argument.'); | |
188 } | |
171 $resolver->getArguments($callable); | 189 $resolver->getArguments($callable); |
172 } | 190 } |
173 | 191 |
174 /** | 192 /** |
175 * Provides test data to testHandleUnresolvedArgument(). | 193 * Provides test data to testHandleUnresolvedArgument(). |