forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSessionMiddlewareTest.php
More file actions
80 lines (62 loc) · 2.69 KB
/
SessionMiddlewareTest.php
File metadata and controls
80 lines (62 loc) · 2.69 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
<?php
use Mockery as m;
class SessionMiddlewareTest extends PHPUnit_Framework_TestCase {
public function tearDown()
{
m::close();
}
public function testSessionIsProperlyStartedAndClosed()
{
$request = Symfony\Component\HttpFoundation\Request::create('/', 'GET');
$response = new Symfony\Component\HttpFoundation\Response;
$middle = new Illuminate\Session\Middleware(
$app = m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'),
$manager = m::mock('Illuminate\Session\SessionManager')
);
$manager->shouldReceive('getSessionConfig')->andReturn(array(
'driver' => 'file',
'lottery' => array(100, 100),
'path' => '/',
'domain' => null,
'lifetime' => 120,
'expire_on_close' => false,
));
$manager->shouldReceive('driver')->andReturn($driver = m::mock('Illuminate\Session\Store')->makePartial());
$driver->shouldReceive('setRequestOnHandler')->once()->with($request);
$driver->shouldReceive('start')->once();
$app->shouldReceive('handle')->once()->with($request, Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST, true)->andReturn($response);
$driver->shouldReceive('save')->once();
$driver->shouldReceive('getHandler')->andReturn($handler = m::mock('StdClass'));
$handler->shouldReceive('gc')->once()->with(120 * 60);
$driver->shouldReceive('getName')->andReturn('name');
$driver->shouldReceive('getId')->andReturn(1);
$middleResponse = $middle->handle($request);
$this->assertTrue($response === $middleResponse);
$this->assertEquals(1, head($response->headers->getCookies())->getValue());
}
public function testSessionIsNotUsedWhenNoDriver()
{
$request = Symfony\Component\HttpFoundation\Request::create('/', 'GET');
$response = new Symfony\Component\HttpFoundation\Response;
$middle = new Illuminate\Session\Middleware(
$app = m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'),
$manager = m::mock('Illuminate\Session\SessionManager')
);
$manager->shouldReceive('getSessionConfig')->andReturn(array(
'driver' => null,
));
$app->shouldReceive('handle')->once()->with($request, Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST, true)->andReturn($response);
$middleResponse = $middle->handle($request);
$this->assertTrue($response === $middleResponse);
}
public function testCheckingForRequestUsingArraySessions()
{
$middleware = new Illuminate\Session\Middleware(
m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'),
$manager = m::mock('Illuminate\Session\SessionManager'),
function() { return true; }
);
$manager->shouldReceive('setDefaultDriver')->once()->with('array');
$middleware->checkRequestForArraySessions(new Symfony\Component\HttpFoundation\Request);
}
}