NativeFileSessionHandlerTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. if (\PHP_VERSION_ID < 50400) {
  28. $this->assertEquals('files', $storage->getSaveHandler()->getSaveHandlerName());
  29. $this->assertEquals('files', ini_get('session.save_handler'));
  30. } else {
  31. $this->assertEquals('files', $storage->getSaveHandler()->getSaveHandlerName());
  32. $this->assertEquals('user', ini_get('session.save_handler'));
  33. }
  34. $this->assertEquals(sys_get_temp_dir(), ini_get('session.save_path'));
  35. $this->assertEquals('TESTING', ini_get('session.name'));
  36. }
  37. /**
  38. * @dataProvider savePathDataProvider
  39. */
  40. public function testConstructSavePath($savePath, $expectedSavePath, $path)
  41. {
  42. $handler = new NativeFileSessionHandler($savePath);
  43. $this->assertEquals($expectedSavePath, ini_get('session.save_path'));
  44. $this->assertTrue(is_dir(realpath($path)));
  45. rmdir($path);
  46. }
  47. public function savePathDataProvider()
  48. {
  49. $base = sys_get_temp_dir();
  50. return array(
  51. array("$base/foo", "$base/foo", "$base/foo"),
  52. array("5;$base/foo", "5;$base/foo", "$base/foo"),
  53. array("5;0600;$base/foo", "5;0600;$base/foo", "$base/foo"),
  54. );
  55. }
  56. /**
  57. * @expectedException \InvalidArgumentException
  58. */
  59. public function testConstructException()
  60. {
  61. $handler = new NativeFileSessionHandler('something;invalid;with;too-many-args');
  62. }
  63. public function testConstructDefault()
  64. {
  65. $path = ini_get('session.save_path');
  66. $storage = new NativeSessionStorage(array('name' => 'TESTING'), new NativeFileSessionHandler());
  67. $this->assertEquals($path, ini_get('session.save_path'));
  68. }
  69. }