Skip to content

Commit 4647df4

Browse files
committed
Add tests DatabaseSessionHandler
1 parent c01bb8d commit 4647df4

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Illuminate\Tests\Integration\Session;
4+
5+
use Illuminate\Session\DatabaseSessionHandler;
6+
use Illuminate\Support\Carbon;
7+
use Illuminate\Tests\Integration\Database\DatabaseTestCase;
8+
9+
class DatabaseSessionHandlerTest extends DatabaseTestCase
10+
{
11+
public function testBasicFunctionality()
12+
{
13+
$path = __DIR__.'/../../../src/Illuminate/Session/Console/stubs/database.stub';
14+
$migration = require_once $path;
15+
16+
$migration->up();
17+
18+
$handler = new DatabaseSessionHandler($this->app['db']->connection(), 'sessions', 1, $this->app);
19+
20+
$handler->write('valid_session_id_2425', json_encode(['foo' => 'bar']));
21+
22+
$this->assertEquals(['foo' => 'bar'], json_decode($handler->read('valid_session_id_2425'), true));
23+
$this->assertEquals('', $handler->read('invalid_session_id_2425'));
24+
25+
$this->assertEquals(true, $handler->destroy('invalid_session_id_2425'));
26+
$this->assertEquals('', $handler->read('valid_session_id_2425'));
27+
$this->assertEquals(0, $handler->gc(1));
28+
Carbon::setTestNow(Carbon::now()->addSeconds(2));
29+
$this->assertEquals(1, $handler->gc(1));
30+
$migration->down();
31+
$this->assertTrue(false);
32+
}
33+
}

0 commit comments

Comments
 (0)