|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Mouf\Mvc\Splash\DI; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\Common\Annotations\AnnotationReader; |
|
8
|
|
|
use Doctrine\Common\Annotations\AnnotationRegistry; |
|
9
|
|
|
use Doctrine\Common\Annotations\Reader; |
|
10
|
|
|
use Mouf\Mvc\Splash\Fixtures\TestController2; |
|
11
|
|
|
use Mouf\Mvc\Splash\Routers\SplashDefaultRouter; |
|
12
|
|
|
use Simplex\Container; |
|
13
|
|
|
use Zend\Diactoros\Response\HtmlResponse; |
|
14
|
|
|
use Zend\Diactoros\Response\RedirectResponse; |
|
15
|
|
|
use Zend\Diactoros\ServerRequest; |
|
16
|
|
|
|
|
17
|
|
|
class SplashServiceProviderTest extends \PHPUnit_Framework_TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
protected function setUp() |
|
20
|
|
|
{ |
|
21
|
|
|
$loader = require __DIR__.'../../../../../../vendor/autoload.php'; |
|
22
|
|
|
AnnotationRegistry::registerLoader(array($loader, 'loadClass')); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function testDefaultRouter() |
|
26
|
|
|
{ |
|
27
|
|
|
$simplex = new Container(); |
|
28
|
|
|
$simplex->register(new SplashServiceProvider()); |
|
29
|
|
|
|
|
30
|
|
|
$simplex[Reader::class] = function() { |
|
31
|
|
|
return new AnnotationReader(); |
|
32
|
|
|
}; |
|
33
|
|
|
|
|
34
|
|
|
$simplex[TestController2::class] = function() { |
|
35
|
|
|
return new TestController2(); |
|
36
|
|
|
}; |
|
37
|
|
|
|
|
38
|
|
|
$simplex['thecodingmachine.splash.controllers'] = [ |
|
39
|
|
|
TestController2::class |
|
40
|
|
|
]; |
|
41
|
|
|
|
|
42
|
|
|
$defaultRouter = $simplex->get(SplashDefaultRouter::class); |
|
43
|
|
|
$this->assertInstanceOf(SplashDefaultRouter::class, $defaultRouter); |
|
44
|
|
|
|
|
45
|
|
|
// Now, let's test the redirect |
|
46
|
|
|
$request = new ServerRequest([], [], '/foo/var/bar/', 'GET', 'php://input', |
|
47
|
|
|
[], |
|
48
|
|
|
[], |
|
49
|
|
|
['id' => 42] |
|
50
|
|
|
); |
|
51
|
|
|
$response = new HtmlResponse(''); |
|
52
|
|
|
$response = $defaultRouter($request, $response); |
|
53
|
|
|
$this->assertInstanceOf(RedirectResponse::class, $response); |
|
54
|
|
|
$this->assertEquals('/foo/var/bar', $response->getHeader('Location')[0]); |
|
55
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|