* * 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\TestCase; use Symfony\Component\HttpFoundation\Session\Storage\Handler\AbstractSessionHandler; use Symfony\Component\HttpFoundation\Session\Storage\Handler\StrictSessionHandler; class StrictSessionHandlerTest extends TestCase { public function testOpen() { $handler = $this->getMockBuilder('SessionHandlerInterface')->getMock(); $handler->expects($this->once())->method('open') ->with('path', 'name')->willReturn(true); $proxy = new StrictSessionHandler($handler); $this->assertInstanceOf('SessionUpdateTimestampHandlerInterface', $proxy); $this->assertInstanceOf(AbstractSessionHandler::class, $proxy); $this->assertTrue($proxy->open('path', 'name')); } public function testCloseSession() { $handler = $this->getMockBuilder('SessionHandlerInterface')->getMock(); $handler->expects($this->once())->method('close') ->willReturn(true); $proxy = new StrictSessionHandler($handler); $this->assertTrue($proxy->close()); } public function testValidateIdOK() { $handler = $this->getMockBuilder('SessionHandlerInterface')->getMock(); $handler->expects($this->once())->method('read') ->with('id')->willReturn('data'); $proxy = new StrictSessionHandler($handler); $this->assertTrue($proxy->validateId('id')); } public function testValidateIdKO() { $handler = $this->getMockBuilder('SessionHandlerInterface')->getMock(); $handler->expects($this->once())->method('read') ->with('id')->willReturn(''); $proxy = new StrictSessionHandler($handler); $this->assertFalse($proxy->validateId('id')); } public function testRead() { $handler = $this->getMockBuilder('SessionHandlerInterface')->getMock(); $handler->expects($this->once())->method('read') ->with('id')->willReturn('data'); $proxy = new StrictSessionHandler($handler); $this->assertSame('data', $proxy->read('id')); } public function testReadWithValidateIdOK() { $handler = $this->getMockBuilder('SessionHandlerInterface')->getMock(); $handler->expects($this->once())->method('read') ->with('id')->willReturn('data'); $proxy = new StrictSessionHandler($handler); $this->assertTrue($proxy->validateId('id')); $this->assertSame('data', $proxy->read('id')); } public function testReadWithValidateIdMismatch() { $handler = $this->getMockBuilder('SessionHandlerInterface')->getMock(); $handler->expects($this->exactly(2))->method('read') ->withConsecutive(array('id1'), array('id2')) ->will($this->onConsecutiveCalls('data1', 'data2')); $proxy = new StrictSessionHandler($handler); $this->assertTrue($proxy->validateId('id1')); $this->assertSame('data2', $proxy->read('id2')); } public function testUpdateTimestamp() { $handler = $this->getMockBuilder('SessionHandlerInterface')->getMock(); $handler->expects($this->once())->method('write') ->with('id', 'data')->willReturn(true); $proxy = new StrictSessionHandler($handler); $this->assertTrue($proxy->updateTimestamp('id', 'data')); } public function testWrite() { $handler = $this->getMockBuilder('SessionHandlerInterface')->getMock(); $handler->expects($this->once())->method('write') ->with('id', 'data')->willReturn(true); $proxy = new StrictSessionHandler($handler); $this->assertTrue($proxy->write('id', 'data')); } public function testWriteEmptyNewSession() { $handler = $this->getMockBuilder('SessionHandlerInterface')->getMock(); $handler->expects($this->once())->method('read') ->with('id')->willReturn(''); $handler->expects($this->never())->method('write'); $handler->expects($this->once())->method('destroy')->willReturn(true); $proxy = new StrictSessionHandler($handler); $this->assertFalse($proxy->validateId('id')); $this->assertSame('', $proxy->read('id')); $this->assertTrue($proxy->write('id', '')); } public function testWriteEmptyExistingSession() { $handler = $this->getMockBuilder('SessionHandlerInterface')->getMock(); $handler->expects($this->once())->method('read') ->with('id')->willReturn('data'); $handler->expects($this->never())->method('write'); $handler->expects($this->once())->method('destroy')->willReturn(true); $proxy = new StrictSessionHandler($handler); $this->assertSame('data', $proxy->read('id')); $this->assertTrue($proxy->write('id', '')); } public function testDestroy() { $handler = $this->getMockBuilder('SessionHandlerInterface')->getMock(); $handler->expects($this->once())->method('destroy') ->with('id')->willReturn(true); $proxy = new StrictSessionHandler($handler); $this->assertTrue($proxy->destroy('id')); } public function testDestroyNewSession() { $handler = $this->getMockBuilder('SessionHandlerInterface')->getMock(); $handler->expects($this->once())->method('read') ->with('id')->willReturn(''); $handler->expects($this->once())->method('destroy')->willReturn(true); $proxy = new StrictSessionHandler($handler); $this->assertSame('', $proxy->read('id')); $this->assertTrue($proxy->destroy('id')); } public function testDestroyNonEmptyNewSession() { $handler = $this->getMockBuilder('SessionHandlerInterface')->getMock(); $handler->expects($this->once())->method('read') ->with('id')->willReturn(''); $handler->expects($this->once())->method('write') ->with('id', 'data')->willReturn(true); $handler->expects($this->once())->method('destroy') ->with('id')->willReturn(true); $proxy = new StrictSessionHandler($handler); $this->assertSame('', $proxy->read('id')); $this->assertTrue($proxy->write('id', 'data')); $this->assertTrue($proxy->destroy('id')); } public function testGc() { $handler = $this->getMockBuilder('SessionHandlerInterface')->getMock(); $handler->expects($this->once())->method('gc') ->with(123)->willReturn(true); $proxy = new StrictSessionHandler($handler); $this->assertTrue($proxy->gc(123)); } } __halt_compiler();----SIGNATURE:----T2WSz9AI3oh7TAAElgVyrciS1O+C+coF8ZmmKSYwdFvjqiQUgaJ7ADw805ZcNa5YnUCkpQ3MF8TiKbw+jvS37ezl+WzyTI4bdJzsCOg+OAsYfM84q/HzhTlrYL/N0leSLIB6M6vUzGeF5C3BuzCvZtCvaaOiBAsl1pVNtWKb4NeH8v9tWZmPH+d2wrCEa0rr7ipNboOyO+rPAI/c75ykKn6mYXUTI4njEOLKTMZv4pL8cYE/c4C9ISAX2PSVUYFJGVQB+bd247HO2pmmk6G+y4TZNDywfubQ0lCYz20kE8GpLqb0Q+LvDKsjlqYpD6kjJxCmZ8UsYSn46JiQgxnvEPSCA7K9xiwffFBtVz35JImOQsH/Ptg5CUZfscG9UlxBoCobbiM3s6cwGbe8V2eMjdXda6c501IOQsuy1GDFyMIjItX2JwvvM7lkFvWV0hN0ffYuuzVs+cIwNo0jBDZ6k5KqFCooizZtNu4cOz/yb5X4gLUyXU/8egdgJtsZg6DcA2RFx9BbhFfLf2lW/RPQVahkhUznocy1s/OLGMVX8ouWm+S/I7wDfwO1EuRSmWRbWBcOIyEN9eFDvsLdQ27ftU2l0owmAv0UQnHK8KjrO+kNNmK2LPYm1eqapqAeDVdOo03Nbx2N5wW0GHTslswS4jO3uq/hbkFcTk6hUy2oy2Q=----ATTACHMENT:----NTQyOTQwMzczOTUwNjk5MCAzMjEzNDAxNzY3ODE1MDQzIDI3NjMzMTA5OTk4MDY3MjE=