summaryrefslogtreecommitdiff
path: root/tests/Unit/Http/SessionServiceProviderTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Unit/Http/SessionServiceProviderTest.php')
-rw-r--r--tests/Unit/Http/SessionServiceProviderTest.php56
1 files changed, 51 insertions, 5 deletions
diff --git a/tests/Unit/Http/SessionServiceProviderTest.php b/tests/Unit/Http/SessionServiceProviderTest.php
index d0125bc2..dd0e538f 100644
--- a/tests/Unit/Http/SessionServiceProviderTest.php
+++ b/tests/Unit/Http/SessionServiceProviderTest.php
@@ -2,7 +2,9 @@
namespace Engelsystem\Test\Unit\Http;
+use Engelsystem\Config\Config;
use Engelsystem\Http\Request;
+use Engelsystem\Http\SessionHandlers\DatabaseHandler;
use Engelsystem\Http\SessionServiceProvider;
use Engelsystem\Test\Unit\ServiceProviderTest;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
@@ -23,6 +25,9 @@ class SessionServiceProviderTest extends ServiceProviderTest
$sessionStorage = $this->getMockForAbstractClass(StorageInterface::class);
$sessionStorage2 = $this->getMockForAbstractClass(StorageInterface::class);
+ $databaseHandler = $this->getMockBuilder(DatabaseHandler::class)
+ ->disableOriginalConstructor()
+ ->getMock();
$session = $this->getSessionMock();
$request = $this->getRequestMock();
@@ -32,22 +37,38 @@ class SessionServiceProviderTest extends ServiceProviderTest
->setConstructorArgs([$app])
->setMethods(['isCli'])
->getMock();
- $serviceProvider->expects($this->exactly(2))
+
+ /** @var Config|MockObject $config */
+ $config = $this->createMock(Config::class);
+
+ $serviceProvider->expects($this->exactly(3))
->method('isCli')
- ->willReturnOnConsecutiveCalls(true, false);
+ ->willReturnOnConsecutiveCalls(true, false, false);
- $app->expects($this->exactly(4))
+ $app->expects($this->exactly(7))
->method('make')
->withConsecutive(
[MockArraySessionStorage::class],
[Session::class],
- [NativeSessionStorage::class, ['options' => ['cookie_httponly' => true]]],
+ [
+ NativeSessionStorage::class,
+ ['options' => ['cookie_httponly' => true, 'name' => 'session'], 'handler' => null]
+ ],
+ [Session::class],
+ [DatabaseHandler::class],
+ [
+ NativeSessionStorage::class,
+ ['options' => ['cookie_httponly' => true, 'name' => 'foobar'], 'handler' => $databaseHandler]
+ ],
[Session::class]
)
->willReturnOnConsecutiveCalls(
$sessionStorage,
$session,
$sessionStorage2,
+ $session,
+ $databaseHandler,
+ $sessionStorage2,
$session
);
$app->expects($this->atLeastOnce())
@@ -58,13 +79,38 @@ class SessionServiceProviderTest extends ServiceProviderTest
['session', $session]
);
+ $app->expects($this->exactly(5))
+ ->method('get')
+ ->withConsecutive(
+ ['request'],
+ ['config'],
+ ['request'],
+ ['config'],
+ ['request']
+ )
+ ->willReturnOnConsecutiveCalls(
+ $request,
+ $config,
+ $request,
+ $config,
+ $request
+ );
+
+ $config->expects($this->exactly(2))
+ ->method('get')
+ ->with('session')
+ ->willReturnOnConsecutiveCalls(
+ ['driver' => 'native', 'name' => 'session'],
+ ['driver' => 'pdo', 'name' => 'foobar']
+ );
+
$this->setExpects($app, 'bind', [StorageInterface::class, 'session.storage'], null, $this->atLeastOnce());
- $this->setExpects($app, 'get', ['request'], $request, $this->atLeastOnce());
$this->setExpects($request, 'setSession', [$session], null, $this->atLeastOnce());
$this->setExpects($session, 'start', null, null, $this->atLeastOnce());
$serviceProvider->register();
$serviceProvider->register();
+ $serviceProvider->register();
}
/**