1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
13
14use PHPUnit\Framework\TestCase;
15
16/**
17 * @requires PHP 7.0
18 */
19class AbstractSessionHandlerTest extends TestCase
20{
21    private static $server;
22
23    public static function setUpBeforeClass()
24    {
25        $spec = [
26            1 => ['file', '/dev/null', 'w'],
27            2 => ['file', '/dev/null', 'w'],
28        ];
29        if (!self::$server = @proc_open('exec php -S localhost:8053', $spec, $pipes, __DIR__.'/Fixtures')) {
30            self::markTestSkipped('PHP server unable to start.');
31        }
32        sleep(1);
33    }
34
35    public static function tearDownAfterClass()
36    {
37        if (self::$server) {
38            proc_terminate(self::$server);
39            proc_close(self::$server);
40        }
41    }
42
43    /**
44     * @dataProvider provideSession
45     */
46    public function testSession($fixture)
47    {
48        $context = ['http' => ['header' => "Cookie: sid=123abc\r\n"]];
49        $context = stream_context_create($context);
50        $result = file_get_contents(sprintf('http://localhost:8053/%s.php', $fixture), false, $context);
51
52        $this->assertStringEqualsFile(__DIR__.sprintf('/Fixtures/%s.expected', $fixture), $result);
53    }
54
55    public function provideSession()
56    {
57        foreach (glob(__DIR__.'/Fixtures/*.php') as $file) {
58            yield [pathinfo($file, \PATHINFO_FILENAME)];
59        }
60    }
61}
62