Yaffs site version 1.1
[yaffs-website] / vendor / symfony / http-foundation / Tests / Session / Storage / Proxy / AbstractProxyTest.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\AbstractProxy;
16
17 // Note until PHPUnit_Mock_Objects 1.2 is released you cannot mock abstracts due to
18 // https://github.com/sebastianbergmann/phpunit-mock-objects/issues/73
19 class ConcreteProxy extends AbstractProxy
20 {
21 }
22
23 class ConcreteSessionHandlerInterfaceProxy extends AbstractProxy implements \SessionHandlerInterface
24 {
25     public function open($savePath, $sessionName)
26     {
27     }
28
29     public function close()
30     {
31     }
32
33     public function read($id)
34     {
35     }
36
37     public function write($id, $data)
38     {
39     }
40
41     public function destroy($id)
42     {
43     }
44
45     public function gc($maxlifetime)
46     {
47     }
48 }
49
50 /**
51  * Test class for AbstractProxy.
52  *
53  * @author Drak <drak@zikula.org>
54  */
55 class AbstractProxyTest extends TestCase
56 {
57     /**
58      * @var AbstractProxy
59      */
60     protected $proxy;
61
62     protected function setUp()
63     {
64         $this->proxy = new ConcreteProxy();
65     }
66
67     protected function tearDown()
68     {
69         $this->proxy = null;
70     }
71
72     public function testGetSaveHandlerName()
73     {
74         $this->assertNull($this->proxy->getSaveHandlerName());
75     }
76
77     public function testIsSessionHandlerInterface()
78     {
79         $this->assertFalse($this->proxy->isSessionHandlerInterface());
80         $sh = new ConcreteSessionHandlerInterfaceProxy();
81         $this->assertTrue($sh->isSessionHandlerInterface());
82     }
83
84     public function testIsWrapper()
85     {
86         $this->assertFalse($this->proxy->isWrapper());
87     }
88
89     public function testIsActivePhp53()
90     {
91         if (\PHP_VERSION_ID >= 50400) {
92             $this->markTestSkipped('Test skipped, for PHP 5.3 only.');
93         }
94
95         $this->assertFalse($this->proxy->isActive());
96     }
97
98     /**
99      * @runInSeparateProcess
100      * @preserveGlobalState disabled
101      * @requires PHP 5.4
102      */
103     public function testIsActivePhp54()
104     {
105         $this->assertFalse($this->proxy->isActive());
106         session_start();
107         $this->assertTrue($this->proxy->isActive());
108     }
109
110     public function testSetActivePhp53()
111     {
112         if (\PHP_VERSION_ID >= 50400) {
113             $this->markTestSkipped('Test skipped, for PHP 5.3 only.');
114         }
115
116         $this->proxy->setActive(true);
117         $this->assertTrue($this->proxy->isActive());
118         $this->proxy->setActive(false);
119         $this->assertFalse($this->proxy->isActive());
120     }
121
122     /**
123      * @runInSeparateProcess
124      * @preserveGlobalState disabled
125      * @expectedException \LogicException
126      * @requires PHP 5.4
127      */
128     public function testSetActivePhp54()
129     {
130         $this->proxy->setActive(true);
131     }
132
133     /**
134      * @runInSeparateProcess
135      * @preserveGlobalState disabled
136      */
137     public function testName()
138     {
139         $this->assertEquals(session_name(), $this->proxy->getName());
140         $this->proxy->setName('foo');
141         $this->assertEquals('foo', $this->proxy->getName());
142         $this->assertEquals(session_name(), $this->proxy->getName());
143     }
144
145     /**
146      * @expectedException \LogicException
147      */
148     public function testNameExceptionPhp53()
149     {
150         if (\PHP_VERSION_ID >= 50400) {
151             $this->markTestSkipped('Test skipped, for PHP 5.3 only.');
152         }
153
154         $this->proxy->setActive(true);
155         $this->proxy->setName('foo');
156     }
157
158     /**
159      * @runInSeparateProcess
160      * @preserveGlobalState disabled
161      * @expectedException \LogicException
162      * @requires PHP 5.4
163      */
164     public function testNameExceptionPhp54()
165     {
166         session_start();
167         $this->proxy->setName('foo');
168     }
169
170     /**
171      * @runInSeparateProcess
172      * @preserveGlobalState disabled
173      */
174     public function testId()
175     {
176         $this->assertEquals(session_id(), $this->proxy->getId());
177         $this->proxy->setId('foo');
178         $this->assertEquals('foo', $this->proxy->getId());
179         $this->assertEquals(session_id(), $this->proxy->getId());
180     }
181
182     /**
183      * @expectedException \LogicException
184      */
185     public function testIdExceptionPhp53()
186     {
187         if (\PHP_VERSION_ID >= 50400) {
188             $this->markTestSkipped('Test skipped, for PHP 5.3 only.');
189         }
190
191         $this->proxy->setActive(true);
192         $this->proxy->setId('foo');
193     }
194
195     /**
196      * @runInSeparateProcess
197      * @preserveGlobalState disabled
198      * @expectedException \LogicException
199      * @requires PHP 5.4
200      */
201     public function testIdExceptionPhp54()
202     {
203         session_start();
204         $this->proxy->setId('foo');
205     }
206 }