AbstractProxyTest.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Proxy;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy;
  13. // Note until PHPUnit_Mock_Objects 1.2 is released you cannot mock abstracts due to
  14. // https://github.com/sebastianbergmann/phpunit-mock-objects/issues/73
  15. class ConcreteProxy extends AbstractProxy
  16. {
  17. }
  18. class ConcreteSessionHandlerInterfaceProxy extends AbstractProxy implements \SessionHandlerInterface
  19. {
  20. public function open($savePath, $sessionName)
  21. {
  22. }
  23. public function close()
  24. {
  25. }
  26. public function read($id)
  27. {
  28. }
  29. public function write($id, $data)
  30. {
  31. }
  32. public function destroy($id)
  33. {
  34. }
  35. public function gc($maxlifetime)
  36. {
  37. }
  38. }
  39. /**
  40. * Test class for AbstractProxy.
  41. *
  42. * @author Drak <drak@zikula.org>
  43. */
  44. class AbstractProxyTest extends TestCase
  45. {
  46. /**
  47. * @var AbstractProxy
  48. */
  49. protected $proxy;
  50. protected function setUp()
  51. {
  52. $this->proxy = new ConcreteProxy();
  53. }
  54. protected function tearDown()
  55. {
  56. $this->proxy = null;
  57. }
  58. public function testGetSaveHandlerName()
  59. {
  60. $this->assertNull($this->proxy->getSaveHandlerName());
  61. }
  62. public function testIsSessionHandlerInterface()
  63. {
  64. $this->assertFalse($this->proxy->isSessionHandlerInterface());
  65. $sh = new ConcreteSessionHandlerInterfaceProxy();
  66. $this->assertTrue($sh->isSessionHandlerInterface());
  67. }
  68. public function testIsWrapper()
  69. {
  70. $this->assertFalse($this->proxy->isWrapper());
  71. }
  72. public function testIsActivePhp53()
  73. {
  74. if (\PHP_VERSION_ID >= 50400) {
  75. $this->markTestSkipped('Test skipped, for PHP 5.3 only.');
  76. }
  77. $this->assertFalse($this->proxy->isActive());
  78. }
  79. /**
  80. * @runInSeparateProcess
  81. * @preserveGlobalState disabled
  82. * @requires PHP 5.4
  83. */
  84. public function testIsActivePhp54()
  85. {
  86. $this->assertFalse($this->proxy->isActive());
  87. session_start();
  88. $this->assertTrue($this->proxy->isActive());
  89. }
  90. public function testSetActivePhp53()
  91. {
  92. if (\PHP_VERSION_ID >= 50400) {
  93. $this->markTestSkipped('Test skipped, for PHP 5.3 only.');
  94. }
  95. $this->proxy->setActive(true);
  96. $this->assertTrue($this->proxy->isActive());
  97. $this->proxy->setActive(false);
  98. $this->assertFalse($this->proxy->isActive());
  99. }
  100. /**
  101. * @runInSeparateProcess
  102. * @preserveGlobalState disabled
  103. * @expectedException \LogicException
  104. * @requires PHP 5.4
  105. */
  106. public function testSetActivePhp54()
  107. {
  108. $this->proxy->setActive(true);
  109. }
  110. /**
  111. * @runInSeparateProcess
  112. * @preserveGlobalState disabled
  113. */
  114. public function testName()
  115. {
  116. $this->assertEquals(session_name(), $this->proxy->getName());
  117. $this->proxy->setName('foo');
  118. $this->assertEquals('foo', $this->proxy->getName());
  119. $this->assertEquals(session_name(), $this->proxy->getName());
  120. }
  121. /**
  122. * @expectedException \LogicException
  123. */
  124. public function testNameExceptionPhp53()
  125. {
  126. if (\PHP_VERSION_ID >= 50400) {
  127. $this->markTestSkipped('Test skipped, for PHP 5.3 only.');
  128. }
  129. $this->proxy->setActive(true);
  130. $this->proxy->setName('foo');
  131. }
  132. /**
  133. * @runInSeparateProcess
  134. * @preserveGlobalState disabled
  135. * @expectedException \LogicException
  136. * @requires PHP 5.4
  137. */
  138. public function testNameExceptionPhp54()
  139. {
  140. session_start();
  141. $this->proxy->setName('foo');
  142. }
  143. /**
  144. * @runInSeparateProcess
  145. * @preserveGlobalState disabled
  146. */
  147. public function testId()
  148. {
  149. $this->assertEquals(session_id(), $this->proxy->getId());
  150. $this->proxy->setId('foo');
  151. $this->assertEquals('foo', $this->proxy->getId());
  152. $this->assertEquals(session_id(), $this->proxy->getId());
  153. }
  154. /**
  155. * @expectedException \LogicException
  156. */
  157. public function testIdExceptionPhp53()
  158. {
  159. if (\PHP_VERSION_ID >= 50400) {
  160. $this->markTestSkipped('Test skipped, for PHP 5.3 only.');
  161. }
  162. $this->proxy->setActive(true);
  163. $this->proxy->setId('foo');
  164. }
  165. /**
  166. * @runInSeparateProcess
  167. * @preserveGlobalState disabled
  168. * @expectedException \LogicException
  169. * @requires PHP 5.4
  170. */
  171. public function testIdExceptionPhp54()
  172. {
  173. session_start();
  174. $this->proxy->setId('foo');
  175. }
  176. }