/** * Check that the merge() method works as expected. * * @return void */ public function testMerge() { // create a reflection class and load the reflection method $reflectionClass = new ReflectionClass(__CLASS__); $reflectionMethod = $reflectionClass->getMethod('nonameAction'); // initialize the descriptor instance $this->descriptor->fromReflectionMethod($reflectionMethod); $descriptor = new ActionDescriptor(); $descriptor->setMethodName('nonameAction'); $descriptor->setName($newName = '/anotherTest'); // merge the descriptors $this->descriptor->merge($descriptor); // check the method name and that the name has been overwritten $this->assertSame('nonameAction', $this->descriptor->getMethodName()); $this->assertSame($newName, $this->descriptor->getName()); $this->assertEquals(array(HttpProtocol::METHOD_POST), $this->descriptor->getRequestMethods()); }
/** * Check that the merge() method works as expected. * * @return void */ public function testMerge() { // initialize the annotation aliases $aliases = array(Result::ANNOTATION => Result::__getClass(), Results::ANNOTATION => Results::__getClass(), Resource::ANNOTATION => Resource::__getClass(), EnterpriseBean::ANNOTATION => EnterpriseBean::__getClass()); // create a reflection class $reflectionClass = new ReflectionClass(__CLASS__, array(), $aliases); // initialize the descriptor instance from reflection class $this->descriptor->fromReflectionClass($reflectionClass); // initialize the descriptor to merge $descriptorToMerge = $this->getMockBuilder('AppserverIo\\Routlt\\Description\\PathDescriptor')->setMethods(array('getName', 'getActions', 'getResults', 'getClassName', 'getResReferences', 'getEpbReferences'))->getMock(); // create a action descriptor $action = new ActionDescriptor(); $action->setName('/test'); $action->setMethodName('someMethod'); // create a result descriptor $result = new ResultDescriptor(); $result->setName('failure'); $result->setType('DummyType'); $result->setResult('/path/to/dummy.phtml'); // create a resource descriptor $resReference = new ResReferenceDescriptor(); $resReference->setName('SomeResource'); // create an EPB descriptor $epbReference = new EpbReferenceDescriptor(); $epbReference->getName('UserSessionBean'); // mock the methods $descriptorToMerge->expects($this->once())->method('getName')->will($this->returnValue('/anotherIndex')); $descriptorToMerge->expects($this->once())->method('getActions')->will($this->returnValue(array($action))); $descriptorToMerge->expects($this->once())->method('getResults')->will($this->returnValue(array($result))); $descriptorToMerge->expects($this->once())->method('getClassName')->will($this->returnValue(__CLASS__)); $descriptorToMerge->expects($this->once())->method('getEpbReferences')->will($this->returnValue(array($epbReference))); $descriptorToMerge->expects($this->once())->method('getResReferences')->will($this->returnValue(array($resReference))); // merge the descriptors $this->descriptor->merge($descriptorToMerge); // check the merge values $this->assertSame('/anotherIndex', $this->descriptor->getName()); $this->assertSame(__CLASS__, $this->descriptor->getClassName()); $this->assertCount(3, $this->descriptor->getActions()); $this->assertCount(2, $this->descriptor->getResults()); $this->assertCount(4, $this->descriptor->getReferences()); $this->assertCount(2, $this->descriptor->getResReferences()); $this->assertCount(2, $this->descriptor->getEpbReferences()); // load the actions $actions = $this->descriptor->getActions(); // check that the method name has been overwritten $this->assertEquals($action->getMethodName(), $actions['/test'][HttpProtocol::METHOD_GET]->getMethodName()); }