Skip to content

Commit

Permalink
Add FPM test for php_admin_value doc_root usage
Browse files Browse the repository at this point in the history
Closes GH-7673.
  • Loading branch information
bukka authored and nikic committed Nov 23, 2021
1 parent 96da461 commit 435a5ac
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
46 changes: 46 additions & 0 deletions sapi/fpm/tests/php-admin-doc-root.phpt
@@ -0,0 +1,46 @@
--TEST--
FPM: php_admin_value doc_root usage
--SKIPIF--
<?php include "skipif.inc"; ?>
--FILE--
<?php

require_once "tester.inc";

$docRoot = __DIR__ . '/';

$cfg = <<<EOT
[global]
error_log = {{FILE:LOG}}
[unconfined]
listen = {{ADDR}}
pm = dynamic
pm.max_children = 5
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 3
php_admin_value[doc_root] = $docRoot
EOT;

$code = <<<EOT
<?php
echo "OK";
EOT;

$tester = new FPM\Tester($cfg, $code);
$sourceFile = $tester->makeSourceFile();
$tester->start();
$tester->expectLogStartNotices();
$tester->request(uri: basename($sourceFile), scriptFilename: $sourceFile)->expectBody('OK');
$tester->terminate();
$tester->close();

?>
Done
--EXPECT--
Done
--CLEAN--
<?php
require_once "tester.inc";
FPM\Tester::clean();
?>
16 changes: 8 additions & 8 deletions sapi/fpm/tests/tester.inc
Expand Up @@ -527,16 +527,14 @@ class Tester
* @param string $query
* @param array $headers
* @param string|null $uri
* @param string|null $address
* @param string|null $successMessage
* @param string|null $errorMessage
* @param bool $connKeepAlive
* @param string|null $scriptFilename
* @return array
*/
private function getRequestParams(
string $query = '',
array $headers = [],
string $uri = null
string $uri = null,
string $scriptFilename = null
) {
if (is_null($uri)) {
$uri = $this->makeSourceFile();
Expand All @@ -546,7 +544,7 @@ class Tester
[
'GATEWAY_INTERFACE' => 'FastCGI/1.0',
'REQUEST_METHOD' => 'GET',
'SCRIPT_FILENAME' => $uri,
'SCRIPT_FILENAME' => $scriptFilename ?: $uri,
'SCRIPT_NAME' => $uri,
'QUERY_STRING' => $query,
'REQUEST_URI' => $uri . ($query ? '?'.$query : ""),
Expand Down Expand Up @@ -580,6 +578,7 @@ class Tester
* @param string|null $successMessage
* @param string|null $errorMessage
* @param bool $connKeepAlive
* @param string|null $scriptFilename = null
* @return Response
*/
public function request(
Expand All @@ -589,13 +588,14 @@ class Tester
string $address = null,
string $successMessage = null,
string $errorMessage = null,
bool $connKeepAlive = false
bool $connKeepAlive = false,
string $scriptFilename = null
) {
if ($this->hasError()) {
return new Response(null, true);
}

$params = $this->getRequestParams($query, $headers, $uri);
$params = $this->getRequestParams($query, $headers, $uri, $scriptFilename);

try {
$this->response = new Response(
Expand Down

0 comments on commit 435a5ac

Please sign in to comment.