Skip to content

Commit 5a0589b

Browse files
committed
Fix tests
Add tests for PHP 7.3, 7.4, 8.0, 8.1, 8.2, 8.3, 8.4
1 parent d6424fe commit 5a0589b

File tree

12 files changed

+828
-51
lines changed

12 files changed

+828
-51
lines changed

src/PHPSemVerChecker/Scanner/Scanner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Scanner
3232
public function __construct()
3333
{
3434
$this->registry = new Registry();
35-
$this->parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
35+
$this->parser = (new ParserFactory())->createForNewestSupportedVersion();
3636
$this->traverser = new NodeTraverser();
3737

3838
$visitors = [

tests/PHPSemVerChecker/Analyzer/ClassMethodAnalyzerTest.php

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PhpParser\Node\Expr;
66
use PhpParser\Node\Expr\MethodCall;
77
use PhpParser\Node\Expr\Variable;
8+
use PhpParser\Node\Name;
89
use PhpParser\Node\Param;
910
use PhpParser\Node\Scalar;
1011
use PhpParser\Node\Scalar\String_;
@@ -258,7 +259,7 @@ public function testCompareSimilarClassMethodWithParameterAdded($context, $visib
258259
new ClassMethod('tmpMethod', [
259260
'type' => Visibility::getModifier($visibility),
260261
'params' => [
261-
new Param(new Variable('a'), null, 'A'),
262+
new Param(new Variable('a'), null, new Name('A')),
262263
],
263264
]),
264265
],
@@ -269,8 +270,8 @@ public function testCompareSimilarClassMethodWithParameterAdded($context, $visib
269270
new ClassMethod('tmpMethod', [
270271
'type' => Visibility::getModifier($visibility),
271272
'params' => [
272-
new Param(new Variable('a'), null, 'A'),
273-
new Param(new Variable('b'), null, 'B'),
273+
new Param(new Variable('a'), null, new Name('A')),
274+
new Param(new Variable('b'), null, new Name('B')),
274275
],
275276
]),
276277
],
@@ -310,8 +311,8 @@ public function testCompareSimilarClassMethodWithParameterRemoved($context, $vis
310311
new ClassMethod('tmpMethod', [
311312
'type' => Visibility::getModifier($visibility),
312313
'params' => [
313-
new Param(new Variable('a'), null, 'A'),
314-
new Param(new Variable('b'), null, 'B'),
314+
new Param(new Variable('a'), null, new Name('A')),
315+
new Param(new Variable('b'), null, new Name('B')),
315316
],
316317
]),
317318
],
@@ -322,7 +323,7 @@ public function testCompareSimilarClassMethodWithParameterRemoved($context, $vis
322323
new ClassMethod('tmpMethod', [
323324
'type' => Visibility::getModifier($visibility),
324325
'params' => [
325-
new Param(new Variable('a'), null, 'A'),
326+
new Param(new Variable('a'), null, new Name('A')),
326327
],
327328
]),
328329
],
@@ -373,7 +374,7 @@ public function testCompareSimilarClassMethodWithParameterTypehintAdded($context
373374
new ClassMethod('tmpMethod', [
374375
'type' => Visibility::getModifier($visibility),
375376
'params' => [
376-
new Param(new Variable('a'), null, 'A'),
377+
new Param(new Variable('a'), null, new Name('A')),
377378
],
378379
]),
379380
],
@@ -413,7 +414,7 @@ public function testCompareSimilarClassMethodWithParameterTypehintRemoved($conte
413414
new ClassMethod('tmpMethod', [
414415
'type' => Visibility::getModifier($visibility),
415416
'params' => [
416-
new Param(new Variable('a'), null, 'A'),
417+
new Param(new Variable('a'), null, new Name('A')),
417418
],
418419
]),
419420
],
@@ -464,8 +465,8 @@ public function testCompareSimilarClassMethodWithDefaultParameterAdded($context,
464465
new ClassMethod('tmpMethod', [
465466
'type' => Visibility::getModifier($visibility),
466467
'params' => [
467-
new Param(new Variable('a'), null, 'A'),
468-
new Param(new Variable('b'), null, 'B'),
468+
new Param(new Variable('a'), null, new Name('A')),
469+
new Param(new Variable('b'), null, new Name('B')),
469470
],
470471
]),
471472
],
@@ -476,8 +477,8 @@ public function testCompareSimilarClassMethodWithDefaultParameterAdded($context,
476477
new ClassMethod('tmpMethod', [
477478
'type' => Visibility::getModifier($visibility),
478479
'params' => [
479-
new Param(new Variable('a'), null, 'A'),
480-
new Param(new Variable('b'), new String_('someDefaultValue'), 'B'),
480+
new Param(new Variable('a'), null, new Name('A')),
481+
new Param(new Variable('b'), new String_('someDefaultValue'), new Name('B')),
481482
],
482483
]),
483484
],
@@ -517,8 +518,8 @@ public function testCompareSimilarClassMethodWithDefaultParameterRemoved($contex
517518
new ClassMethod('tmpMethod', [
518519
'type' => Visibility::getModifier($visibility),
519520
'params' => [
520-
new Param(new Variable('a'), null, 'A'),
521-
new Param(new Variable('b'), new String_('someDefaultValue'), 'B'),
521+
new Param(new Variable('a'), null, new Name('A')),
522+
new Param(new Variable('b'), new String_('someDefaultValue'), new Name('B')),
522523
],
523524
]),
524525
],
@@ -529,8 +530,8 @@ public function testCompareSimilarClassMethodWithDefaultParameterRemoved($contex
529530
new ClassMethod('tmpMethod', [
530531
'type' => Visibility::getModifier($visibility),
531532
'params' => [
532-
new Param(new Variable('a'), null, 'A'),
533-
new Param(new Variable('b'), null, 'B'),
533+
new Param(new Variable('a'), null, new Name('A')),
534+
new Param(new Variable('b'), null, new Name('B')),
534535
],
535536
]),
536537
],
@@ -570,8 +571,8 @@ public function testCompareSimilarClassMethodWithDefaultParameterValueChanged($c
570571
new ClassMethod('tmpMethod', [
571572
'type' => Visibility::getModifier($visibility),
572573
'params' => [
573-
new Param(new Variable('a'), null, 'A'),
574-
new Param(new Variable('b'), new String_('someDefaultValue'), 'B'),
574+
new Param(new Variable('a'), null, new Name('A')),
575+
new Param(new Variable('b'), new String_('someDefaultValue'), new Name('B')),
575576
],
576577
]),
577578
],
@@ -582,8 +583,8 @@ public function testCompareSimilarClassMethodWithDefaultParameterValueChanged($c
582583
new ClassMethod('tmpMethod', [
583584
'type' => Visibility::getModifier($visibility),
584585
'params' => [
585-
new Param(new Variable('a'), null, 'A'),
586-
new Param(new Variable('b'), new String_('someNewDefaultValue'), 'B'),
586+
new Param(new Variable('a'), null, new Name('A')),
587+
new Param(new Variable('b'), new String_('someNewDefaultValue'), new Name('B')),
587588
],
588589
]),
589590
],

tests/PHPSemVerChecker/Analyzer/FunctionAnalyzerTest.php

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@ public function testSimilarFunctionWithParameterAdded()
121121

122122
$before->addFunction(new Function_('tmp', [
123123
'params' => [
124-
new Param(new Variable('a'), null, 'A'),
124+
new Param(new Variable('a'), null, new Name('A')),
125125
],
126126
]));
127127

128128
$after->addFunction(new Function_('tmp', [
129129
'params' => [
130-
new Param(new Variable('a'), null, 'A'),
131-
new Param(new Variable('b'), null, 'B'),
130+
new Param(new Variable('a'), null, new Name('A')),
131+
new Param(new Variable('b'), null, new Name('B')),
132132
],
133133
]));
134134

@@ -149,14 +149,14 @@ public function testSimilarFunctionWithParameterRemoved()
149149

150150
$before->addFunction(new Function_('tmp', [
151151
'params' => [
152-
new Param(new Variable('a'), null, 'A'),
153-
new Param(new Variable('b'), null, 'B'),
152+
new Param(new Variable('a'), null, new Name('A')),
153+
new Param(new Variable('b'), null, new Name('B')),
154154
],
155155
]));
156156

157157
$after->addFunction(new Function_('tmp', [
158158
'params' => [
159-
new Param(new Variable('a'), null, 'A'),
159+
new Param(new Variable('a'), null, new Name('A')),
160160
],
161161
]));
162162

@@ -184,7 +184,7 @@ public function testSimilarFunctionWithParameterTypehintAdded()
184184

185185
$after->addFunction(new Function_('tmp', [
186186
'params' => [
187-
new Param(new Variable('a'), null, 'A'),
187+
new Param(new Variable('a'), null, new Name('A')),
188188
],
189189
]));
190190

@@ -205,7 +205,7 @@ public function testSimilarFunctionWithParameterTypehintRemoved()
205205

206206
$before->addFunction(new Function_('tmp', [
207207
'params' => [
208-
new Param(new Variable('a'), null, 'A'),
208+
new Param(new Variable('a'), null, new Name('A')),
209209
],
210210
]));
211211

@@ -232,15 +232,15 @@ public function testSimilarFunctionWithDefaultParameterAdded()
232232

233233
$before->addFunction(new Function_('tmp', [
234234
'params' => [
235-
new Param(new Variable('a'), null, 'A'),
236-
new Param(new Variable('b'), null, 'B'),
235+
new Param(new Variable('a'), null, new Name('A')),
236+
new Param(new Variable('b'), null, new Name('B')),
237237
],
238238
]));
239239

240240
$after->addFunction(new Function_('tmp', [
241241
'params' => [
242-
new Param(new Variable('a'), null, 'A'),
243-
new Param(new Variable('b'), new String_('someDefaultValue'), 'B'),
242+
new Param(new Variable('a'), null, new Name('A')),
243+
new Param(new Variable('b'), new String_('someDefaultValue'), new Name('B')),
244244
],
245245
]));
246246

@@ -261,15 +261,15 @@ public function testSimilarFunctionWithDefaultParameterRemoved()
261261

262262
$before->addFunction(new Function_('tmp', [
263263
'params' => [
264-
new Param(new Variable('a'), null, 'A'),
265-
new Param(new Variable('b'), new String_('someDefaultValue'), 'B'),
264+
new Param(new Variable('a'), null, new Name('A')),
265+
new Param(new Variable('b'), new String_('someDefaultValue'), new Name('B')),
266266
],
267267
]));
268268

269269
$after->addFunction(new Function_('tmp', [
270270
'params' => [
271-
new Param(new Variable('a'), null, 'A'),
272-
new Param(new Variable('a'), null, 'B'),
271+
new Param(new Variable('a'), null, new Name('A')),
272+
new Param(new Variable('a'), null, new Name('B')),
273273
],
274274
]));
275275

@@ -290,15 +290,15 @@ public function testSimilarFunctionWithDefaultParameterValueChanged()
290290

291291
$before->addFunction(new Function_('tmp', [
292292
'params' => [
293-
new Param(new Variable('a'), null, 'A'),
294-
new Param(new Variable('b'), new String_('someDefaultValue'), 'B'),
293+
new Param(new Variable('a'), null, new Name('A')),
294+
new Param(new Variable('b'), new String_('someDefaultValue'), new Name('B')),
295295
],
296296
]));
297297

298298
$after->addFunction(new Function_('tmp', [
299299
'params' => [
300-
new Param(new Variable('a'), null, 'A'),
301-
new Param(new Variable('a'), new String_('someNewDefaultValue'), 'B'),
300+
new Param(new Variable('a'), null, new Name('A')),
301+
new Param(new Variable('a'), new String_('someNewDefaultValue'), new Name('B')),
302302
],
303303
]));
304304

@@ -319,14 +319,14 @@ public function testSimilarFunctionWithParameterAddedWithDefault()
319319

320320
$before->addFunction(new Function_('tmp', [
321321
'params' => [
322-
new Param(new Variable('a'), null, 'A'),
322+
new Param(new Variable('a'), null, new Name('A')),
323323
],
324324
]));
325325

326326
$after->addFunction(new Function_('tmp', [
327327
'params' => [
328-
new Param(new Variable('a'), null, 'A'),
329-
new Param(new Variable('a'), new String_('someDefaultValue'), 'B'),
328+
new Param(new Variable('a'), null, new Name('A')),
329+
new Param(new Variable('a'), new String_('someDefaultValue'), new Name('B')),
330330
],
331331
]));
332332

@@ -350,13 +350,13 @@ public function testSimilarFunctionImplementation()
350350

351351
$before->addFunction(new Function_('tmp', [
352352
'stmts' => [
353-
new FuncCall('someFunction'),
353+
new FuncCall(new Name('someFunction')),
354354
],
355355
]));
356356

357357
$after->addFunction(new Function_('tmp', [
358358
'stmts' => [
359-
new FuncCall('someFunction'),
359+
new FuncCall(new Name('someFunction')),
360360
],
361361
]));
362362

@@ -373,13 +373,13 @@ public function testFunctionImplementationChanged()
373373

374374
$before->addFunction(new Function_('tmp', [
375375
'stmts' => [
376-
new FuncCall('someFunction'),
376+
new FuncCall(new Name('someFunction')),
377377
],
378378
]));
379379

380380
$after->addFunction(new Function_('tmp', [
381381
'stmts' => [
382-
new FuncCall('someOtherFunction'),
382+
new FuncCall(new Name('someOtherFunction')),
383383
],
384384
]));
385385

@@ -400,13 +400,13 @@ public function testFunctionCaseChanged()
400400

401401
$before->addFunction(new Function_('somefunctionname', [
402402
'stmts' => [
403-
new FuncCall('someFunctionCall'),
403+
new FuncCall(new Name('someFunctionCall')),
404404
],
405405
]));
406406

407407
$after->addFunction(new Function_('someFunctionName', [
408408
'stmts' => [
409-
new FuncCall('someFunctionCall'),
409+
new FuncCall(new Name('someFunctionCall')),
410410
],
411411
]));
412412

tests/PHPSemVerChecker/Comparator/TypeComparatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function getProvider()
6161
[null, null],
6262
['test', 'test'],
6363
[Name::concat('namespaced', 'test'), 'namespaced\test'],
64-
[new NullableType('test'), '?test'],
64+
[new NullableType(new Identifier('test')), '?test'],
6565
[new NullableType(Name::concat('namespaced', 'test')), '?namespaced\test'],
6666
[new UnionType([new Identifier('self'), new Identifier('array')]), 'array|self'],
6767
];

tests/PHPSemVerChecker/Scanner/ScannerTest.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,60 @@ public function testPHP72()
4444

4545
$this->assertTrue(true);
4646
}
47+
48+
public function testPHP73()
49+
{
50+
$scanner = new Scanner();
51+
$scanner->scan(__DIR__.'/../../fixtures/general/PHP7.3.php');
52+
53+
$this->assertTrue(true);
54+
}
55+
56+
public function testPHP74()
57+
{
58+
$scanner = new Scanner();
59+
$scanner->scan(__DIR__.'/../../fixtures/general/PHP7.4.php');
60+
61+
$this->assertTrue(true);
62+
}
63+
64+
public function testPHP80()
65+
{
66+
$scanner = new Scanner();
67+
$scanner->scan(__DIR__.'/../../fixtures/general/PHP8.0.php');
68+
69+
$this->assertTrue(true);
70+
}
71+
72+
public function testPHP81()
73+
{
74+
$scanner = new Scanner();
75+
$scanner->scan(__DIR__.'/../../fixtures/general/PHP8.1.php');
76+
77+
$this->assertTrue(true);
78+
}
79+
80+
public function testPHP82()
81+
{
82+
$scanner = new Scanner();
83+
$scanner->scan(__DIR__.'/../../fixtures/general/PHP8.2.php');
84+
85+
$this->assertTrue(true);
86+
}
87+
88+
public function testPHP83()
89+
{
90+
$scanner = new Scanner();
91+
$scanner->scan(__DIR__.'/../../fixtures/general/PHP8.3.php');
92+
93+
$this->assertTrue(true);
94+
}
95+
96+
public function testPHP84()
97+
{
98+
$scanner = new Scanner();
99+
$scanner->scan(__DIR__.'/../../fixtures/general/PHP8.4.php');
100+
101+
$this->assertTrue(true);
102+
}
47103
}

0 commit comments

Comments
 (0)