Use app configured session lifetime for garbage collection
This commit is contained in:
parent
6da0c8a835
commit
9f35ebc482
|
@ -71,6 +71,7 @@ class DatabaseHandler extends AbstractHandler
|
|||
*/
|
||||
public function gc(int $max_lifetime): int|false
|
||||
{
|
||||
$max_lifetime = config('session.lifetime') * 24 * 60 * 60;
|
||||
$timestamp = $this->getCurrentTimestamp(-$max_lifetime);
|
||||
|
||||
return $this->getQuery()
|
||||
|
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Engelsystem\Test\Unit\Http\SessionHandlers;
|
||||
|
||||
use Engelsystem\Config\Config;
|
||||
use Engelsystem\Http\SessionHandlers\DatabaseHandler;
|
||||
use Engelsystem\Test\Unit\HasDatabase;
|
||||
use Engelsystem\Test\Unit\TestCase;
|
||||
|
@ -73,12 +74,16 @@ class DatabaseHandlerTest extends TestCase
|
|||
*/
|
||||
public function testGc(): void
|
||||
{
|
||||
$this->app->instance('config', new Config());
|
||||
|
||||
$this->database->insert("INSERT INTO sessions VALUES ('foo', 'Lorem Ipsum', '2000-01-01 01:00')");
|
||||
$this->database->insert("INSERT INTO sessions VALUES ('bar', 'Dolor Sit', '3000-01-01 01:00')");
|
||||
config(['session.lifetime' => 1]); // 1 day
|
||||
|
||||
$handler = new DatabaseHandler($this->database);
|
||||
|
||||
$this->assertEquals(1, $handler->gc(60 * 60));
|
||||
// Max lifetime gets overwritten by settings
|
||||
$this->assertEquals(1, $handler->gc(0));
|
||||
|
||||
$return = $this->database->select('SELECT * FROM sessions');
|
||||
$this->assertCount(1, $return);
|
||||
|
|
Loading…
Reference in New Issue