菜谱项目

AbstractProxyTest.php 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. /**
  73. * @runInSeparateProcess
  74. * @preserveGlobalState disabled
  75. */
  76. public function testIsActive()
  77. {
  78. $this->assertFalse($this->proxy->isActive());
  79. session_start();
  80. $this->assertTrue($this->proxy->isActive());
  81. }
  82. /**
  83. * @runInSeparateProcess
  84. * @preserveGlobalState disabled
  85. */
  86. public function testName()
  87. {
  88. $this->assertEquals(session_name(), $this->proxy->getName());
  89. $this->proxy->setName('foo');
  90. $this->assertEquals('foo', $this->proxy->getName());
  91. $this->assertEquals(session_name(), $this->proxy->getName());
  92. }
  93. /**
  94. * @runInSeparateProcess
  95. * @preserveGlobalState disabled
  96. * @expectedException \LogicException
  97. */
  98. public function testNameException()
  99. {
  100. session_start();
  101. $this->proxy->setName('foo');
  102. }
  103. /**
  104. * @runInSeparateProcess
  105. * @preserveGlobalState disabled
  106. */
  107. public function testId()
  108. {
  109. $this->assertEquals(session_id(), $this->proxy->getId());
  110. $this->proxy->setId('foo');
  111. $this->assertEquals('foo', $this->proxy->getId());
  112. $this->assertEquals(session_id(), $this->proxy->getId());
  113. }
  114. /**
  115. * @runInSeparateProcess
  116. * @preserveGlobalState disabled
  117. * @expectedException \LogicException
  118. */
  119. public function testIdException()
  120. {
  121. session_start();
  122. $this->proxy->setId('foo');
  123. }
  124. }