diff --git a/bin/roave-backward-compatibility-check.php b/bin/roave-backward-compatibility-check.php index ce6d1e6d..6f2a3714 100644 --- a/bin/roave-backward-compatibility-check.php +++ b/bin/roave-backward-compatibility-check.php @@ -14,6 +14,7 @@ use Roave\BackwardCompatibility\CompareClasses; use Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassBased; use Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassConstantBased; +use Roave\BackwardCompatibility\DetectChanges\BCBreak\EnumBased\CaseAdded; use Roave\BackwardCompatibility\DetectChanges\BCBreak\FunctionBased; use Roave\BackwardCompatibility\DetectChanges\BCBreak\InterfaceBased; use Roave\BackwardCompatibility\DetectChanges\BCBreak\MethodBased; @@ -312,6 +313,7 @@ static function (string $installationPath) use ($composerIo): Installer { ), )), ))), + new CaseAdded(), ), ); diff --git a/src/CompareClasses.php b/src/CompareClasses.php index 2378ef8b..787cb489 100644 --- a/src/CompareClasses.php +++ b/src/CompareClasses.php @@ -10,6 +10,7 @@ use Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassBased\ClassBased; use Roave\BackwardCompatibility\DetectChanges\BCBreak\InterfaceBased\InterfaceBased; use Roave\BackwardCompatibility\DetectChanges\BCBreak\TraitBased\TraitBased; +use Roave\BackwardCompatibility\DetectChanges\BCBreak\EnumBased\EnumBased; use Roave\BetterReflection\Reflection\ReflectionClass; use Roave\BetterReflection\Reflector\Exception\IdentifierNotFound; use Roave\BetterReflection\Reflector\Reflector; @@ -20,6 +21,7 @@ public function __construct( private ClassBased $classBasedComparisons, private InterfaceBased $interfaceBasedComparisons, private TraitBased $traitBasedComparisons, + private EnumBased $enumBasedComparisons, ) { } @@ -89,6 +91,12 @@ private function examineSymbol( return; } + if ($oldSymbol->isEnum()) { + yield from ($this->enumBasedComparisons)($oldSymbol, $newClass); + + return; + } + yield from ($this->classBasedComparisons)($oldSymbol, $newClass); } diff --git a/src/DetectChanges/BCBreak/ClassBased/EnumCaseAdded.php b/src/DetectChanges/BCBreak/EnumBased/CaseAdded.php similarity index 90% rename from src/DetectChanges/BCBreak/ClassBased/EnumCaseAdded.php rename to src/DetectChanges/BCBreak/EnumBased/CaseAdded.php index 4259e1f5..4c5093b2 100644 --- a/src/DetectChanges/BCBreak/ClassBased/EnumCaseAdded.php +++ b/src/DetectChanges/BCBreak/EnumBased/CaseAdded.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassBased; +namespace Roave\BackwardCompatibility\DetectChanges\BCBreak\EnumBased; use Roave\BackwardCompatibility\Change; use Roave\BackwardCompatibility\Changes; @@ -10,7 +10,7 @@ use Roave\BetterReflection\Reflection\ReflectionEnum; use Roave\BetterReflection\Reflection\ReflectionEnumCase; -class EnumCaseAdded implements ClassBased +class CaseAdded implements EnumBased { public function __invoke(ReflectionClass $fromEnum, ReflectionClass $toEnum): Changes { diff --git a/src/DetectChanges/BCBreak/EnumBased/EnumBased.php b/src/DetectChanges/BCBreak/EnumBased/EnumBased.php new file mode 100644 index 00000000..73fb8b72 --- /dev/null +++ b/src/DetectChanges/BCBreak/EnumBased/EnumBased.php @@ -0,0 +1,11 @@ +classBasedComparison = $this->createMock(ClassBased::class); $this->interfaceBasedComparison = $this->createMock(InterfaceBased::class); $this->traitBasedComparison = $this->createMock(TraitBased::class); + $this->enumBasedComparison = $this->createMock(EnumBased::class); $this->compareClasses = new CompareClasses( $this->classBasedComparison, $this->interfaceBasedComparison, $this->traitBasedComparison, + $this->enumBasedComparison, ); } diff --git a/test/unit/DetectChanges/BCBreak/ClassBased/EnumCaseAddedTest.php b/test/unit/DetectChanges/BCBreak/EnumBased/EnumCaseAddedTest.php similarity index 68% rename from test/unit/DetectChanges/BCBreak/ClassBased/EnumCaseAddedTest.php rename to test/unit/DetectChanges/BCBreak/EnumBased/EnumCaseAddedTest.php index 9dadc1ce..af7fa1d4 100644 --- a/test/unit/DetectChanges/BCBreak/ClassBased/EnumCaseAddedTest.php +++ b/test/unit/DetectChanges/BCBreak/EnumBased/EnumCaseAddedTest.php @@ -2,26 +2,17 @@ declare(strict_types=1); -namespace RoaveTest\BackwardCompatibility\DetectChanges\BCBreak\ClassBased; +namespace RoaveTest\BackwardCompatibility\DetectChanges\BCBreak\EnumBased; use PHPUnit\Framework\TestCase; use Roave\BackwardCompatibility\Change; -use Roave\BackwardCompatibility\Changes; -use Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassBased\ClassBecameTrait; -use Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassBased\EnumCaseAdded; -use Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassBased\MethodChanged; -use Roave\BackwardCompatibility\DetectChanges\BCBreak\MethodBased\MethodBased; +use Roave\BackwardCompatibility\DetectChanges\BCBreak\EnumBased\CaseAdded; use Roave\BetterReflection\BetterReflection; use Roave\BetterReflection\Reflection\ReflectionClass; -use Roave\BetterReflection\Reflection\ReflectionMethod; use Roave\BetterReflection\Reflector\DefaultReflector; use Roave\BetterReflection\SourceLocator\Type\SingleFileSourceLocator; -use Roave\BetterReflection\SourceLocator\Type\StringSourceLocator; -use RoaveTest\BackwardCompatibility\Assertion; -use function strtolower; - -/** @covers \Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassBased\EnumCaseAdded */ +/** @covers \Roave\BackwardCompatibility\DetectChanges\BCBreak\EnumBased\CaseAdded */ final class EnumCaseAddedTest extends TestCase { /** @@ -35,7 +26,7 @@ public function testDiffs( array $expectedMessages, ): void { - $changes = (new EnumCaseAdded())($fromEnum, $toEnum); + $changes = (new CaseAdded())($fromEnum, $toEnum); self::assertSame( $expectedMessages, @@ -58,11 +49,11 @@ public function enumsToBeTested() (new DefaultReflector(new SingleFileSourceLocator( __DIR__ . '/../../../../asset/api/old/EnumWithCasesBeingAdded.php', $locator, - )))->reflectClass(\RoaveTestAsset\EnumWithCasesBeingAdded::class), + )))->reflectClass('RoaveTestAsset\EnumWithCasesBeingAdded'), (new DefaultReflector(new SingleFileSourceLocator( __DIR__ . '/../../../../asset/api/new/EnumWithCasesBeingAdded.php', $locator, - )))->reflectClass(\RoaveTestAsset\EnumWithCasesBeingAdded::class), + )))->reflectClass('RoaveTestAsset\EnumWithCasesBeingAdded'), [ '[BC] ADDED: Case RoaveTestAsset\EnumWithCasesBeingAdded::January was added', '[BC] ADDED: Case RoaveTestAsset\EnumWithCasesBeingAdded::February was added',