WriteCheckSessionHandlerTest.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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\Handler;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\HttpFoundation\Session\Storage\Handler\WriteCheckSessionHandler;
  13. /**
  14. * @author Adrien Brault <adrien.brault@gmail.com>
  15. *
  16. * @group legacy
  17. */
  18. class WriteCheckSessionHandlerTest extends TestCase
  19. {
  20. public function test()
  21. {
  22. $wrappedSessionHandlerMock = $this->getMockBuilder('SessionHandlerInterface')->getMock();
  23. $writeCheckSessionHandler = new WriteCheckSessionHandler($wrappedSessionHandlerMock);
  24. $wrappedSessionHandlerMock
  25. ->expects($this->once())
  26. ->method('close')
  27. ->with()
  28. ->will($this->returnValue(true))
  29. ;
  30. $this->assertTrue($writeCheckSessionHandler->close());
  31. }
  32. public function testWrite()
  33. {
  34. $wrappedSessionHandlerMock = $this->getMockBuilder('SessionHandlerInterface')->getMock();
  35. $writeCheckSessionHandler = new WriteCheckSessionHandler($wrappedSessionHandlerMock);
  36. $wrappedSessionHandlerMock
  37. ->expects($this->once())
  38. ->method('write')
  39. ->with('foo', 'bar')
  40. ->will($this->returnValue(true))
  41. ;
  42. $this->assertTrue($writeCheckSessionHandler->write('foo', 'bar'));
  43. }
  44. public function testSkippedWrite()
  45. {
  46. $wrappedSessionHandlerMock = $this->getMockBuilder('SessionHandlerInterface')->getMock();
  47. $writeCheckSessionHandler = new WriteCheckSessionHandler($wrappedSessionHandlerMock);
  48. $wrappedSessionHandlerMock
  49. ->expects($this->once())
  50. ->method('read')
  51. ->with('foo')
  52. ->will($this->returnValue('bar'))
  53. ;
  54. $wrappedSessionHandlerMock
  55. ->expects($this->never())
  56. ->method('write')
  57. ;
  58. $this->assertEquals('bar', $writeCheckSessionHandler->read('foo'));
  59. $this->assertTrue($writeCheckSessionHandler->write('foo', 'bar'));
  60. }
  61. public function testNonSkippedWrite()
  62. {
  63. $wrappedSessionHandlerMock = $this->getMockBuilder('SessionHandlerInterface')->getMock();
  64. $writeCheckSessionHandler = new WriteCheckSessionHandler($wrappedSessionHandlerMock);
  65. $wrappedSessionHandlerMock
  66. ->expects($this->once())
  67. ->method('read')
  68. ->with('foo')
  69. ->will($this->returnValue('bar'))
  70. ;
  71. $wrappedSessionHandlerMock
  72. ->expects($this->once())
  73. ->method('write')
  74. ->with('foo', 'baZZZ')
  75. ->will($this->returnValue(true))
  76. ;
  77. $this->assertEquals('bar', $writeCheckSessionHandler->read('foo'));
  78. $this->assertTrue($writeCheckSessionHandler->write('foo', 'baZZZ'));
  79. }
  80. }