123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <?php
- /*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
- use PHPUnit\Framework\MockObject\MockObject;
- use PHPUnit\Framework\TestCase;
- use Symfony\Component\Cache\Marshaller\MarshallerInterface;
- use Symfony\Component\HttpFoundation\Session\Storage\Handler\AbstractSessionHandler;
- use Symfony\Component\HttpFoundation\Session\Storage\Handler\MarshallingSessionHandler;
- /**
- * @author Ahmed TAILOULOUTE <ahmed.tailouloute@gmail.com>
- */
- class MarshallingSessionHandlerTest extends TestCase
- {
- /**
- * @var MockObject|\SessionHandlerInterface
- */
- protected $handler;
- /**
- * @var MockObject|MarshallerInterface
- */
- protected $marshaller;
- protected function setUp(): void
- {
- $this->marshaller = $this->createMock(MarshallerInterface::class);
- $this->handler = $this->createMock(AbstractSessionHandler::class);
- }
- public function testOpen()
- {
- $marshallingSessionHandler = new MarshallingSessionHandler($this->handler, $this->marshaller);
- $this->handler->expects($this->once())->method('open')
- ->with('path', 'name')->willReturn(true);
- $marshallingSessionHandler->open('path', 'name');
- }
- public function testClose()
- {
- $marshallingSessionHandler = new MarshallingSessionHandler($this->handler, $this->marshaller);
- $this->handler->expects($this->once())->method('close')->willReturn(true);
- $this->assertTrue($marshallingSessionHandler->close());
- }
- public function testDestroy()
- {
- $marshallingSessionHandler = new MarshallingSessionHandler($this->handler, $this->marshaller);
- $this->handler->expects($this->once())->method('destroy')
- ->with('session_id')->willReturn(true);
- $marshallingSessionHandler->destroy('session_id');
- }
- public function testGc()
- {
- $marshallingSessionHandler = new MarshallingSessionHandler($this->handler, $this->marshaller);
- $this->handler->expects($this->once())->method('gc')
- ->with(4711)->willReturn(1);
- $marshallingSessionHandler->gc(4711);
- }
- public function testRead()
- {
- $marshallingSessionHandler = new MarshallingSessionHandler($this->handler, $this->marshaller);
- $this->handler->expects($this->once())->method('read')->with('session_id')
- ->willReturn('data');
- $this->marshaller->expects($this->once())->method('unmarshall')->with('data')
- ->willReturn('unmarshalled_data')
- ;
- $result = $marshallingSessionHandler->read('session_id');
- $this->assertEquals('unmarshalled_data', $result);
- }
- public function testWrite()
- {
- $marshallingSessionHandler = new MarshallingSessionHandler($this->handler, $this->marshaller);
- $this->marshaller->expects($this->once())->method('marshall')
- ->with(['data' => 'data'], [])
- ->willReturn(['data' => 'marshalled_data']);
- $this->handler->expects($this->once())->method('write')
- ->with('session_id', 'marshalled_data')
- ;
- $marshallingSessionHandler->write('session_id', 'data');
- }
- public function testValidateId()
- {
- $marshallingSessionHandler = new MarshallingSessionHandler($this->handler, $this->marshaller);
- $this->handler->expects($this->once())->method('validateId')
- ->with('session_id')->willReturn(true);
- $marshallingSessionHandler->validateId('session_id');
- }
- public function testUpdateTimestamp()
- {
- $marshallingSessionHandler = new MarshallingSessionHandler($this->handler, $this->marshaller);
- $this->handler->expects($this->once())->method('updateTimestamp')
- ->with('session_id', 'data')->willReturn(true);
- $marshallingSessionHandler->updateTimestamp('session_id', 'data');
- }
- }
|