createMock(ClientInterface::class); $client->expects($this->exactly(2))->method('__call') ->willReturnOnConsecutiveCalls(1, 0); $id = (new Handler($client))->create_sid(); $this->assertSame(1, preg_match('/^[a-f0-9]{64}$/', $id)); } public function testValidatesExistingAndMissingIds() { $client = $this->createMock(ClientInterface::class); $client->expects($this->exactly(2))->method('__call') ->with('exists', ['session-id']) ->willReturnOnConsecutiveCalls(1, 0); $handler = new Handler($client); $this->assertTrue($handler->validateId('session-id')); $this->assertFalse($handler->validateId('session-id')); } public function testUpdatesTimestampAndPreservesData() { $client = $this->createMock(ClientInterface::class); $client->expects($this->once())->method('__call') ->with('setex', ['session-id', 120, 'data']); $handler = new Handler($client, ['gc_maxlifetime' => 120]); $this->assertTrue($handler->updateTimestamp('session-id', 'data')); } /** * @dataProvider sessionIdOperations */ public function testRejectsRedisErrorsDuringSessionIdOperations($operation, array $arguments) { $client = $this->createMock(ClientInterface::class); $client->expects($this->once())->method('__call') ->willReturn(new Error('NOPERM denied')); $handler = new Handler($client); $this->expectException(ServerException::class); $this->expectExceptionMessage('NOPERM denied'); $handler->$operation(...$arguments); } public function sessionIdOperations() { return [ ['validateId', ['session-id']], ['create_sid', []], ]; } }