No Description

AbstractProxyTest.php 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy;
  12. // Note until PHPUnit_Mock_Objects 1.2 is released you cannot mock abstracts due to
  13. // https://github.com/sebastianbergmann/phpunit-mock-objects/issues/73
  14. class ConcreteProxy extends AbstractProxy
  15. {
  16. }
  17. class ConcreteSessionHandlerInterfaceProxy extends AbstractProxy implements \SessionHandlerInterface
  18. {
  19. public function open($savePath, $sessionName)
  20. {
  21. }
  22. public function close()
  23. {
  24. }
  25. public function read($id)
  26. {
  27. }
  28. public function write($id, $data)
  29. {
  30. }
  31. public function destroy($id)
  32. {
  33. }
  34. public function gc($maxlifetime)
  35. {
  36. }
  37. }
  38. /**
  39. * Test class for AbstractProxy.
  40. *
  41. * @author Drak <drak@zikula.org>
  42. */
  43. class AbstractProxyTest extends \PHPUnit_Framework_TestCase
  44. {
  45. /**
  46. * @var AbstractProxy
  47. */
  48. protected $proxy;
  49. protected function setUp()
  50. {
  51. $this->proxy = new ConcreteProxy();
  52. }
  53. protected function tearDown()
  54. {
  55. $this->proxy = null;
  56. }
  57. public function testGetSaveHandlerName()
  58. {
  59. $this->assertNull($this->proxy->getSaveHandlerName());
  60. }
  61. public function testIsSessionHandlerInterface()
  62. {
  63. $this->assertFalse($this->proxy->isSessionHandlerInterface());
  64. $sh = new ConcreteSessionHandlerInterfaceProxy();
  65. $this->assertTrue($sh->isSessionHandlerInterface());
  66. }
  67. public function testIsWrapper()
  68. {
  69. $this->assertFalse($this->proxy->isWrapper());
  70. }
  71. /**
  72. * @runInSeparateProcess
  73. * @preserveGlobalState disabled
  74. */
  75. public function testIsActive()
  76. {
  77. $this->assertFalse($this->proxy->isActive());
  78. session_start();
  79. $this->assertTrue($this->proxy->isActive());
  80. }
  81. /**
  82. * @runInSeparateProcess
  83. * @preserveGlobalState disabled
  84. */
  85. public function testName()
  86. {
  87. $this->assertEquals(session_name(), $this->proxy->getName());
  88. $this->proxy->setName('foo');
  89. $this->assertEquals('foo', $this->proxy->getName());
  90. $this->assertEquals(session_name(), $this->proxy->getName());
  91. }
  92. /**
  93. * @runInSeparateProcess
  94. * @preserveGlobalState disabled
  95. * @expectedException \LogicException
  96. */
  97. public function testNameException()
  98. {
  99. session_start();
  100. $this->proxy->setName('foo');
  101. }
  102. /**
  103. * @runInSeparateProcess
  104. * @preserveGlobalState disabled
  105. */
  106. public function testId()
  107. {
  108. $this->assertEquals(session_id(), $this->proxy->getId());
  109. $this->proxy->setId('foo');
  110. $this->assertEquals('foo', $this->proxy->getId());
  111. $this->assertEquals(session_id(), $this->proxy->getId());
  112. }
  113. /**
  114. * @runInSeparateProcess
  115. * @preserveGlobalState disabled
  116. * @expectedException \LogicException
  117. */
  118. public function testIdException()
  119. {
  120. session_start();
  121. $this->proxy->setId('foo');
  122. }
  123. }