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