| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Symplify\DefaultAutowire\Tests\Config\Definition; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use PHPUnit\Framework\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Symfony\Component\DependencyInjection\ContainerBuilder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Symplify\DefaultAutowire\Config\Definition\ConfigurationResolver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Symplify\DefaultAutowire\SymplifyDefaultAutowireBundle; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | final class ConfigurationResolverTest extends TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |      * @var ConfigurationResolver | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     private $configurationResolver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     protected function setUp() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         $this->configurationResolver = new ConfigurationResolver(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     public function testResolveDefaults() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         $resolvedConfiguration = $this->configurationResolver->resolveFromContainerBuilder(new ContainerBuilder()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $this->assertCount(6, $resolvedConfiguration['autowire_types']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         $this->assertSame([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |             'autowire_types' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |                 'Doctrine\ORM\EntityManager' => 'doctrine.orm.default_entity_manager', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |                 'Doctrine\ORM\EntityManagerInterface' => 'doctrine.orm.default_entity_manager', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |                 'Doctrine\Portability\Connection' => 'database_connection', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |                 'Symfony\Component\EventDispatcher\EventDispatcher' => 'event_dispatcher', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |                 'Symfony\Component\EventDispatcher\EventDispatcherInterface' => 'event_dispatcher', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |                 'Symfony\Component\Translation\TranslatorInterface' => 'translator', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         ], $resolvedConfiguration); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 39 |  | View Code Duplication |     public function testOverrideDefaults() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $containerBuilder = new ContainerBuilder(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $containerBuilder->prependExtensionConfig(SymplifyDefaultAutowireBundle::ALIAS, [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             'autowire_types' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |                 'Doctrine\ORM\EntityManager' => 'other_entity_manager', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $resolvedConfiguration = $this->configurationResolver->resolveFromContainerBuilder( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             $containerBuilder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $autowireTypes = $resolvedConfiguration['autowire_types']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $this->assertCount(6, $autowireTypes); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $this->assertSame('other_entity_manager', $autowireTypes['Doctrine\ORM\EntityManager']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 58 |  | View Code Duplication |     public function testAddNewValues() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $containerBuilder = new ContainerBuilder(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $containerBuilder->prependExtensionConfig(SymplifyDefaultAutowireBundle::ALIAS, [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             'autowire_types' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |                 'SomeInterface' => 'some_service', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         $resolvedConfiguration = $this->configurationResolver->resolveFromContainerBuilder( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             $containerBuilder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $autowireTypes = $resolvedConfiguration['autowire_types']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $this->assertCount(7, $autowireTypes); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $this->assertSame('some_service', $autowireTypes['SomeInterface']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 77 |  |  |     public function testCache() | 
            
                                                        
            
                                    
            
            
                | 78 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 79 |  |  |         $resolvedConfiguration = $this->configurationResolver->resolveFromContainerBuilder(new ContainerBuilder()); | 
            
                                                        
            
                                    
            
            
                | 80 |  |  |         $resolvedConfiguration2 = $this->configurationResolver->resolveFromContainerBuilder(new ContainerBuilder()); | 
            
                                                        
            
                                    
            
            
                | 81 |  |  |         $this->assertSame($resolvedConfiguration, $resolvedConfiguration2); | 
            
                                                        
            
                                    
            
            
                | 82 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 83 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 84 |  |  |  | 
            
                        
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.