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;
|
$this->attributes = $attributes;
|
||||||
if ($dispatcher === null) {
|
if ($dispatcher === null) {
|
||||||
$dispatcher = $this->getDispatcher();
|
$dispatcher = $this->getDefaultDispatcher();
|
||||||
}
|
}
|
||||||
$this->dispatcher = $dispatcher;
|
$this->dispatcher = $dispatcher;
|
||||||
$this->pathVariablesAttributeName = $pathVariablesAttributeName;
|
$this->pathVariablesAttributeName = $pathVariablesAttributeName;
|
||||||
|
|
@ -107,7 +107,17 @@ class Server
|
||||||
*/
|
*/
|
||||||
public function createRouter()
|
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
|
* @return DispatcherInterface
|
||||||
*/
|
*/
|
||||||
protected function getDispatcher()
|
protected function getDefaultDispatcher()
|
||||||
{
|
{
|
||||||
return new Dispatcher();
|
return new Dispatcher();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,11 +34,11 @@ class ServerTest extends \PHPUnit_Framework_TestCase
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->server = $this->getMockBuilder('WellRESTed\Server')
|
$this->server = $this->getMockBuilder('WellRESTed\Server')
|
||||||
->setMethods(["getDispatcher", "getRequest", "getResponse", "getTransmitter"])
|
->setMethods(["getDefaultDispatcher", "getRequest", "getResponse", "getTransmitter"])
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
$this->server->expects($this->any())
|
$this->server->expects($this->any())
|
||||||
->method("getDispatcher")
|
->method("getDefaultDispatcher")
|
||||||
->will($this->returnValue($this->dispatcher->reveal()));
|
->will($this->returnValue($this->dispatcher->reveal()));
|
||||||
$this->server->expects($this->any())
|
$this->server->expects($this->any())
|
||||||
->method("getRequest")
|
->method("getRequest")
|
||||||
|
|
@ -54,7 +54,7 @@ class ServerTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::__construct
|
* @covers ::__construct
|
||||||
* @covers ::getDispatcher
|
* @covers ::getDefaultDispatcher
|
||||||
* @uses WellRESTed\Dispatching\Dispatcher
|
* @uses WellRESTed\Dispatching\Dispatcher
|
||||||
*/
|
*/
|
||||||
public function testCreatesInstances()
|
public function testCreatesInstances()
|
||||||
|
|
@ -72,6 +72,14 @@ class ServerTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->assertSame($server, $server->add("middleware"));
|
$this->assertSame($server, $server->add("middleware"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::getDispatcher
|
||||||
|
*/
|
||||||
|
public function testReturnsDispatcher()
|
||||||
|
{
|
||||||
|
$this->assertSame($this->dispatcher->reveal(), $this->server->getDispatcher());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::add
|
* @covers ::add
|
||||||
* @covers ::dispatch
|
* @covers ::dispatch
|
||||||
|
|
@ -187,5 +195,4 @@ class ServerTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->server->respond();
|
$this->server->respond();
|
||||||
$this->request->withAttribute("name", "value")->shouldHaveBeenCalled();
|
$this->request->withAttribute("name", "value")->shouldHaveBeenCalled();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue