Yaffs site version 1.1
[yaffs-website] / vendor / symfony / http-foundation / Tests / Session / Storage / Proxy / SessionHandlerProxyTest.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
12 namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Proxy;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy;
16
17 /**
18  * Tests for SessionHandlerProxy class.
19  *
20  * @author Drak <drak@zikula.org>
21  *
22  * @runTestsInSeparateProcesses
23  * @preserveGlobalState disabled
24  */
25 class SessionHandlerProxyTest extends TestCase
26 {
27     /**
28      * @var \PHPUnit_Framework_MockObject_Matcher
29      */
30     private $mock;
31
32     /**
33      * @var SessionHandlerProxy
34      */
35     private $proxy;
36
37     protected function setUp()
38     {
39         $this->mock = $this->getMockBuilder('SessionHandlerInterface')->getMock();
40         $this->proxy = new SessionHandlerProxy($this->mock);
41     }
42
43     protected function tearDown()
44     {
45         $this->mock = null;
46         $this->proxy = null;
47     }
48
49     public function testOpen()
50     {
51         $this->mock->expects($this->once())
52             ->method('open')
53             ->will($this->returnValue(true));
54
55         $this->assertFalse($this->proxy->isActive());
56         $this->proxy->open('name', 'id');
57         if (\PHP_VERSION_ID < 50400) {
58             $this->assertTrue($this->proxy->isActive());
59         } else {
60             $this->assertFalse($this->proxy->isActive());
61         }
62     }
63
64     public function testOpenFalse()
65     {
66         $this->mock->expects($this->once())
67             ->method('open')
68             ->will($this->returnValue(false));
69
70         $this->assertFalse($this->proxy->isActive());
71         $this->proxy->open('name', 'id');
72         $this->assertFalse($this->proxy->isActive());
73     }
74
75     public function testClose()
76     {
77         $this->mock->expects($this->once())
78             ->method('close')
79             ->will($this->returnValue(true));
80
81         $this->assertFalse($this->proxy->isActive());
82         $this->proxy->close();
83         $this->assertFalse($this->proxy->isActive());
84     }
85
86     public function testCloseFalse()
87     {
88         $this->mock->expects($this->once())
89             ->method('close')
90             ->will($this->returnValue(false));
91
92         $this->assertFalse($this->proxy->isActive());
93         $this->proxy->close();
94         $this->assertFalse($this->proxy->isActive());
95     }
96
97     public function testRead()
98     {
99         $this->mock->expects($this->once())
100             ->method('read');
101
102         $this->proxy->read('id');
103     }
104
105     public function testWrite()
106     {
107         $this->mock->expects($this->once())
108             ->method('write');
109
110         $this->proxy->write('id', 'data');
111     }
112
113     public function testDestroy()
114     {
115         $this->mock->expects($this->once())
116             ->method('destroy');
117
118         $this->proxy->destroy('id');
119     }
120
121     public function testGc()
122     {
123         $this->mock->expects($this->once())
124             ->method('gc');
125
126         $this->proxy->gc(86400);
127     }
128 }