AbstractProxyTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy;
  14. /**
  15. * Test class for AbstractProxy.
  16. *
  17. * @author Drak <drak@zikula.org>
  18. */
  19. class AbstractProxyTest extends TestCase
  20. {
  21. /**
  22. * @var AbstractProxy
  23. */
  24. protected $proxy;
  25. protected function setUp()
  26. {
  27. $this->proxy = $this->getMockForAbstractClass(AbstractProxy::class);
  28. }
  29. protected function tearDown()
  30. {
  31. $this->proxy = null;
  32. }
  33. public function testGetSaveHandlerName()
  34. {
  35. $this->assertNull($this->proxy->getSaveHandlerName());
  36. }
  37. public function testIsSessionHandlerInterface()
  38. {
  39. $this->assertFalse($this->proxy->isSessionHandlerInterface());
  40. $sh = new SessionHandlerProxy(new \SessionHandler());
  41. $this->assertTrue($sh->isSessionHandlerInterface());
  42. }
  43. public function testIsWrapper()
  44. {
  45. $this->assertFalse($this->proxy->isWrapper());
  46. }
  47. /**
  48. * @runInSeparateProcess
  49. * @preserveGlobalState disabled
  50. */
  51. public function testIsActive()
  52. {
  53. $this->assertFalse($this->proxy->isActive());
  54. session_start();
  55. $this->assertTrue($this->proxy->isActive());
  56. }
  57. /**
  58. * @runInSeparateProcess
  59. * @preserveGlobalState disabled
  60. */
  61. public function testName()
  62. {
  63. $this->assertEquals(session_name(), $this->proxy->getName());
  64. $this->proxy->setName('foo');
  65. $this->assertEquals('foo', $this->proxy->getName());
  66. $this->assertEquals(session_name(), $this->proxy->getName());
  67. }
  68. /**
  69. * @runInSeparateProcess
  70. * @preserveGlobalState disabled
  71. * @expectedException \LogicException
  72. */
  73. public function testNameException()
  74. {
  75. session_start();
  76. $this->proxy->setName('foo');
  77. }
  78. /**
  79. * @runInSeparateProcess
  80. * @preserveGlobalState disabled
  81. */
  82. public function testId()
  83. {
  84. $this->assertEquals(session_id(), $this->proxy->getId());
  85. $this->proxy->setId('foo');
  86. $this->assertEquals('foo', $this->proxy->getId());
  87. $this->assertEquals(session_id(), $this->proxy->getId());
  88. }
  89. /**
  90. * @runInSeparateProcess
  91. * @preserveGlobalState disabled
  92. * @expectedException \LogicException
  93. */
  94. public function testIdException()
  95. {
  96. session_start();
  97. $this->proxy->setId('foo');
  98. }
  99. }