Skip to content

Commit c896df0

Browse files
committed
Update trait-related tests to use the new Trait_ constructor (which expects subnodes instead of stmts).
Assert returned code in analyzer tests.
1 parent 4666578 commit c896df0

File tree

5 files changed

+92
-54
lines changed

5 files changed

+92
-54
lines changed

tests/PHPSemVerChecker/Analyzer/ClassAnalyzerTest.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,39 @@ public function testSimilarClasses()
2727
Assert::assertNoDifference($report);
2828
}
2929

30-
public function testV005ClassRemoved()
30+
public function testClassAdded()
3131
{
3232
$before = new Registry();
3333
$after = new Registry();
3434

35-
$before->addClass(new Class_('tmp'));
35+
$after->addClass(new Class_('tmp'));
3636

3737
$analyzer = new ClassAnalyzer();
3838
$report = $analyzer->analyze($before, $after);
3939

40-
Assert::assertDifference($report, 'class', Level::MAJOR);
41-
$this->assertSame('Class was removed.', $report['class'][Level::MAJOR][0]->getReason());
42-
$this->assertSame('tmp', $report['class'][Level::MAJOR][0]->getTarget());
40+
$context = 'class';
41+
$expectedLevel = Level::MINOR;
42+
Assert::assertDifference($report, $context, $expectedLevel);
43+
$this->assertSame('V014', $report[$context][$expectedLevel][0]->getCode());
44+
$this->assertSame('Class was added.', $report[$context][$expectedLevel][0]->getReason());
45+
$this->assertSame('tmp', $report[$context][$expectedLevel][0]->getTarget());
4346
}
4447

45-
public function testV014ClassAdded()
48+
public function testClassRemoved()
4649
{
4750
$before = new Registry();
4851
$after = new Registry();
4952

50-
$after->addClass(new Class_('tmp'));
53+
$before->addClass(new Class_('tmp'));
5154

5255
$analyzer = new ClassAnalyzer();
5356
$report = $analyzer->analyze($before, $after);
5457

55-
Assert::assertDifference($report, 'class', Level::MINOR);
56-
$this->assertSame('Class was added.', $report['class'][Level::MINOR][0]->getReason());
57-
$this->assertSame('tmp', $report['class'][Level::MINOR][0]->getTarget());
58+
$context = 'class';
59+
$expectedLevel = Level::MAJOR;
60+
Assert::assertDifference($report, $context, $expectedLevel);
61+
$this->assertSame('V005', $report[$context][$expectedLevel][0]->getCode());
62+
$this->assertSame('Class was removed.', $report[$context][$expectedLevel][0]->getReason());
63+
$this->assertSame('tmp', $report[$context][$expectedLevel][0]->getTarget());
5864
}
5965
}

tests/PHPSemVerChecker/Analyzer/ClassPropertyAnalyzerTest.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testCompareSimilarProperty()
3535
Assert::assertNoDifference($report);
3636
}
3737

