AbstractSessionHandlerTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. /**
  13. * @requires PHP 7.0
  14. */
  15. class AbstractSessionHandlerTest extends TestCase
  16. {
  17. private static $server;
  18. public static function setUpBeforeClass()
  19. {
  20. $spec = [
  21. 1 => ['file', '/dev/null', 'w'],
  22. 2 => ['file', '/dev/null', 'w'],
  23. ];
  24. if (!self::$server = @proc_open('exec php -S localhost:8053', $spec, $pipes, __DIR__.'/Fixtures')) {
  25. self::markTestSkipped('PHP server unable to start.');
  26. }
  27. sleep(1);
  28. }
  29. public static function tearDownAfterClass()
  30. {
  31. if (self::$server) {
  32. proc_terminate(self::$server);
  33. proc_close(self::$server);
  34. }
  35. }
  36. /**
  37. * @dataProvider provideSession
  38. */
  39. public function testSession($fixture)
  40. {
  41. $context = ['http' => ['header' => "Cookie: sid=123abc\r\n"]];
  42. $context = stream_context_create($context);
  43. $result = file_get_contents(sprintf('http://localhost:8053/%s.php', $fixture), false, $context);
  44. $this->assertStringEqualsFile(__DIR__.sprintf('/Fixtures/%s.expected', $fixture), $result);
  45. }
  46. public function provideSession()
  47. {
  48. foreach (glob(__DIR__.'/Fixtures/*.php') as $file) {
  49. yield [pathinfo($file, PATHINFO_FILENAME)];
  50. }
  51. }
  52. }