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;
13
14use PHPUnit\Framework\TestCase;
15
16/**
17 * @requires PHP 7.0
18 */
19class ResponseFunctionalTest 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:8054', $spec, $pipes, __DIR__.'/Fixtures/response-functional')) {
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 provideCookie
45     */
46    public function testCookie($fixture)
47    {
48        if (\PHP_VERSION_ID >= 80000 && 'cookie_max_age' === $fixture) {
49            $this->markTestSkipped('This fixture produces a fatal error on PHP 8.');
50        }
51
52        $result = file_get_contents(sprintf('http://localhost:8054/%s.php', $fixture));
53        $this->assertStringMatchesFormatFile(__DIR__.sprintf('/Fixtures/response-functional/%s.expected', $fixture), $result);
54    }
55
56    public function provideCookie()
57    {
58        foreach (glob(__DIR__.'/Fixtures/response-functional/*.php') as $file) {
59            yield [pathinfo($file, \PATHINFO_FILENAME)];
60        }
61    }
62}
63