菜谱项目

NativeFileSessionHandlerTest.php 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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\NativeFileSessionHandler;
  13. use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
  14. /**
  15. * Test class for NativeFileSessionHandler.
  16. *
  17. * @author Drak <drak@zikula.org>
  18. *
  19. * @runTestsInSeparateProcesses
  20. * @preserveGlobalState disabled
  21. */
  22. class NativeFileSessionHandlerTest extends TestCase
  23. {
  24. public function testConstruct()
  25. {
  26. $storage = new NativeSessionStorage(array('name' => 'TESTING'), new NativeFileSessionHandler(sys_get_temp_dir()));
  27. $this->assertEquals('files', $storage->getSaveHandler()->getSaveHandlerName());
  28. $this->assertEquals('user', ini_get('session.save_handler'));
  29. $this->assertEquals(sys_get_temp_dir(), ini_get('session.save_path'));
  30. $this->assertEquals('TESTING', ini_get('session.name'));
  31. }
  32. /**
  33. * @dataProvider savePathDataProvider
  34. */
  35. public function testConstructSavePath($savePath, $expectedSavePath, $path)
  36. {
  37. $handler = new NativeFileSessionHandler($savePath);
  38. $this->assertEquals($expectedSavePath, ini_get('session.save_path'));
  39. $this->assertTrue(is_dir(realpath($path)));
  40. rmdir($path);
  41. }
  42. public function savePathDataProvider()
  43. {
  44. $base = sys_get_temp_dir();
  45. return array(
  46. array("$base/foo", "$base/foo", "$base/foo"),
  47. array("5;$base/foo", "5;$base/foo", "$base/foo"),
  48. array("5;0600;$base/foo", "5;0600;$base/foo", "$base/foo"),
  49. );
  50. }
  51. /**
  52. * @expectedException \InvalidArgumentException
  53. */
  54. public function testConstructException()
  55. {
  56. $handler = new NativeFileSessionHandler('something;invalid;with;too-many-args');
  57. }
  58. public function testConstructDefault()
  59. {
  60. $path = ini_get('session.save_path');
  61. $storage = new NativeSessionStorage(array('name' => 'TESTING'), new NativeFileSessionHandler());
  62. $this->assertEquals($path, ini_get('session.save_path'));
  63. }
  64. }