|
| 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