Open Monograph Press  3.3.0
WriteCheckSessionHandlerTest.php
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
13 
14 use PHPUnit\Framework\TestCase;
16 
20 class WriteCheckSessionHandlerTest extends TestCase
21 {
22  public function test()
23  {
24  $wrappedSessionHandlerMock = $this->getMockBuilder('SessionHandlerInterface')->getMock();
25  $writeCheckSessionHandler = new WriteCheckSessionHandler($wrappedSessionHandlerMock);
26 
27  $wrappedSessionHandlerMock
28  ->expects($this->once())
29  ->method('close')
30  ->with()
31  ->will($this->returnValue(true))
32  ;
33 
34  $this->assertTrue($writeCheckSessionHandler->close());
35  }
36 
37  public function testWrite()
38  {
39  $wrappedSessionHandlerMock = $this->getMockBuilder('SessionHandlerInterface')->getMock();
40  $writeCheckSessionHandler = new WriteCheckSessionHandler($wrappedSessionHandlerMock);
41 
42  $wrappedSessionHandlerMock
43  ->expects($this->once())
44  ->method('write')
45  ->with('foo', 'bar')
46  ->will($this->returnValue(true))
47  ;
48 
49  $this->assertTrue($writeCheckSessionHandler->write('foo', 'bar'));
50  }
51 
52  public function testSkippedWrite()
53  {
54  $wrappedSessionHandlerMock = $this->getMockBuilder('SessionHandlerInterface')->getMock();
55  $writeCheckSessionHandler = new WriteCheckSessionHandler($wrappedSessionHandlerMock);
56 
57  $wrappedSessionHandlerMock
58  ->expects($this->once())
59  ->method('read')
60  ->with('foo')
61  ->will($this->returnValue('bar'))
62  ;
63 
64  $wrappedSessionHandlerMock
65  ->expects($this->never())
66  ->method('write')
67  ;
68 
69  $this->assertEquals('bar', $writeCheckSessionHandler->read('foo'));
70  $this->assertTrue($writeCheckSessionHandler->write('foo', 'bar'));
71  }
72 
73  public function testNonSkippedWrite()
74  {
75  $wrappedSessionHandlerMock = $this->getMockBuilder('SessionHandlerInterface')->getMock();
76  $writeCheckSessionHandler = new WriteCheckSessionHandler($wrappedSessionHandlerMock);
77 
78  $wrappedSessionHandlerMock
79  ->expects($this->once())
80  ->method('read')
81  ->with('foo')
82  ->will($this->returnValue('bar'))
83  ;
84 
85  $wrappedSessionHandlerMock
86  ->expects($this->once())
87  ->method('write')
88  ->with('foo', 'baZZZ')
89  ->will($this->returnValue(true))
90  ;
91 
92  $this->assertEquals('bar', $writeCheckSessionHandler->read('foo'));
93  $this->assertTrue($writeCheckSessionHandler->write('foo', 'baZZZ'));
94  }
95 }
Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\WriteCheckSessionHandlerTest\testNonSkippedWrite
testNonSkippedWrite()
Definition: WriteCheckSessionHandlerTest.php:73
Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\WriteCheckSessionHandlerTest\testWrite
testWrite()
Definition: WriteCheckSessionHandlerTest.php:37
Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\WriteCheckSessionHandlerTest\test
test()
Definition: WriteCheckSessionHandlerTest.php:22
Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\WriteCheckSessionHandlerTest
Definition: WriteCheckSessionHandlerTest.php:20
Symfony\Component\HttpFoundation\Session\Storage\Handler\WriteCheckSessionHandler
Definition: WriteCheckSessionHandler.php:19
Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\WriteCheckSessionHandlerTest\testSkippedWrite
testSkippedWrite()
Definition: WriteCheckSessionHandlerTest.php:52
Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler
Definition: MemcachedSessionHandlerTest.php:12