File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -216,4 +216,33 @@ public function testTransformerWhichAddsStrictTypesDoesNotResultInDoubleStrictTy
216
216
$ patcher ->patch ($ exercise , $ code )
217
217
);
218
218
}
219
+
220
+ public function testAddingStrictTypesDeclareDoesNotBreakBeforeInsertion (): void
221
+ {
222
+ $ code = '<?php $original = true; ' ;
223
+ $ patch = (new Patch ())
224
+ ->withTransformer (function (array $ statements ) {
225
+ return array_merge ([new \PhpParser \Node \Stmt \Declare_ ([
226
+ new DeclareDeclare (
227
+ new \PhpParser \Node \Identifier ('strict_types ' ),
228
+ new LNumber (1 )
229
+ )
230
+ ])], $ statements );
231
+ })
232
+ ->withInsertion (new Insertion (Insertion::TYPE_BEFORE , '$before = "here"; ' ));
233
+
234
+ $ patcher = new CodePatcher ((new ParserFactory ())->create (ParserFactory::PREFER_PHP7 ), new Standard ());
235
+
236
+ $ exercise = $ this ->createMock (PatchableExercise::class);
237
+
238
+ $ exercise
239
+ ->expects ($ this ->once ())
240
+ ->method ('getPatch ' )
241
+ ->willReturn ($ patch );
242
+
243
+ $ this ->assertEquals (
244
+ "<?php \n\ndeclare (strict_types=1); \n\$before = \"here \"; \n\$original = true; " ,
245
+ $ patcher ->patch ($ exercise , $ code )
246
+ );
247
+ }
219
248
}
You can’t perform that action at this time.
0 commit comments