38-
public function testV008PublicPropertyRemoved()
38+
public function testPublicPropertyRemoved()
3939
{
4040
$classBefore = new Class_('tmp', [
4141
'stmts' => [
@@ -50,12 +50,15 @@ public function testV008PublicPropertyRemoved()
5050
$analyzer = new PropertyAnalyzer('class');
5151
$report = $analyzer->analyze($classBefore, $classAfter);
5252

53-
Assert::assertDifference($report, 'class', Level::MAJOR);
54-
$this->assertSame('[public] Property has been removed.', $report['class'][Level::MAJOR][0]->getReason());
55-
$this->assertSame('tmp::$tmpProperty', $report['class'][Level::MAJOR][0]->getTarget());
53+
$context = 'class';
54+
$expectedLevel = Level::MAJOR;
55+
Assert::assertDifference($report, $context, $expectedLevel);
56+
$this->assertSame('V008', $report[$context][$expectedLevel][0]->getCode());
57+
$this->assertSame('[public] Property has been removed.', $report[$context][$expectedLevel][0]->getReason());
58+
$this->assertSame('tmp::$tmpProperty', $report[$context][$expectedLevel][0]->getTarget());
5659
}
5760

58-
public function testV019PropertyAdded()
61+
public function testPropertyAdded()
5962
{
6063
$classBefore = new Class_('tmp');
6164

@@ -70,8 +73,11 @@ public function testV019PropertyAdded()
7073
$analyzer = new PropertyAnalyzer('class');
7174
$report = $analyzer->analyze($classBefore, $classAfter);
7275

73-
Assert::assertDifference($report, 'class', Level::MAJOR);
74-
$this->assertSame('[public] Property has been added.', $report['class'][Level::MAJOR][0]->getReason());
75-
$this->assertSame('tmp::$tmpProperty', $report['class'][Level::MAJOR][0]->getTarget());
76+
$context = 'class';
77+
$expectedLevel = Level::MAJOR;
78+
Assert::assertDifference($report, $context, $expectedLevel);
79+
$this->assertSame('V019', $report[$context][$expectedLevel][0]->getCode());
80+
$this->assertSame('[public] Property has been added.', $report[$context][$expectedLevel][0]->getReason());
81+
$this->assertSame('tmp::$tmpProperty', $report[$context][$expectedLevel][0]->getTarget());
7682
}
7783
}

tests/PHPSemVerChecker/Analyzer/InterfaceAnalyzerTest.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testCompareSimilarInterface()
2727
Assert::assertNoDifference($report);
2828
}
2929

30-
public function testV033InterfaceRemoved()
30+
public function testInterfaceRemoved()
3131
{
3232
$before = new Registry();
3333
$after = new Registry();
@@ -37,12 +37,15 @@ public function testV033InterfaceRemoved()
3737
$analyzer = new InterfaceAnalyzer();
3838
$report = $analyzer->analyze($before, $after);
3939

40-
Assert::assertDifference($report, 'interface', Level::MAJOR);
41-
$this->assertSame('Interface was removed.', $report['interface'][Level::MAJOR][0]->getReason());
42-
$this->assertSame('tmp', $report['interface'][Level::MAJOR][0]->getTarget());
40+
$context = 'interface';
41+
$expectedLevel = Level::MAJOR;
42+
Assert::assertDifference($report, $context, $expectedLevel);
43+
$this->assertSame('V033', $report[$context][$expectedLevel][0]->getCode());
44+
$this->assertSame('Interface was removed.', $report[$context][$expectedLevel][0]->getReason());
45+
$this->assertSame('tmp', $report[$context][$expectedLevel][0]->getTarget());
4346
}
4447

45-
public function testV032InterfaceAdded()
48+
public function testInterfaceAdded()
4649
{
4750
$before = new Registry();
4851
$after = new Registry();
@@ -52,8 +55,11 @@ public function testV032InterfaceAdded()
5255
$analyzer = new InterfaceAnalyzer();
5356
$report = $analyzer->analyze($before, $after);
5457

55-
Assert::assertDifference($report, 'interface', Level::MINOR);
56-
$this->assertSame('Interface was added.', $report['interface'][Level::MINOR][0]->getReason());
57-
$this->assertSame('tmp', $report['interface'][Level::MINOR][0]->getTarget());
58+
$context = 'interface';
59+
$expectedLevel = Level::MINOR;
60+
Assert::assertDifference($report, $context, $expectedLevel);
61+
$this->assertSame('V032', $report[$context][$expectedLevel][0]->getCode());
62+
$this->assertSame('Interface was added.', $report[$context][$expectedLevel][0]->getReason());
63+
$this->assertSame('tmp', $report[$context][$expectedLevel][0]->getTarget());
5864
}
5965
}

tests/PHPSemVerChecker/Analyzer/TraitAnalyzerTest.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testCompareSimilarTrait()
2727
Assert::assertNoDifference($report);
2828
}
2929

30-
public function testV037TraitRemoved()
30+
public function testTraitRemoved()
3131
{
3232
$before = new Registry();
3333
$after = new Registry();
@@ -37,12 +37,15 @@ public function testV037TraitRemoved()
3737
$analyzer = new TraitAnalyzer();
3838
$report = $analyzer->analyze($before, $after);
3939

40-
Assert::assertDifference($report, 'trait', Level::MAJOR);
41-
$this->assertSame('Trait was removed.', $report['trait'][Level::MAJOR][0]->getReason());
42-
$this->assertSame('tmp', $report['trait'][Level::MAJOR][0]->getTarget());
40+
$context = 'trait';
41+
$expectedLevel = Level::MAJOR;
42+
Assert::assertDifference($report, $context, $expectedLevel);
43+
$this->assertSame('V037', $report[$context][$expectedLevel][0]->getCode());
44+
$this->assertSame('Trait was removed.', $report[$context][$expectedLevel][0]->getReason());
45+
$this->assertSame('tmp', $report[$context][$expectedLevel][0]->getTarget());
4346
}
4447

45-
public function testV046TraitAdded()
48+
public function testTraitAdded()
4649
{
4750
$before = new Registry();
4851
$after = new Registry();
@@ -52,8 +55,11 @@ public function testV046TraitAdded()
5255
$analyzer = new TraitAnalyzer();
5356
$report = $analyzer->analyze($before, $after);
5457

55-
Assert::assertDifference($report, 'trait', Level::MINOR);
56-
$this->assertSame('Trait was added.', $report['trait'][Level::MINOR][0]->getReason());
57-
$this->assertSame('tmp', $report['trait'][Level::MINOR][0]->getTarget());
58+
$context = 'trait';
59+
$expectedLevel = Level::MINOR;
60+
Assert::assertDifference($report, $context, $expectedLevel);
61+
$this->assertSame('V046', $report[$context][$expectedLevel][0]->getCode());
62+
$this->assertSame('Trait was added.', $report[$context][$expectedLevel][0]->getReason());
63+
$this->assertSame('tmp', $report[$context][$expectedLevel][0]->getTarget());
5864
}
5965
}

