ResponseFunctionalTest.php 1.8 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;
  11. use PHPUnit\Framework\SkippedTestSuiteError;
  12. use PHPUnit\Framework\TestCase;
  13. class ResponseFunctionalTest extends TestCase
  14. {
  15. private static $server;
  16. public static function setUpBeforeClass(): void
  17. {
  18. $spec = [
  19. 1 => ['file', '/dev/null', 'w'],
  20. 2 => ['file', '/dev/null', 'w'],
  21. ];
  22. if (!self::$server = @proc_open('exec '.\PHP_BINARY.' -S localhost:8054', $spec, $pipes, __DIR__.'/Fixtures/response-functional')) {
  23. throw new SkippedTestSuiteError('PHP server unable to start.');
  24. }
  25. sleep(1);
  26. }
  27. public static function tearDownAfterClass(): void
  28. {
  29. if (self::$server) {
  30. proc_terminate(self::$server);
  31. proc_close(self::$server);
  32. }
  33. }
  34. /**
  35. * @dataProvider provideCookie
  36. */
  37. public function testCookie($fixture)
  38. {
  39. if (\PHP_VERSION_ID >= 80000 && 'cookie_max_age' === $fixture) {
  40. $this->markTestSkipped('This fixture produces a fatal error on PHP 8.');
  41. }
  42. $result = file_get_contents(sprintf('http://localhost:8054/%s.php', $fixture));
  43. $result = preg_replace_callback('/expires=[^;]++/', function ($m) { return str_replace('-', ' ', $m[0]); }, $result);
  44. $this->assertStringMatchesFormatFile(__DIR__.sprintf('/Fixtures/response-functional/%s.expected', $fixture), $result);
  45. }
  46. public static function provideCookie()
  47. {
  48. foreach (glob(__DIR__.'/Fixtures/response-functional/*.php') as $file) {
  49. yield [pathinfo($file, \PATHINFO_FILENAME)];
  50. }
  51. }
  52. }