/**
  * Tests if the merge method works successfully.
  *
  * @return void
  */
 public function testMergeSuccessful()
 {
     // initialize the configuration
     $node = new EpbRefNode();
     $node->initFromFile(__DIR__ . '/_files/dd-epb-ref.xml');
     // initialize the descriptor from the nodes data
     $this->descriptor->fromConfiguration($node);
     // initialize the descriptor to merge
     $descriptorToMerge = $this->getMockForAbstractClass('AppserverIo\\Description\\EpbReferenceDescriptor');
     // initialize the configuration of the descriptor to be merged
     $nodeToMerge = new EpbRefNode();
     $nodeToMerge->initFromFile(__DIR__ . '/_files/dd-epb-ref-to-merge.xml');
     $descriptorToMerge->fromConfiguration($nodeToMerge);
     // merge the descriptors
     $this->descriptor->merge($descriptorToMerge);
     // check if all values have been initialized
     $this->assertSame('env/MyUserProcessor', $this->descriptor->getName());
     $this->assertSame('Another Description', $this->descriptor->getDescription());
     $this->assertSame('php:global/example/MyUserProcessor', $this->descriptor->getLookup());
     $this->assertSame('MyUserProcessorLocal', $this->descriptor->getBeanInterface());
     $this->assertSame('MyUserProcessor', $this->descriptor->getBeanName());
     $this->assertInstanceOf('AppserverIo\\Description\\InjectionTargetDescriptor', $injectTarget = $this->descriptor->getInjectionTarget());
     $this->assertSame('AppserverIo\\Apps\\Example\\Services\\ASampleProcessor', $injectTarget->getTargetClass());
     $this->assertSame('aSampleProcessor', $injectTarget->getTargetProperty());
     $this->assertNull($injectTarget->getTargetMethod());
 }
Ejemplo n.º 2
0
 /**
  * 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());
 }