AppserverIo\Appserver\Application\Application::newService PHP Method

newService() public method

(non-PHPdoc)
See also: AppserverIo\Appserver\Application\Interfaces\ContextInterface::newService()
public newService ( string $className ) : object
$className string The API service class name to return the instance for
return object The service instance
    public function newService($className)
    {
        return $this->getInitialContext()->newService($className);
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Test if the newService() method will be forwarded to the initial context.
  *
  * @return void
  */
 public function testNewService()
 {
     // define the methods to mock
     $methodsToMock = array('getClassLoader', 'newInstance', 'newService', 'getAttribute', 'getSystemLogger', 'getSystemConfiguration', 'getLogger');
     // create a mock instance
     $mockInitialContext = $this->getMock('AppserverIo\\Appserver\\Application\\Interfaces\\ContextInterface', $methodsToMock);
     $mockInitialContext->expects($this->any())->method('newService')->will($this->returnValue($newService = new \stdClass()));
     // check if the passed instance is equal to the getter one
     $this->application->injectInitialContext($mockInitialContext);
     $this->assertEquals($newService, $this->application->newService('\\stdClass'));
 }