|
42 | 42 |
|
43 | 43 | $invalid = InlineChecker::checkVariable(-5, 'positive-int', 'age', __FILE__, $registry); |
44 | 44 | expect($invalid)->toBeInstanceOf(ErrorMessage::class) |
45 | | - ->and($invalid->getMessage())->toContain('Variable $age must be of type positive-int'); |
| 45 | + ->and($invalid->getMessage())->toContain('Variable $age must be of type positive-int') |
| 46 | + ; |
46 | 47 | }); |
47 | 48 |
|
48 | 49 | test('validates non-empty-string and numeric-string', function () { |
|
77 | 78 | expect(InlineChecker::checkVariable([1, -5, 3], 'list<positive-int>', 'scores', __FILE__, $registry))->toBeInstanceOf(ErrorMessage::class); |
78 | 79 |
|
79 | 80 | expect(InlineChecker::checkVariable(['id' => 1, 'name' => 'Alice'], 'array{id: int, name: string}', 'user', __FILE__, $registry)) |
80 | | - ->toBe(['id' => 1, 'name' => 'Alice']); |
| 81 | + ->toBe(['id' => 1, 'name' => 'Alice']) |
| 82 | + ; |
81 | 83 |
|
82 | 84 | expect(InlineChecker::checkVariable(['id' => 1], 'array{id: int, name: string}', 'user', __FILE__, $registry))->toBeInstanceOf(ErrorMessage::class); |
83 | 85 | }); |
|
112 | 114 | $result = InlineChecker::checkVariable($collection, $typeString, 'dogs', __FILE__, $registry); |
113 | 115 |
|
114 | 116 | expect($result)->toBe($collection) |
115 | | - ->and(TypePHP::getGenericType($collection))->toBe(Dog::class); |
| 117 | + ->and(TypePHP::getGenericType($collection))->toBe(Dog::class) |
| 118 | + ; |
116 | 119 | }); |
117 | 120 |
|
118 | 121 | test('ignores object and generic checks when respective toggles are false', function () { |
|
131 | 134 | describe('checkVariable: Callables & Direct Returns', function () { |
132 | 135 | test('wraps callable variable in lazy proxy', function () { |
133 | 136 | $registry = new TypeValidatorRegistry(); |
134 | | - $cb = fn(int $id): string => "user_{$id}"; |
| 137 | + $cb = fn (int $id): string => "user_{$id}"; |
135 | 138 |
|
136 | 139 | $wrapped = InlineChecker::checkVariable($cb, 'callable(positive-int): non-empty-string', 'formatter', __FILE__, $registry); |
137 | 140 |
|
138 | 141 | expect($wrapped)->toBeCallable() |
139 | | - ->and($wrapped(10))->toBe('user_10'); |
| 142 | + ->and($wrapped(10))->toBe('user_10') |
| 143 | + ; |
140 | 144 |
|
141 | | - expect(fn() => $wrapped(-5))->toThrow(TypeError::class, 'positive-int'); |
| 145 | + expect(fn () => $wrapped(-5))->toThrow(TypeError::class, 'positive-int'); |
142 | 146 | }); |
143 | 147 |
|
144 | 148 | test('formats error message context as Return value when varName is return', function () { |
|
147 | 151 | $invalid = InlineChecker::checkVariable(-5, 'positive-int', 'return', __FILE__, $registry); |
148 | 152 |
|
149 | 153 | expect($invalid)->toBeInstanceOf(ErrorMessage::class) |
150 | | - ->and($invalid->getMessage())->toContain('Return value must be of type positive-int'); |
| 154 | + ->and($invalid->getMessage())->toContain('Return value must be of type positive-int') |
| 155 | + ; |
151 | 156 | }); |
152 | 157 |
|
153 | 158 | test('returns value immediately when all inline checks are disabled', function () { |
|
181 | 186 |
|
182 | 187 | $invalid = InlineChecker::checkProperty(['invalid'], $fixture, 'numbers', __FILE__, $registry); |
183 | 188 | expect($invalid)->toBeInstanceOf(ErrorMessage::class) |
184 | | - ->and($invalid->getMessage())->toContain('numbers[0]'); |
| 189 | + ->and($invalid->getMessage())->toContain('numbers[0]') |
| 190 | + ; |
185 | 191 | }); |
186 | 192 |
|
187 | 193 | test('validates static class properties against @var docblock', function () { |
|
192 | 198 |
|
193 | 199 | $invalid = InlineChecker::checkProperty(12345, ConfiguredProperty::class, 'staticTitle', __FILE__, $registry); |
194 | 200 | expect($invalid)->toBeInstanceOf(ErrorMessage::class) |
195 | | - ->and($invalid->getMessage())->toContain('staticTitle must be of type string'); |
| 201 | + ->and($invalid->getMessage())->toContain('staticTitle must be of type string') |
| 202 | + ; |
196 | 203 | }); |
197 | 204 |
|
198 | 205 | test('substitutes generic template types in class properties', function () { |
|
205 | 212 | $registry = new TypeValidatorRegistry(); |
206 | 213 | $collection = new HookedCollection(); |
207 | 214 |
|
208 | | - TemplateManager::bindTemplate(HookedCollection::class . '::__construct', $collection, 'T', new \PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode(Dog::class)); |
| 215 | + TemplateManager::bindTemplate(HookedCollection::class . '::__construct', $collection, 'T', new PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode(Dog::class)); |
209 | 216 |
|
210 | 217 | $valid = InlineChecker::checkProperty([new Dog()], $collection, 'items', __FILE__, $registry); |
211 | 218 | expect($valid)->toBeArray(); |
212 | 219 |
|
213 | 220 | $invalid = InlineChecker::checkProperty([new Car()], $collection, 'items', __FILE__, $registry); |
214 | 221 | expect($invalid)->toBeInstanceOf(ErrorMessage::class) |
215 | | - ->and($invalid->getMessage())->toContain("items['0']"); |
| 222 | + ->and($invalid->getMessage())->toContain("items['0']") |
| 223 | + ; |
216 | 224 | }); |
217 | 225 |
|
218 | 226 | test('ignores property checks when properties toggle is false', function () { |
|
0 commit comments