tests/PHPSemVerChecker/Analyzer/TraitPropertyAnalyzerTest.php

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,19 @@ class TraitPropertyAnalyzerTest extends TestCase {
1515
public function testCompareSimilarProperty()
1616
{
1717
$traitBefore = new Trait_('tmp', [
18-
new Property(Class_::MODIFIER_PUBLIC, [
19-
new PropertyProperty('tmpProperty'),
20-
]),
18+
'stmts' => [
19+
new Property(Class_::MODIFIER_PUBLIC, [
20+
new PropertyProperty('tmpProperty'),
21+
]),
22+
],
2123
]);
2224

2325
$traitAfter = new Trait_('tmp', [
24-
new Property(Class_::MODIFIER_PUBLIC, [
25-
new PropertyProperty('tmpProperty'),
26-
]),
26+
'stmts' => [
27+
new Property(Class_::MODIFIER_PUBLIC, [
28+
new PropertyProperty('tmpProperty'),
29+
]),
30+
],
2731
]);
2832

2933
$analyzer = new PropertyAnalyzer('trait');
@@ -32,39 +36,49 @@ public function testCompareSimilarProperty()
3236
Assert::assertNoDifference($report);
3337
}
3438

35-
public function testV040PublicPropertyRemoved()
39+
public function testPublicPropertyRemoved()
3640
{
3741
$traitBefore = new Trait_('tmp', [
38-
new Property(Class_::MODIFIER_PUBLIC, [
39-
new PropertyProperty('tmpProperty'),
40-
]),
42+
'stmts' => [
43+
new Property(Class_::MODIFIER_PUBLIC, [
44+
new PropertyProperty('tmpProperty'),
45+
]),
46+
],
4147
]);
4248

4349
$traitAfter = new Trait_('tmp');
4450

4551
$analyzer = new PropertyAnalyzer('trait');
4652
$report = $analyzer->analyze($traitBefore, $traitAfter);
4753

48-
Assert::assertDifference($report, 'trait', Level::MAJOR);
49-
$this->assertSame('[public] Property has been removed.', $report['trait'][Level::MAJOR][0]->getReason());
50-
$this->assertSame('tmp::$tmpProperty', $report['trait'][Level::MAJOR][0]->getTarget());
54+
$context = 'trait';
55+
$expectedLevel = Level::MAJOR;
56+
Assert::assertDifference($report, $context, $expectedLevel);
57+
$this->assertSame('V040', $report[$context][$expectedLevel][0]->getCode());
58+
$this->assertSame('[public] Property has been removed.', $report[$context][$expectedLevel][0]->getReason());
59+
$this->assertSame('tmp::$tmpProperty', $report[$context][$expectedLevel][0]->getTarget());
5160
}
5261

53-
public function testV049PropertyAdded()
62+
public function testPropertyAdded()
5463
{
5564
$traitBefore = new Trait_('tmp');
5665

5766
$traitAfter = new Trait_('tmp', [
58-
new Property(Class_::MODIFIER_PUBLIC, [
59-
new PropertyProperty('tmpProperty'),
60-
]),
67+
'stmts' => [
68+
new Property(Class_::MODIFIER_PUBLIC, [
69+
new PropertyProperty('tmpProperty'),
70+
]),
71+
],
6172
]);
6273

6374
$analyzer = new PropertyAnalyzer('trait');
6475
$report = $analyzer->analyze($traitBefore, $traitAfter);
6576

66-
Assert::assertDifference($report, 'trait', Level::MAJOR);
67-
$this->assertSame('[public] Property has been added.', $report['trait'][Level::MAJOR][0]->getReason());
68-
$this->assertSame('tmp::$tmpProperty', $report['trait'][Level::MAJOR][0]->getTarget());
77+
$context = 'trait';
78+
$expectedLevel = Level::MAJOR;
79+
Assert::assertDifference($report, $context, $expectedLevel);
80+
$this->assertSame('V049', $report[$context][$expectedLevel][0]->getCode());
81+
$this->assertSame('[public] Property has been added.', $report[$context][$expectedLevel][0]->getReason());
82+
$this->assertSame('tmp::$tmpProperty', $report[$context][$expectedLevel][0]->getTarget());
6983
}
7084
}

0 commit comments

Comments
 (0)