This repository was archived by the owner on Jul 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSilexApplicationTest.php
More file actions
88 lines (63 loc) · 2.5 KB
/
SilexApplicationTest.php
File metadata and controls
88 lines (63 loc) · 2.5 KB
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
<?php
namespace functional;
use common\TestCase;
use Pimple;
use Silex\Application;
use Stack\Session;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage;
use Symfony\Component\HttpKernel\Client;
use Symfony\Component\HttpKernel\HttpKernelInterface;
/* Taken from silex SessionServiceProviderTest */
class SilexApplicationTest extends TestCase
{
public function testWithSessionRoutes()
{
$app = new Application();
$app['exception_handler']->disable();
$app['session'] = $app->share(function ($app) {
return $app['request']->getSession();
});
$app->get('/login', function () use ($app) {
$app['session']->set('logged_in', true);
return 'Logged in successfully.';
});
$app->get('/account', function () use ($app) {
if (!$app['session']->get('logged_in')) {
return 'You are not logged in.';
}
return 'This is your account.';
});
$app->get('/logout', function () use ($app) {
$app['session']->invalidate();
return 'Logged out successfully.';
});
$app = $this->sessionify($app);
$client = new Client($app);
$client->request('GET', '/login');
$this->assertEquals('Logged in successfully.', $client->getResponse()->getContent());
$client->request('GET', '/account');
$this->assertEquals('This is your account.', $client->getResponse()->getContent());
$client->request('GET', '/logout');
$this->assertEquals('Logged out successfully.', $client->getResponse()->getContent());
$client->request('GET', '/account');
$this->assertEquals('You are not logged in.', $client->getResponse()->getContent());
}
public function testWithRoutesThatDoNotUseSession()
{
$app = new Application();
$app['exception_handler']->disable();
$app->get('/', function () {
return 'A welcome page.';
});
$app->get('/robots.txt', function () {
return 'Informations for robots.';
});
$app = $this->sessionify($app);
$client = new Client($app);
$client->request('GET', '/');
$this->assertEquals('A welcome page.', $client->getResponse()->getContent());
$client->request('GET', '/robots.txt');
$this->assertEquals('Informations for robots.', $client->getResponse()->getContent());
}
}