|
6 | 6 |
|
7 | 7 | declare(strict_types=1); |
8 | 8 |
|
9 | | -namespace NS { |
10 | | - define('DEFINED', 123); |
11 | | - define('NS_DEFINED', 'xxx'); |
12 | | - const NS_DEFINED = 456; |
| 9 | +use Nette\Utils\Reflection; |
| 10 | +use Tester\Assert; |
13 | 11 |
|
14 | | - interface Bar |
15 | | - { |
16 | | - const DEFINED = 'xyz'; |
17 | | - } |
| 12 | +require __DIR__ . '/../bootstrap.php'; |
| 13 | +require __DIR__ . '/fixtures.reflection/defaultValue.php'; |
18 | 14 |
|
19 | | - class Foo |
20 | | - { |
21 | | - const DEFINED = 'abc'; |
22 | 15 |
|
| 16 | +Assert::exception(function () { |
| 17 | + Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'a')); |
| 18 | +}, ReflectionException::class); |
23 | 19 |
|
24 | | - public function method( |
25 | | - $a, |
26 | | - $b = self::DEFINED, |
27 | | - $c = Foo::DEFINED, |
28 | | - $d = SELF::DEFINED, |
29 | | - $e = bar::DEFINED, |
30 | | - $f = self::UNDEFINED, |
31 | | - $g = Undefined::ANY, |
32 | | - $h = DEFINED, |
33 | | - $i = UNDEFINED, |
34 | | - $j = NS_DEFINED |
35 | | - ) { |
36 | | - } |
37 | | - } |
38 | | -} |
| 20 | +Assert::same(NS\Foo::DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'b'))); |
39 | 21 |
|
40 | | -namespace { |
41 | | - use Nette\Utils\Reflection; |
42 | | - use Tester\Assert; |
| 22 | +Assert::same(NS\Foo::DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'c'))); |
43 | 23 |
|
44 | | - require __DIR__ . '/../bootstrap.php'; |
| 24 | +Assert::same(NS\Foo::DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'd'))); |
45 | 25 |
|
| 26 | +Assert::same(NS\Bar::DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'e'))); |
46 | 27 |
|
47 | | - Assert::exception(function () { |
48 | | - Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'a')); |
49 | | - }, ReflectionException::class); |
| 28 | +Assert::exception(function () { |
| 29 | + Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'f')); |
| 30 | +}, ReflectionException::class, 'Unable to resolve constant self::UNDEFINED used as default value of $f in NS\Foo::method().'); |
50 | 31 |
|
51 | | - Assert::same(NS\Foo::DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'b'))); |
| 32 | +Assert::exception(function () { |
| 33 | + Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'g')); |
| 34 | +}, ReflectionException::class, 'Unable to resolve constant NS\Undefined::ANY used as default value of $g in NS\Foo::method().'); |
52 | 35 |
|
53 | | - Assert::same(NS\Foo::DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'c'))); |
| 36 | +Assert::same(DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'h'))); |
54 | 37 |
|
55 | | - Assert::same(NS\Foo::DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'd'))); |
| 38 | +Assert::exception(function () { |
| 39 | + Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'i')); |
| 40 | +}, ReflectionException::class, 'Unable to resolve constant NS\UNDEFINED used as default value of $i in NS\Foo::method().'); |
56 | 41 |
|
57 | | - Assert::same(NS\Bar::DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'e'))); |
58 | | - |
59 | | - Assert::exception(function () { |
60 | | - Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'f')); |
61 | | - }, ReflectionException::class, 'Unable to resolve constant self::UNDEFINED used as default value of $f in NS\Foo::method().'); |
62 | | - |
63 | | - Assert::exception(function () { |
64 | | - Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'g')); |
65 | | - }, ReflectionException::class, 'Unable to resolve constant NS\Undefined::ANY used as default value of $g in NS\Foo::method().'); |
66 | | - |
67 | | - Assert::same(DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'h'))); |
68 | | - |
69 | | - Assert::exception(function () { |
70 | | - Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'i')); |
71 | | - }, ReflectionException::class, 'Unable to resolve constant NS\UNDEFINED used as default value of $i in NS\Foo::method().'); |
72 | | - |
73 | | - Assert::same(NS\NS_DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'j'))); |
74 | | -} |
| 42 | +Assert::same(NS\NS_DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'j'))); |
0 commit comments