* @copyright Meritoo.pl */ class SessionManagerTest extends BaseTestCase { public function testConstructorVisibilityAndArguments() { static::assertConstructorVisibilityAndArguments(SessionManager::class, OopVisibilityType::IS_PUBLIC, 1, 1); } public function testGetSessionKeyWhenFailedWithoutReason() { $this->expectException(CreateSessionKeyFailedException::class); $this->expectExceptionMessage('Create of the session key has failed'); $clientManager = $this->createMock(JsonRpcClientManager::class); $clientManager ->expects(static::any()) ->method('runMethod') ->willReturn([]); (new SessionManager($clientManager))->getSessionKey('lorem', 'ipsum'); } public function testGetSessionKeyWhenFailedWithReason() { $reason = 'Invalid credentials'; $this->expectException(CreateSessionKeyFailedException::class); $this->expectExceptionMessage(sprintf('Create of the session key has failed. Reason: \'%s\'.', $reason)); $clientManager = $this->createMock(JsonRpcClientManager::class); $clientManager ->expects(static::any()) ->method('runMethod') ->willReturn([ 'status' => $reason, ]); (new SessionManager($clientManager))->getSessionKey('lorem', 'ipsum'); } public function testGetSessionKey() { $clientManager = $this->createMock(JsonRpcClientManager::class); $clientManager ->expects(static::any()) ->method('runMethod') ->willReturn('12345'); $sessionManager = new SessionManager($clientManager); static::assertEquals('12345', $sessionManager->getSessionKey('lorem', 'ipsum')); } public function testReleaseSessionKey() { $clientManager = $this->createMock(JsonRpcClientManager::class); $clientManager ->expects(static::any()) ->method('runMethod') ->willReturn([]); $sessionManager = new SessionManager($clientManager); static::assertInstanceOf(SessionManager::class, $sessionManager->releaseSessionKey()); } }