| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace RoaveTest\ApiCompare\Comparator\BackwardsCompatibility\ClassBased; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use PHPUnit\Framework\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Roave\ApiCompare\Change; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Roave\ApiCompare\Comparator\BackwardsCompatibility\ClassBased\ClassBecameFinal; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Roave\BetterReflection\BetterReflection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Roave\BetterReflection\Reflection\ReflectionClass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Roave\BetterReflection\Reflector\ClassReflector; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Roave\BetterReflection\SourceLocator\Type\StringSourceLocator; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  | final class ClassBecameFinalTest extends TestCase | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |      * @dataProvider classesToBeTested | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |      * @param string[] $expectedMessages | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     public function testDiffs( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         ReflectionClass $fromClass, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         ReflectionClass $toClass, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         array $expectedMessages | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     ) : void { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         $changes = (new ClassBecameFinal()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |             ->compare($fromClass, $toClass); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         self::assertSame( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |             $expectedMessages, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |             array_map(function (Change $change) : string { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |                 return $change->__toString(); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 34 |  |  |             }, iterator_to_array($changes)) | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |     /** @return (string[]|ReflectionClass)[][] */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     public function classesToBeTested() : array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $locator = (new BetterReflection())->astLocator(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $fromReflector = new ClassReflector(new StringSourceLocator( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             <<<'PHP' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | class A {} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | final class B {} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | class C {} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | final class D {} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | PHP | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             , | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |             $locator | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $toReflector = new ClassReflector(new StringSourceLocator( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             <<<'PHP' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | final class A {} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | class B {} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | class C {} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | final class D {} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | PHP | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             , | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             $locator | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |             'A' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |                 $fromReflector->reflect('A'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |                 $toReflector->reflect('A'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |                 ['[BC] CHANGED: Class A became final'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             'B' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |                 $fromReflector->reflect('B'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |                 $toReflector->reflect('B'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |                 [], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |             'C' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |                 $fromReflector->reflect('C'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |                 $toReflector->reflect('C'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |                 [], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             'D' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |                 $fromReflector->reflect('D'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |                 $toReflector->reflect('D'), | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 86 |  |  |                 [], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 90 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 91 |  |  |  |