| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Symplify\DefaultAutowire\Tests; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Doctrine\ORM\EntityManagerInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use PHPUnit_Framework_TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Symfony\Component\DependencyInjection\Container; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Symfony\Component\EventDispatcher\EventDispatcher; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Symfony\Component\EventDispatcher\EventDispatcherInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Symplify\DefaultAutowire\Tests\Resources\Repository\SomeRepository; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Symplify\DefaultAutowire\Tests\Source\SomeAutowiredService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Symplify\DefaultAutowire\Tests\Source\SomeService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | final class CompleteTest extends PHPUnit_Framework_TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      * @var Container | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     private $container; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     protected function setUp() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     { | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 24 |  |  |         $kernel = new AppKernel('test_env', true); | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |         $kernel->boot(); | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |         $this->container = $kernel->getContainer(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |     public function testSomeServiceAutowire() | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         /** @var SomeAutowiredService $someAutowiredService */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $someAutowiredService = $this->container->get('some_autowired_service'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $this->assertInstanceOf(SomeAutowiredService::class, $someAutowiredService); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $this->assertInstanceOf(SomeService::class, $someAutowiredService->getSomeService()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $this->assertInstanceOf(EventDispatcherInterface::class, $someAutowiredService->getEventDispatcher()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $this->assertInstanceOf(EventDispatcher::class, $someAutowiredService->getEventDispatcher()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $this->assertNotInstanceOf(TraceableEventDispatcher::class, $someAutowiredService->getEventDispatcher()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     public function testRepositoryAutowire() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         /** @var SomeRepository $someRepository */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $someRepository = $this->container->get('some_repository'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $this->assertInstanceOf(SomeRepository::class, $someRepository); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $this->assertInstanceOf(EntityManagerInterface::class, $someRepository->getEntityManager()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 50 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 51 |  |  |  | 
            
                        
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.