Add public method Server::getDispatcher to make the dispatcher available.
This commit is contained in:
parent
6b3f2dded1
commit
5dcd119952
|
|
@ -55,7 +55,7 @@ class Server
|
|||
}
|
||||
$this->attributes = $attributes;
|
||||
if ($dispatcher === null) {
|
||||
$dispatcher = $this->getDispatcher();
|
||||
$dispatcher = $this->getDefaultDispatcher();
|
||||
}
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->pathVariablesAttributeName = $pathVariablesAttributeName;
|
||||
|
|
@ -107,7 +107,17 @@ class Server
|
|||
*/
|
||||
public function createRouter()
|
||||
{
|
||||
return new Router($this->dispatcher, $this->pathVariablesAttributeName);
|
||||
return new Router($this->getDispatcher(), $this->pathVariablesAttributeName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the dispatched used by the server.
|
||||
*
|
||||
* @return DispatcherInterface
|
||||
*/
|
||||
public function getDispatcher()
|
||||
{
|
||||
return $this->dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -156,7 +166,7 @@ class Server
|
|||
*
|
||||
* @return DispatcherInterface
|
||||
*/
|
||||
protected function getDispatcher()
|
||||
protected function getDefaultDispatcher()
|
||||
{
|
||||
return new Dispatcher();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,11 +34,11 @@ class ServerTest extends \PHPUnit_Framework_TestCase
|
|||
);
|
||||
|
||||
$this->server = $this->getMockBuilder('WellRESTed\Server')
|
||||
->setMethods(["getDispatcher", "getRequest", "getResponse", "getTransmitter"])
|
||||
->setMethods(["getDefaultDispatcher", "getRequest", "getResponse", "getTransmitter"])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->server->expects($this->any())
|
||||
->method("getDispatcher")
|
||||
->method("getDefaultDispatcher")
|
||||
->will($this->returnValue($this->dispatcher->reveal()));
|
||||
$this->server->expects($this->any())
|
||||
->method("getRequest")
|
||||
|
|
@ -54,7 +54,7 @@ class ServerTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
/**
|
||||
* @covers ::__construct
|
||||
* @covers ::getDispatcher
|
||||
* @covers ::getDefaultDispatcher
|
||||
* @uses WellRESTed\Dispatching\Dispatcher
|
||||
*/
|
||||
public function testCreatesInstances()
|
||||
|
|
@ -72,6 +72,14 @@ class ServerTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertSame($server, $server->add("middleware"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getDispatcher
|
||||
*/
|
||||
public function testReturnsDispatcher()
|
||||
{
|
||||
$this->assertSame($this->dispatcher->reveal(), $this->server->getDispatcher());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::add
|
||||
* @covers ::dispatch
|
||||
|
|
@ -187,5 +195,4 @@ class ServerTest extends \PHPUnit_Framework_TestCase
|
|||
$this->server->respond();
|
||||
$this->request->withAttribute("name", "value")->shouldHaveBeenCalled();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue