Skip to content

Commit 90c23c9

Browse files
committed
Adding more tests
1 parent 67837dc commit 90c23c9

File tree

3 files changed

+41
-13
lines changed

3 files changed

+41
-13
lines changed

src/Infrastructure/Http/Dispatcher/Dispatcher.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function __construct(
7373
* @param string $namespace Namespace
7474
* @return $this
7575
*/
76-
public function setDefaultNamespace(string $namespace)
76+
public function setDefaultNamespace(string $namespace): DispatcherInterface
7777
{
7878
$this->defaultNamespace = $namespace;
7979

@@ -84,9 +84,9 @@ public function setDefaultNamespace(string $namespace)
8484
* @param array $classParts Class Template Vars
8585
* @return $this
8686
*/
87-
public function setClassParts(array $classParts)
87+
public function setClassParts(array $classParts): DispatcherInterface
8888
{
89-
$this->setClassParts = $classParts;
89+
$this->classParts = $classParts;
9090

9191
return $this;
9292
}
@@ -95,7 +95,7 @@ public function setClassParts(array $classParts)
9595
* @param string $template Template String
9696
* @return $this
9797
*/
98-
public function setClassTemplate(string $template)
98+
public function setClassTemplate(string $template): DispatcherInterface
9999
{
100100
$this->classTemplate = $template;
101101
}
@@ -104,7 +104,7 @@ public function setClassTemplate(string $template)
104104
* @param string $separator Separator
105105
* @return $this
106106
*/
107-
public function setMethodSeparator(string $separator)
107+
public function setMethodSeparator(string $separator): DispatcherInterface
108108
{
109109
$this->methodSeparator = $separator;
110110

@@ -115,7 +115,7 @@ public function setMethodSeparator(string $separator)
115115
* @param string $separator Separator
116116
* @return $this
117117
*/
118-
public function setNamespaceSeparator(string $separator)
118+
public function setNamespaceSeparator(string $separator): DispatcherInterface
119119
{
120120
$this->namespaceSeparator = $separator;
121121

tests/TestCase/Infrastructure/Http/Dispatcher/DispatcherTest.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
use Phauthentic\Infrastructure\Http\Dispatcher\Dispatcher;
2020
use PHPUnit\Framework\TestCase;
21+
use Psr\Container\ContainerInterface;
22+
use Psr\Http\Message\ResponseInterface;
2123
use Psr\Http\Message\ServerRequestInterface;
2224

2325
/**
@@ -26,14 +28,23 @@
2628
class DispatcherTest extends TestCase
2729
{
2830
/**
29-
*
31+
* @return void
3032
*/
31-
public function testSomething()
33+
public function testDispatching(): void
3234
{
35+
$container = $this->getMockBuilder(ContainerInterface::class)
36+
->getMock();
3337
$request = $this->getMockBuilder(ServerRequestInterface::class)
3438
->getMock();
39+
$response = $this->getMockBuilder(ResponseInterface::class)
40+
->getMock();
41+
42+
$callable = function() use ($response) {
43+
return $response;
44+
};
3545

36-
//$dispatcher = new Dispatcher();
37-
//$dispatcher->dispatch($request, 'Plugin.Controller@foo');
46+
$dispatcher = new Dispatcher($container);
47+
$result = $dispatcher->dispatch($request, $callable);
48+
$this->assertInstanceOf(ResponseInterface::class, $result);
3849
}
3950
}

tests/TestCase/Infrastructure/Http/Middleware/DispatcherMiddlewareTest.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
use Phauthentic\Infrastructure\Http\Dispatcher\HandlerExtractorInterface;
2121
use Phauthentic\Infrastructure\Http\Middleware\DispatcherMiddleware;
2222
use PHPUnit\Framework\TestCase;
23+
use Psr\Http\Message\ResponseInterface;
24+
use Psr\Http\Message\ServerRequestInterface;
25+
use Psr\Http\Server\RequestHandlerInterface;
2326

2427
/**
2528
* DispatcherMiddleware Test
@@ -29,19 +32,33 @@ class DispatcherMiddlewareTest extends TestCase
2932
/**
3033
* @return void
3134
*/
32-
public function testHandle(): void
35+
public function testProcess(): void
3336
{
37+
$request = $this->getMockBuilder(ServerRequestInterface::class)
38+
->getMock();
39+
$response = $this->getMockBuilder(ResponseInterface::class)
40+
->getMock();
41+
$requestHandler = $this->getMockBuilder(RequestHandlerInterface::class)
42+
->getMock();
3443
$extractor = $this->getMockBuilder(HandlerExtractorInterface::class)
3544
->getMock();
36-
3745
$dispatcher = $this->getMockBuilder(DispatcherInterface::class)
3846
->getMock();
3947

48+
$request->expects($this->any())
49+
->method('getAttribute')
50+
->with('handler', null)
51+
->willReturn(function () use ($response) {
52+
return $response;
53+
});
54+
4055
$middleware = new DispatcherMiddleware(
4156
$extractor,
4257
$dispatcher
4358
);
4459

45-
//$middleware->process($request, $requestHandlerInterface);
60+
$result = $middleware->process($request, $requestHandler);
61+
62+
$this->assertInstanceOf(ResponseInterface::class, $result);
4663
}
4764
}

0 commit comments

Comments
 (0)