NativeFileSessionHandlerTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. *
  21. * @preserveGlobalState disabled
  22. */
  23. class NativeFileSessionHandlerTest extends TestCase
  24. {
  25. public function testConstruct()
  26. {
  27. new NativeSessionStorage(['name' => 'TESTING'], new NativeFileSessionHandler(sys_get_temp_dir()));
  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. new NativeFileSessionHandler($savePath);
  38. $this->assertEquals($expectedSavePath, \ini_get('session.save_path'));
  39. $this->assertDirectoryExists(realpath($path));
  40. rmdir($path);
  41. }
  42. public static function savePathDataProvider()
  43. {
  44. $base = sys_get_temp_dir();
  45. return [
  46. ["$base/foo", "$base/foo", "$base/foo"],
  47. ["5;$base/foo", "5;$base/foo", "$base/foo"],
  48. ["5;0600;$base/foo", "5;0600;$base/foo", "$base/foo"],
  49. ];
  50. }
  51. public function testConstructException()
  52. {
  53. $this->expectException(\InvalidArgumentException::class);
  54. new NativeFileSessionHandler('something;invalid;with;too-many-args');
  55. }
  56. public function testConstructDefault()
  57. {
  58. $path = \ini_get('session.save_path');
  59. new NativeSessionStorage(['name' => 'TESTING'], new NativeFileSessionHandler());
  60. $this->assertEquals($path, \ini_get('session.save_path'));
  61. }
  62. }