Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6386d39

Browse files
cvillegernicolas-grekas
authored andcommitted
[HttpFoundation] Add functional tests for Request::sendHeaders()
1 parent e350ea0 commit 6386d39

File tree

6 files changed

+127
-0
lines changed

6 files changed

+127
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
$parent = __DIR__;
4+
while (!@file_exists($parent.'/vendor/autoload.php')) {
5+
if (!@file_exists($parent)) {
6+
// open_basedir restriction in effect
7+
break;
8+
}
9+
if ($parent === dirname($parent)) {
10+
echo "vendor/autoload.php not found\n";
11+
exit(1);
12+
}
13+
14+
$parent = dirname($parent);
15+
}
16+
17+
require $parent.'/vendor/autoload.php';
18+
19+
error_reporting(-1);
20+
ini_set('html_errors', 0);
21+
ini_set('display_errors', 1);
22+
23+
header_remove('X-Powered-By');
24+
header('Content-Type: text/plain; charset=utf-8');
25+
26+
register_shutdown_function(function () {
27+
echo "\n";
28+
session_write_close();
29+
print_r(headers_list());
30+
echo "shutdown\n";
31+
});
32+
ob_start();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
Array
3+
(
4+
[0] => Content-Type: text/plain; charset=utf-8
5+
[1] => Cache-Control: no-cache, private
6+
[2] => Date: Sat, 12 Nov 1955 20:04:00 GMT
7+
[3] => Set-Cookie: CookieSamesiteLaxTest=LaxValue; path=/; httponly; samesite=lax
8+
)
9+
shutdown
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
use Symfony\Component\HttpFoundation\Cookie;
4+
use Symfony\Component\HttpFoundation\Response;
5+
6+
require __DIR__.'/common.inc';
7+
8+
$r = new Response();
9+
$r->headers->set('Date', 'Sat, 12 Nov 1955 20:04:00 GMT');
10+
$r->headers->setCookie(new Cookie('CookieSamesiteLaxTest', 'LaxValue', 0, '/', null, false, true, false, Cookie::SAMESITE_LAX));
11+
$r->sendHeaders();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
Array
3+
(
4+
[0] => Content-Type: text/plain; charset=utf-8
5+
[1] => Cache-Control: no-cache, private
6+
[2] => Date: Sat, 12 Nov 1955 20:04:00 GMT
7+
[3] => Set-Cookie: CookieSamesiteStrictTest=StrictValue; path=/; httponly; samesite=strict
8+
)
9+
shutdown
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
use Symfony\Component\HttpFoundation\Cookie;
4+
use Symfony\Component\HttpFoundation\Response;
5+
6+
require __DIR__.'/common.inc';
7+
8+
$r = new Response();
9+
$r->headers->set('Date', 'Sat, 12 Nov 1955 20:04:00 GMT');
10+
$r->headers->setCookie(new Cookie('CookieSamesiteStrictTest', 'StrictValue', 0, '/', null, false, true, false, Cookie::SAMESITE_STRICT));
11+
$r->sendHeaders();
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpFoundation\Tests;
13+
14+
use PHPUnit\Framework\TestCase;
15+
16+
class RequestFunctionalTest extends TestCase
17+
{
18+
private static $server;
19+
20+
public static function setUpBeforeClass()
21+
{
22+
$spec = array(
23+
1 => array('file', '/dev/null', 'w'),
24+
2 => array('file', '/dev/null', 'w'),
25+
);
26+
if (!self::$server = @proc_open('exec php -S localhost:8054', $spec, $pipes, __DIR__.'/Fixtures')) {
27+
self::markTestSkipped('PHP server unable to start.');
28+
}
29+
sleep(1);
30+
}
31+
32+
public static function tearDownAfterClass()
33+
{
34+
if (self::$server) {
35+
proc_terminate(self::$server);
36+
proc_close(self::$server);
37+
}
38+
}
39+
40+
/**
41+
* @dataProvider provideCookie
42+
*/
43+
public function testCookieSamesite($fixture)
44+
{
45+
$result = file_get_contents(sprintf('http://localhost:8054/%s.php', $fixture));
46+
$this->assertStringEqualsFile(__DIR__.sprintf('/Fixtures/%s.expected', $fixture), $result);
47+
}
48+
49+
public function provideCookie()
50+
{
51+
foreach (glob(__DIR__.'/Fixtures/cookie_*.php') as $file) {
52+
yield array(pathinfo($file, PATHINFO_FILENAME));
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)