|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Test: Nette\PhpGenerator for files. |
| 5 | + */ |
| 6 | + |
| 7 | +use Tester\Assert; |
| 8 | + |
| 9 | +require __DIR__ . '/../bootstrap.php'; |
| 10 | + |
| 11 | + |
| 12 | +Assert::noError(function () { |
| 13 | + new Nette\PhpGenerator\PhpNamespace(''); // global namespace |
| 14 | + new Nette\PhpGenerator\PhpNamespace(NULL); // global namespace for back compatibility |
| 15 | + new Nette\PhpGenerator\PhpNamespace('Iñtërnâti\ônàlizætiøn'); |
| 16 | +}); |
| 17 | + |
| 18 | +Assert::exception(function () { |
| 19 | + new Nette\PhpGenerator\PhpNamespace('*'); |
| 20 | +}, Nette\InvalidArgumentException::class); |
| 21 | + |
| 22 | +Assert::exception(function () { |
| 23 | + new Nette\PhpGenerator\PhpNamespace('abc abc'); |
| 24 | +}, Nette\InvalidArgumentException::class); |
| 25 | + |
| 26 | +Assert::exception(function () { |
| 27 | + new Nette\PhpGenerator\PhpNamespace('abc\\'); |
| 28 | +}, Nette\InvalidArgumentException::class); |
| 29 | + |
| 30 | +Assert::exception(function () { |
| 31 | + new Nette\PhpGenerator\PhpNamespace('\\abc'); |
| 32 | +}, Nette\InvalidArgumentException::class); |
| 33 | + |
| 34 | + |
| 35 | +Assert::noError(function () { |
| 36 | + new Nette\PhpGenerator\ClassType(NULL); // anonymous class |
| 37 | + new Nette\PhpGenerator\ClassType('Iñtërnâtiônàlizætiøn'); |
| 38 | +}); |
| 39 | + |
| 40 | +Assert::exception(function () { |
| 41 | + new Nette\PhpGenerator\ClassType(''); |
| 42 | +}, Nette\InvalidArgumentException::class); |
| 43 | + |
| 44 | +Assert::exception(function () { |
| 45 | + new Nette\PhpGenerator\ClassType('*'); |
| 46 | +}, Nette\InvalidArgumentException::class); |
| 47 | + |
| 48 | +Assert::exception(function () { |
| 49 | + new Nette\PhpGenerator\ClassType('abc abc'); |
| 50 | +}, Nette\InvalidArgumentException::class); |
| 51 | + |
| 52 | +Assert::exception(function () { |
| 53 | + new Nette\PhpGenerator\ClassType('abc\\abc'); |
| 54 | +}, Nette\InvalidArgumentException::class); |
| 55 | + |
| 56 | +Assert::exception(function () { |
| 57 | + new Nette\PhpGenerator\ClassType('\\abc'); |
| 58 | +}, Nette\InvalidArgumentException::class); |
| 59 | + |
| 60 | + |
| 61 | +Assert::noError(function () { |
| 62 | + new Nette\PhpGenerator\Property('Iñtërnâtiônàlizætiøn'); |
| 63 | +}); |
| 64 | + |
| 65 | +Assert::exception(function () { |
| 66 | + new Nette\PhpGenerator\Property(NULL); |
| 67 | +}, Nette\InvalidArgumentException::class); |
| 68 | + |
| 69 | +Assert::exception(function () { |
| 70 | + new Nette\PhpGenerator\Property(''); |
| 71 | +}, Nette\InvalidArgumentException::class); |
| 72 | + |
| 73 | +Assert::exception(function () { |
| 74 | + new Nette\PhpGenerator\Property('*'); |
| 75 | +}, Nette\InvalidArgumentException::class); |
| 76 | + |
| 77 | + |
| 78 | +Assert::noError(function () { |
| 79 | + new Nette\PhpGenerator\Parameter('Iñtërnâtiônàlizætiøn'); |
| 80 | +}); |
| 81 | + |
| 82 | +Assert::exception(function () { |
| 83 | + new Nette\PhpGenerator\Parameter(''); |
| 84 | +}, Nette\InvalidArgumentException::class); |
| 85 | + |
| 86 | +Assert::exception(function () { |
| 87 | + new Nette\PhpGenerator\Parameter(NULL); |
| 88 | +}, Nette\InvalidArgumentException::class); |
| 89 | + |
| 90 | +Assert::exception(function () { |
| 91 | + new Nette\PhpGenerator\Parameter('*'); |
| 92 | +}, Nette\InvalidArgumentException::class); |
| 93 | + |
| 94 | +Assert::exception(function () { |
| 95 | + new Nette\PhpGenerator\Parameter('$test'); |
| 96 | +}, Nette\InvalidArgumentException::class); |
| 97 | + |
| 98 | + |
| 99 | +Assert::noError(function () { |
| 100 | + new Nette\PhpGenerator\Method('Iñtërnâtiônàlizætiøn'); |
| 101 | +}); |
| 102 | + |
| 103 | +Assert::exception(function () { |
| 104 | + new Nette\PhpGenerator\Method(''); |
| 105 | +}, Nette\InvalidArgumentException::class); |
| 106 | + |
| 107 | +Assert::exception(function () { |
| 108 | + new Nette\PhpGenerator\Method(NULL); |
| 109 | +}, Nette\DeprecatedException::class); |
| 110 | + |
| 111 | +Assert::exception(function () { |
| 112 | + new Nette\PhpGenerator\Method('*'); |
| 113 | +}, Nette\InvalidArgumentException::class); |
| 114 | + |
| 115 | + |
| 116 | +Assert::noError(function () { |
| 117 | + new Nette\PhpGenerator\GlobalFunction('Iñtërnâtiônàlizætiøn'); |
| 118 | +}); |
| 119 | + |
| 120 | +Assert::exception(function () { |
| 121 | + new Nette\PhpGenerator\GlobalFunction(''); |
| 122 | +}, Nette\InvalidArgumentException::class); |
| 123 | + |
| 124 | +Assert::exception(function () { |
| 125 | + new Nette\PhpGenerator\GlobalFunction(NULL); |
| 126 | +}, Nette\InvalidArgumentException::class); |
| 127 | + |
| 128 | +Assert::exception(function () { |
| 129 | + new Nette\PhpGenerator\GlobalFunction('*'); |
| 130 | +}, Nette\InvalidArgumentException::class); |
| 131 | + |
| 132 | + |
| 133 | +Assert::noError(function () { |
| 134 | + new Nette\PhpGenerator\Constant('Iñtërnâtiônàlizætiøn'); |
| 135 | +}); |
| 136 | + |
| 137 | +Assert::exception(function () { |
| 138 | + new Nette\PhpGenerator\Constant(NULL); |
| 139 | +}, Nette\InvalidArgumentException::class); |
| 140 | + |
| 141 | +Assert::exception(function () { |
| 142 | + new Nette\PhpGenerator\Constant(''); |
| 143 | +}, Nette\InvalidArgumentException::class); |
| 144 | + |
| 145 | +Assert::exception(function () { |
| 146 | + new Nette\PhpGenerator\Constant('*'); |
| 147 | +}, Nette\InvalidArgumentException::class); |
0 commit comments