| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * This file is part of phpDocumentor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @copyright 2010-2018 Mike van Riel<[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @license   http://www.opensource.org/licenses/mit-license.php MIT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @link      http://phpdoc.org | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | namespace phpDocumentor\Reflection\Php\Factory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Mockery as m; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use phpDocumentor\Reflection\DocBlock as DocBlockElement; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use phpDocumentor\Reflection\Fqsen; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use phpDocumentor\Reflection\Php\Constant as ConstantElement; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use phpDocumentor\Reflection\Php\Interface_ as InterfaceElement; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use phpDocumentor\Reflection\Php\Method as MethodElement; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use phpDocumentor\Reflection\Php\ProjectFactoryStrategy; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use phpDocumentor\Reflection\Php\StrategyContainer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use PhpParser\Comment\Doc; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | use PhpParser\Node\Const_; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | use PhpParser\Node\Expr\Variable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | use PhpParser\Node\Stmt\ClassConst; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | use PhpParser\Node\Stmt\ClassMethod; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | use PhpParser\Node\Stmt\Interface_ as InterfaceNode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  * Test case for Interface_ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  * @coversDefaultClass phpDocumentor\Reflection\Php\Factory\Interface_ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  * @covers ::<!public> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  */ | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 35 |  |  | // @codingStandardsIgnoreStart | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  | class Interface_Test extends TestCase | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  | // @codingStandardsIgnoreEnd | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     protected function setUp() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $this->fixture = new Interface_(); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 42 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |      * @covers ::matches | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     public function testMatches() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $this->assertFalse($this->fixture->matches(new \stdClass())); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $this->assertTrue($this->fixture->matches(m::mock(InterfaceNode::class))); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |      * @covers ::create | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     public function testSimpleCreate() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $containerMock = m::mock(StrategyContainer::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $interfaceMock = $this->buildClassMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $interfaceMock->shouldReceive('getDocComment')->andReturnNull(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         /** @var InterfaceElement $class */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $class = $this->fixture->create($interfaceMock, $containerMock); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $this->assertInstanceOf(InterfaceElement::class, $class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $this->assertEquals('\Space\MyInterface', (string) $class->getFqsen()); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |      * @covers ::create | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     public function testCreateWithDocBlock() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $doc = m::mock(Doc::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         $interfaceMock = $this->buildClassMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         $interfaceMock->shouldReceive('getDocComment')->andReturn($doc); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $docBlock = new DocBlockElement(''); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         $strategyMock = m::mock(ProjectFactoryStrategy::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         $containerMock = m::mock(StrategyContainer::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $strategyMock->shouldReceive('create') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             ->with($doc, $containerMock, null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             ->andReturn($docBlock); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         $containerMock->shouldReceive('findMatching') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             ->with($doc) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             ->andReturn($strategyMock); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         /** @var InterfaceElement $interface */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         $interface = $this->fixture->create($interfaceMock, $containerMock); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         $this->assertSame($docBlock, $interface->getDocBlock()); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 94 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |      * @covers ::create | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     public function testWithMethodMembers() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         $method1 = new ClassMethod('\Space\MyInterface::method1'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         $method1Descriptor = new MethodElement(new Fqsen('\Space\MyInterface::method1')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         $strategyMock = m::mock(ProjectFactoryStrategy::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         $containerMock = m::mock(StrategyContainer::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         $interfaceMock = $this->buildClassMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         $interfaceMock->shouldReceive('getDocComment')->andReturnNull(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         $interfaceMock->stmts = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |             $method1, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         $strategyMock->shouldReceive('create') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |             ->with($method1, $containerMock, null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |             ->andReturn($method1Descriptor); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         $containerMock->shouldReceive('findMatching') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |             ->with($method1) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |             ->andReturn($strategyMock); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         $this->fixture->create($interfaceMock, $containerMock); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         /** @var InterfaceElement $interface */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         $interface = $this->fixture->create($interfaceMock, $containerMock); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         $this->assertInstanceOf(InterfaceElement::class, $interface); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         $this->assertEquals('\Space\MyInterface', (string) $interface->getFqsen()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |         $this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |             ['\Space\MyInterface::method1' => $method1Descriptor], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |             $interface->getMethods() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |         ); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 130 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 131 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 132 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  |      * @covers ::create | 
            
                                                                        
                            
            
                                    
            
            
                | 134 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |     public function testWithConstants() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |         $const = new Const_('\Space\MyClass::MY_CONST', new Variable('a')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |         $constant = new ClassConst([$const]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |         $result = new ConstantElement(new Fqsen('\Space\MyClass::MY_CONST')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |         $strategyMock = m::mock(ProjectFactoryStrategy::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |         $containerMock = m::mock(StrategyContainer::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |         $strategyMock->shouldReceive('create') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |             ->with(m::type(ClassConstantIterator::class), $containerMock, null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |             ->andReturn($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |         $containerMock->shouldReceive('findMatching') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |             ->with(m::type(ClassConstantIterator::class)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |             ->andReturn($strategyMock); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |         $classMock = $this->buildClassMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |         $classMock->shouldReceive('getDocComment')->andReturnNull(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |         $classMock->stmts = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |             $constant, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |         /** @var ClassElement $class */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |         $class = $this->fixture->create($classMock, $containerMock); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |         $this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |                 '\Space\MyClass::MY_CONST' => $result, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |             $class->getConstants() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |         ); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 167 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 168 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 169 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 170 |  |  |      * @return m\MockInterface|InterfaceNode | 
            
                                                                        
                            
            
                                    
            
            
                | 171 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |     private function buildClassMock() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |         $interfaceMock = m::mock(InterfaceNode::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |         $interfaceMock->fqsen = new Fqsen('\Space\MyInterface'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |         $interfaceMock->extends = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |         $interfaceMock->shouldReceive('getLine')->andReturn(1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |         return $interfaceMock; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 179 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 180 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 181 |  |  |  |