ef1da130a2a1a84d0816b733e8e1aa8e3a209933
[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     /**
90      * @runInSeparateProcess
91      * @preserveGlobalState disabled
92      */
93     public function testIsActive()
94     {
95         $this->assertFalse($this->proxy->isActive());
96         session_start();
97         $this->assertTrue($this->proxy->isActive());
98     }
99
100     /**
101      * @runInSeparateProcess
102      * @preserveGlobalState disabled
103      */
104     public function testName()
105     {
106         $this->assertEquals(session_name(), $this->proxy->getName());
107         $this->proxy->setName('foo');
108         $this->assertEquals('foo', $this->proxy->getName());
109         $this->assertEquals(session_name(), $this->proxy->getName());
110     }
111
112     /**
113      * @runInSeparateProcess
114      * @preserveGlobalState disabled
115      * @expectedException \LogicException
116      */
117     public function testNameException()
118     {
119         session_start();
120         $this->proxy->setName('foo');
121     }
122
123     /**
124      * @runInSeparateProcess
125      * @preserveGlobalState disabled
126      */
127     public function testId()
128     {
129         $this->assertEquals(session_id(), $this->proxy->getId());
130         $this->proxy->setId('foo');
131         $this->assertEquals('foo', $this->proxy->getId());
132         $this->assertEquals(session_id(), $this->proxy->getId());
133     }
134
135     /**
136      * @runInSeparateProcess
137      * @preserveGlobalState disabled
138      * @expectedException \LogicException
139      */
140     public function testIdException()
141     {
142         session_start();
143         $this->proxy->setId('foo');
144     }
145 }