/
FunctionalTest.php
122 lines (97 loc) · 2.98 KB
/
FunctionalTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
namespace DI\Bridge\Silex\Test;
use DI\ContainerBuilder;
use stdClass;
use Symfony\Component\HttpFoundation\Request;
class FunctionalTest extends BaseTestCase
{
/**
* @test
*/
public function should_dispatch_get()
{
$app = $this->createApplication();
$app->get('/foo', function () {
return 'Hello';
});
$response = $app->handle(Request::create('/foo'));
$this->assertEquals('Hello', $response->getContent());
}
/**
* @test
*/
public function should_resolve_controllers_from_the_container()
{
$app = $this->createApplication();
$app->get('/foo', 'DI\Bridge\Silex\Test\Fixture\InvokableController');
$response = $app->handle(Request::create('/foo'));
$this->assertEquals('Hello world', $response->getContent());
}
/**
* @test
*/
public function should_resolve_array_controllers()
{
$app = $this->createApplication();
$app->get('/foo', ['DI\Bridge\Silex\Test\Fixture\Controller', 'home']);
$response = $app->handle(Request::create('/foo'));
$this->assertEquals('Hello world', $response->getContent());
}
/**
* @test
*/
public function should_pass_url_placeholders()
{
$app = $this->createApplication();
$app->get('/{name}', ['DI\Bridge\Silex\Test\Fixture\Controller', 'hello']);
$response = $app->handle(Request::create('/john'));
$this->assertEquals('Hello john', $response->getContent());
}
/**
* @test
*/
public function should_pass_request_object()
{
$app = $this->createApplication();
$app->get('/', function (Request $request) {
return 'Hello ' . $request->get('name');
});
$response = $app->handle(Request::create('/?name=john'));
$this->assertEquals('Hello john', $response->getContent());
}
/**
* @test
*/
public function should_pass_phpdi_service_based_on_type_hint()
{
$builder = new ContainerBuilder;
$builder->addDefinitions([
'stdClass' => function () {
$service = new stdClass;
$service->foo = 'bar';
return $service;
},
]);
$app = $this->createApplication($builder);
$app->get('/', function (stdClass $param) {
return $param->foo;
});
$response = $app->handle(Request::create('/'));
$this->assertEquals('bar', $response->getContent());
}
/**
* @test
*/
public function should_pass_pimple_service_based_on_type_hint()
{
$app = $this->createApplication();
$service = new stdClass;
$service->foo = 'bar';
$app['stdClass'] = $service;
$app->get('/', function (stdClass $param) {
return $param->foo;
});
$response = $app->handle(Request::create('/'));
$this->assertEquals('bar', $response->getContent());
}
}