@@ -275,6 +275,88 @@ public function testDifferingNumericTypesAdditionInStrictMode(): void
275
275
$ this ->analyzeFile ('somefile.php ' , new Context ());
276
276
}
277
277
278
+ public function testConcatenationWithIntInStrictMode (): void
279
+ {
280
+ $ config = Config::getInstance ();
281
+ $ config ->strict_binary_operands = true ;
282
+
283
+ $ this ->addFile (
284
+ 'somefile.php ' ,
285
+ '<?php
286
+ $a = "hi" . 5; ' ,
287
+ );
288
+
289
+ $ this ->analyzeFile ('somefile.php ' , new Context ());
290
+ }
291
+
292
+ public function testConcatenationWithArrayKeyInStrictMode (): void
293
+ {
294
+ $ config = Config::getInstance ();
295
+ $ config ->strict_binary_operands = true ;
296
+
297
+ $ this ->addFile (
298
+ 'somefile.php ' ,
299
+ '<?php
300
+ interface I {
301
+ /** @return array-key */
302
+ public function t();
303
+ }
304
+
305
+ function test(I $i): void {
306
+ $a = "hi" . $i->t();
307
+ }
308
+ ' ,
309
+ );
310
+
311
+ $ this ->analyzeFile ('somefile.php ' , new Context ());
312
+ }
313
+
314
+ public function testConcatenationWithAllowedUnionTypeInStrictMode (): void
315
+ {
316
+ $ config = Config::getInstance ();
317
+ $ config ->strict_binary_operands = true ;
318
+
319
+ $ this ->addFile (
320
+ 'somefile.php ' ,
321
+ '<?php
322
+ interface I {
323
+ /** @return int|string */
324
+ public function t();
325
+ }
326
+
327
+ function test(I $i): void {
328
+ $a = "hi" . $i->t();
329
+ }
330
+ ' ,
331
+ );
332
+
333
+ $ this ->analyzeFile ('somefile.php ' , new Context ());
334
+ }
335
+
336
+ public function testConcatenationWithBadUnionTypeInStrictMode (): void
337
+ {
338
+ $ config = Config::getInstance ();
339
+ $ config ->strict_binary_operands = true ;
340
+
341
+ $ this ->addFile (
342
+ 'somefile.php ' ,
343
+ '<?php
344
+ interface I {
345
+ /** @return int|float */
346
+ public function t();
347
+ }
348
+
349
+ function test(I $i): void {
350
+ $a = "hi" . $i->t();
351
+ }
352
+ ' ,
353
+ );
354
+ $ this ->expectException (CodeException::class);
355
+ $ this ->expectExceptionMessage ('InvalidOperand ' );
356
+
357
+ $ this ->analyzeFile ('somefile.php ' , new Context ());
358
+ }
359
+
278
360
public function testImplicitStringConcatenation (): void
279
361
{
280
362
$ config = Config::getInstance ();
0 commit comments