No Description

SessionHandlerProxyTest.php 2.9KB

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