菜谱项目

WriteCheckSessionHandlerTest.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. class WriteCheckSessionHandlerTest extends TestCase
  17. {
  18. public function test()
  19. {
  20. $wrappedSessionHandlerMock = $this->getMockBuilder('SessionHandlerInterface')->getMock();
  21. $writeCheckSessionHandler = new WriteCheckSessionHandler($wrappedSessionHandlerMock);
  22. $wrappedSessionHandlerMock
  23. ->expects($this->once())
  24. ->method('close')
  25. ->with()
  26. ->will($this->returnValue(true))
  27. ;
  28. $this->assertTrue($writeCheckSessionHandler->close());
  29. }
  30. public function testWrite()
  31. {
  32. $wrappedSessionHandlerMock = $this->getMockBuilder('SessionHandlerInterface')->getMock();
  33. $writeCheckSessionHandler = new WriteCheckSessionHandler($wrappedSessionHandlerMock);
  34. $wrappedSessionHandlerMock
  35. ->expects($this->once())
  36. ->method('write')
  37. ->with('foo', 'bar')
  38. ->will($this->returnValue(true))
  39. ;
  40. $this->assertTrue($writeCheckSessionHandler->write('foo', 'bar'));
  41. }
  42. public function testSkippedWrite()
  43. {
  44. $wrappedSessionHandlerMock = $this->getMockBuilder('SessionHandlerInterface')->getMock();
  45. $writeCheckSessionHandler = new WriteCheckSessionHandler($wrappedSessionHandlerMock);
  46. $wrappedSessionHandlerMock
  47. ->expects($this->once())
  48. ->method('read')
  49. ->with('foo')
  50. ->will($this->returnValue('bar'))
  51. ;
  52. $wrappedSessionHandlerMock
  53. ->expects($this->never())
  54. ->method('write')
  55. ;
  56. $this->assertEquals('bar', $writeCheckSessionHandler->read('foo'));
  57. $this->assertTrue($writeCheckSessionHandler->write('foo', 'bar'));
  58. }
  59. public function testNonSkippedWrite()
  60. {
  61. $wrappedSessionHandlerMock = $this->getMockBuilder('SessionHandlerInterface')->getMock();
  62. $writeCheckSessionHandler = new WriteCheckSessionHandler($wrappedSessionHandlerMock);
  63. $wrappedSessionHandlerMock
  64. ->expects($this->once())
  65. ->method('read')
  66. ->with('foo')
  67. ->will($this->returnValue('bar'))
  68. ;
  69. $wrappedSessionHandlerMock
  70. ->expects($this->once())
  71. ->method('write')
  72. ->with('foo', 'baZZZ')
  73. ->will($this->returnValue(true))
  74. ;
  75. $this->assertEquals('bar', $writeCheckSessionHandler->read('foo'));
  76. $this->assertTrue($writeCheckSessionHandler->write('foo', 'baZZZ'));
  77. }
  78. }