SessionHandlerProxyTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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\SessionHandlerProxy;
  13. /**
  14. * Tests for SessionHandlerProxy class.
  15. *
  16. * @author Drak <drak@zikula.org>
  17. *
  18. * @runTestsInSeparateProcesses
  19. * @preserveGlobalState disabled
  20. */
  21. class SessionHandlerProxyTest extends TestCase
  22. {
  23. /**
  24. * @var \PHPUnit_Framework_MockObject_Matcher
  25. */
  26. private $mock;
  27. /**
  28. * @var SessionHandlerProxy
  29. */
  30. private $proxy;
  31. protected function setUp()
  32. {
  33. $this->mock = $this->getMockBuilder('SessionHandlerInterface')->getMock();
  34. $this->proxy = new SessionHandlerProxy($this->mock);
  35. }
  36. protected function tearDown()
  37. {
  38. $this->mock = null;
  39. $this->proxy = null;
  40. }
  41. public function testOpen()
  42. {
  43. $this->mock->expects($this->once())
  44. ->method('open')
  45. ->will($this->returnValue(true));
  46. $this->assertFalse($this->proxy->isActive());
  47. $this->proxy->open('name', 'id');
  48. if (\PHP_VERSION_ID < 50400) {
  49. $this->assertTrue($this->proxy->isActive());
  50. } else {
  51. $this->assertFalse($this->proxy->isActive());
  52. }
  53. }
  54. public function testOpenFalse()
  55. {
  56. $this->mock->expects($this->once())
  57. ->method('open')
  58. ->will($this->returnValue(false));
  59. $this->assertFalse($this->proxy->isActive());
  60. $this->proxy->open('name', 'id');
  61. $this->assertFalse($this->proxy->isActive());
  62. }
  63. public function testClose()
  64. {
  65. $this->mock->expects($this->once())
  66. ->method('close')
  67. ->will($this->returnValue(true));
  68. $this->assertFalse($this->proxy->isActive());
  69. $this->proxy->close();
  70. $this->assertFalse($this->proxy->isActive());
  71. }
  72. public function testCloseFalse()
  73. {
  74. $this->mock->expects($this->once())
  75. ->method('close')
  76. ->will($this->returnValue(false));
  77. $this->assertFalse($this->proxy->isActive());
  78. $this->proxy->close();
  79. $this->assertFalse($this->proxy->isActive());
  80. }
  81. public function testRead()
  82. {
  83. $this->mock->expects($this->once())
  84. ->method('read');
  85. $this->proxy->read('id');
  86. }
  87. public function testWrite()
  88. {
  89. $this->mock->expects($this->once())
  90. ->method('write');
  91. $this->proxy->write('id', 'data');
  92. }
  93. public function testDestroy()
  94. {
  95. $this->mock->expects($this->once())
  96. ->method('destroy');
  97. $this->proxy->destroy('id');
  98. }
  99. public function testGc()
  100. {
  101. $this->mock->expects($this->once())
  102. ->method('gc');
  103. $this->proxy->gc(86400);
  104. }
  105. }