| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Go! AOP framework | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @copyright Copyright 2015, Lisachenko Alexander <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * This source file is subject to the license that is bundled | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * with this source code in the file LICENSE. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | namespace Go\Symfony\GoAopBundle\Tests; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Go\Instrument\ClassLoading\AopComposerLoader; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Go\Symfony\GoAopBundle\DependencyInjection\Compiler\AspectCollectorPass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Go\Symfony\GoAopBundle\GoAopBundle; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use PHPUnit\Framework\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Symfony\Component\Debug\DebugClassLoader; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Symfony\Component\DependencyInjection\ContainerBuilder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Symfony\Component\DependencyInjection\ContainerInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * Class GoAopBundleTest | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 23 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  | class GoAopBundleTest extends TestCase | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |      * @test | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |      * @expectedException \InvalidArgumentException | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     public function itThrowsExceptionWhenBundleIsNotRegisteredAsFirstBundle() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $container = $this->getMockBuilder(ContainerBuilder::class)->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $container | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             ->method('getParameter') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             ->with('kernel.bundles') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             ->willReturn(['ArbitraryBundleName' => 'A bundle']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $bundle = new GoAopBundle(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $bundle->getName(); // invoke resolution of bundle name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $bundle->build($container); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 44 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |      * @test | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     public function itRegistersAspectCollectorPassPass() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $container = $this->getMockBuilder(ContainerBuilder::class)->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $container | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             ->method('getParameter') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             ->with('kernel.bundles') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             ->willReturn(['GoAopBundle' => 'A bundle']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $container | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             ->expects($spy = $this->exactly(1)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             ->method('addCompilerPass'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $bundle = new GoAopBundle(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $bundle->getName(); // invoke resolution of bundle name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $bundle->build($container); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         $invocation = $spy->getInvocations()[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $this->assertInstanceOf(AspectCollectorPass::class, $invocation->parameters[0]); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 70 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |      * @test | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |      * @runInSeparateProcess | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     public function itBoots() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         require_once __DIR__.'/Fixtures/mock/DebugClassLoader.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         require_once __DIR__.'/Fixtures/mock/AopComposerLoader.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $container = $this->getMockBuilder(ContainerInterface::class)->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $container | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             ->expects($this->once()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |             ->method('get') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |             ->with('goaop.aspect.container'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         $bundle = new GoAopBundle(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         $bundle->setContainer($container); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         DebugClassLoader::reset(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         DebugClassLoader::enable(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         $this->assertTrue(DebugClassLoader::$enabled); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         $bundle->boot(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         $this->assertTrue(DebugClassLoader::$enabled); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         $this->assertEquals(['enable', 'disable', 'enable'], DebugClassLoader::$invocations); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 99 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  |      * @test | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |      * @runInSeparateProcess | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |      * @expectedException \RuntimeException | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |      * @expectedExceptionMessage Initialization of AOP loader was failed, probably due to Debug::enable() | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     public function itThrowsExceptionOnBootWithoutAopComposerLoader() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         require_once __DIR__.'/Fixtures/mock/DebugClassLoader.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         require_once __DIR__.'/Fixtures/mock/AopComposerLoader.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         $container = $this->getMockBuilder(ContainerInterface::class)->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         $container | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |             ->expects($this->once()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |             ->method('get') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |             ->with('goaop.aspect.container'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         $bundle = new GoAopBundle(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         $bundle->setContainer($container); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         AopComposerLoader::$initialized = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         $bundle->boot(); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 125 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 126 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 127 |  |  |  | 
            
                        
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: