Skip to content

Commit ef5795e

Browse files
committed
Added tests for the PropertyAnalyzer for both classes and traits.
1 parent 4e77291 commit ef5795e

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
namespace PHPSemVerChecker\Test\Analyzer;
4+
5+
use PhpParser\Node\Stmt\Class_;
6+
use PhpParser\Node\Stmt\Property;
7+
use PhpParser\Node\Stmt\PropertyProperty;
8+
use PHPSemVerChecker\Analyzer\PropertyAnalyzer;
9+
use PHPSemVerChecker\SemanticVersioning\Level;
10+
use PHPSemVerChecker\Test\Assertion\Assert;
11+
use PHPSemVerChecker\Test\TestCase;
12+
13+
class ClassPropertyAnalyzerTest extends TestCase {
14+
public function testCompareSimilarProperty()
15+
{
16+
$classBefore = new Class_('tmp', [
17+
'stmts' => [
18+
new Property(Class_::MODIFIER_PUBLIC, [
19+
new PropertyProperty('tmpProperty'),
20+
]),
21+
],
22+
]);
23+
24+
$classAfter = new Class_('tmp', [
25+
'stmts' => [
26+
new Property(Class_::MODIFIER_PUBLIC, [
27+
new PropertyProperty('tmpProperty'),
28+
]),
29+
],
30+
]);
31+
32+
$analyzer = new PropertyAnalyzer('class');
33+
$report = $analyzer->analyze($classBefore, $classAfter);
34+
35+
Assert::assertNoDifference($report);
36+
}
37+
38+
public function testV006PublicPropertyRemoved()
39+
{
40+
$classBefore = new Class_('tmp', [
41+
'stmts' => [
42+
new Property(Class_::MODIFIER_PUBLIC, [
43+
new PropertyProperty('tmpProperty'),
44+
]),
45+
],
46+
]);
47+
48+
$classAfter = new Class_('tmp');
49+
50+
$analyzer = new PropertyAnalyzer('class');
51+
$report = $analyzer->analyze($classBefore, $classAfter);
52+
53+
Assert::assertDifference($report, 'class', Level::MAJOR);
54+
$this->assertSame('Property has been removed.', $report['class'][Level::MAJOR][0]->getReason());
55+
$this->assertSame('tmp::$tmpProperty', $report['class'][Level::MAJOR][0]->getTarget());
56+
}
57+
58+
public function testV015PropertyAdded()
59+
{
60+
$classBefore = new Class_('tmp');
61+
62+
$classAfter = new Class_('tmp', [
63+
'stmts' => [
64+
new Property(Class_::MODIFIER_PUBLIC, [
65+
new PropertyProperty('tmpProperty'),
66+
]),
67+
],
68+
]);
69+
70+
$analyzer = new PropertyAnalyzer('class');
71+
$report = $analyzer->analyze($classBefore, $classAfter);
72+
73+
Assert::assertDifference($report, 'class', Level::MAJOR);
74+
$this->assertSame('Property has been added.', $report['class'][Level::MAJOR][0]->getReason());
75+
$this->assertSame('tmp::$tmpProperty', $report['class'][Level::MAJOR][0]->getTarget());
76+
}
77+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
namespace PHPSemVerChecker\Test\Analyzer;
4+
5+
use PhpParser\Node\Stmt\Class_;
6+
use PhpParser\Node\Stmt\Trait_;
7+
use PhpParser\Node\Stmt\Property;
8+
use PhpParser\Node\Stmt\PropertyProperty;
9+
use PHPSemVerChecker\Analyzer\PropertyAnalyzer;
10+
use PHPSemVerChecker\SemanticVersioning\Level;
11+
use PHPSemVerChecker\Test\Assertion\Assert;
12+
use PHPSemVerChecker\Test\TestCase;
13+
14+
class TraitPropertyAnalyzerTest extends TestCase {
15+
public function testCompareSimilarProperty()
16+
{
17+
$traitBefore = new Trait_('tmp', [
18+
new Property(Class_::MODIFIER_PUBLIC, [
19+
new PropertyProperty('tmpProperty'),
20+
]),
21+
]);
22+
23+
$traitAfter = new Trait_('tmp', [
24+
new Property(Class_::MODIFIER_PUBLIC, [
25+
new PropertyProperty('tmpProperty'),
26+
]),
27+
]);
28+
29+
$analyzer = new PropertyAnalyzer('trait');
30+
$report = $analyzer->analyze($traitBefore, $traitAfter);
31+
32+
Assert::assertNoDifference($report);
33+
}
34+
35+
public function testV006PublicPropertyRemoved()
36+
{
37+
$traitBefore = new Trait_('tmp', [
38+
new Property(Class_::MODIFIER_PUBLIC, [
39+
new PropertyProperty('tmpProperty'),
40+
]),
41+
]);
42+
43+
$traitAfter = new Trait_('tmp');
44+
45+
$analyzer = new PropertyAnalyzer('trait');
46+
$report = $analyzer->analyze($traitBefore, $traitAfter);
47+
48+
Assert::assertDifference($report, 'trait', Level::MAJOR);
49+
$this->assertSame('Property has been removed.', $report['trait'][Level::MAJOR][0]->getReason());
50+
$this->assertSame('tmp::$tmpProperty', $report['trait'][Level::MAJOR][0]->getTarget());
51+
}
52+
53+
public function testV015PropertyAdded()
54+
{
55+
$traitBefore = new Trait_('tmp');
56+
57+
$traitAfter = new Trait_('tmp', [
58+
new Property(Class_::MODIFIER_PUBLIC, [
59+
new PropertyProperty('tmpProperty'),
60+
]),
61+
]);
62+
63+
$analyzer = new PropertyAnalyzer('trait');
64+
$report = $analyzer->analyze($traitBefore, $traitAfter);
65+
66+
Assert::assertDifference($report, 'trait', Level::MAJOR);
67+
$this->assertSame('Property has been added.', $report['trait'][Level::MAJOR][0]->getReason());
68+
$this->assertSame('tmp::$tmpProperty', $report['trait'][Level::MAJOR][0]->getTarget());
69+
}
70+
}

0 commit comments

Comments
 (0)