-
Notifications
You must be signed in to change notification settings - Fork 548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhancement: Run end-to-end tests asserting an HTTP response status code #900
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
tests/EndToEnd/paths-return-http-response-status-code-200-301-or-302.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--TEST-- | ||
paths return HTTP response status code 200, 301, or 302 | ||
--FILE-- | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
$httpHost = getenv('HTTP_HOST'); | ||
|
||
if (!is_string($httpHost)) { | ||
throw new \RuntimeException('Environment variable "HTTP_HOST" is not set.'); | ||
} | ||
|
||
$pathToRoot = realpath(__DIR__ . '/../..'); | ||
|
||
$pathsToFiles = [ | ||
...glob($pathToRoot . '/*.php'), | ||
...glob($pathToRoot . '/archive/*.php'), | ||
...glob($pathToRoot . '/conferences/*.php'), | ||
...glob($pathToRoot . '/license/*.php'), | ||
...glob($pathToRoot . '/manual/*.php'), | ||
...glob($pathToRoot . '/manual/en/*.php'), | ||
...glob($pathToRoot . '/releases/*.php'), | ||
...glob($pathToRoot . '/releases/*/*.php'), | ||
...glob($pathToRoot . '/releases/*/*/*.php'), | ||
]; | ||
|
||
$paths = str_replace($pathToRoot, '', $pathsToFiles); | ||
|
||
$baseUrl = sprintf( | ||
'http://%s', | ||
$httpHost, | ||
); | ||
|
||
$pathsToStatusCodes = array_combine( | ||
$paths, | ||
array_map(static function (string $url) use ($baseUrl): int { | ||
$handle = curl_init(); | ||
|
||
$options = [ | ||
CURLOPT_RETURNTRANSFER => true, | ||
CURLOPT_URL => sprintf( | ||
'%s%s', | ||
$baseUrl, | ||
$url, | ||
), | ||
]; | ||
|
||
curl_setopt_array($handle, $options); | ||
|
||
curl_exec($handle); | ||
|
||
return curl_getinfo($handle, CURLINFO_HTTP_CODE); | ||
}, $paths), | ||
); | ||
|
||
$pathsWithUnexpectedStatusCodes = array_filter($pathsToStatusCodes, static function (int $statusCode): bool { | ||
return !in_array($statusCode, [200, 301, 302], true); | ||
}); | ||
|
||
var_dump($pathsWithUnexpectedStatusCodes); | ||
?> | ||
--EXPECT-- | ||
array(0) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[PHP] | ||
|
||
display_errors = Off | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
#!/bin/bash | ||
|
||
# https://github.com/cubny/php-built-in-server-manager/blob/9a5cbeaad50a108d6058b882b83ba23fbd7722a9/server | ||
|
||
# default hostname | ||
HOST=localhost | ||
# default port number | ||
PORT=8080 | ||
# script name | ||
NAME=${0##*/} | ||
|
||
usage () { | ||
cat <<EOF | ||
|
||
$NAME (PHP built-in web server manager) Version 0.2.0 | ||
PHP builtin server manager on port $PORT | ||
|
||
usage: ./$NAME <command> [<hostname>:<port>] | ||
|
||
Available commands: | ||
|
||
start Starts PHP built-in web server server on specified hostname:port, default is localhost:$PORT | ||
stop Stops the PHP built-in web server | ||
restart Stops and Starts on previously specified hostname:port | ||
status Status of "$NAME" process | ||
log Show the PHP built-in web server logs. Use the -f option for a live update | ||
|
||
|
||
report bugs to [email protected] | ||
$NAME homepage: <https://github.com/cubny/php-built-in-server-manager> | ||
|
||
EOF | ||
return 0 | ||
} | ||
|
||
setup_colors() { | ||
|
||
if which tput >/dev/null 2>&1; then | ||
ncolors=$(tput colors) | ||
fi | ||
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then | ||
RED="$(tput setaf 1)" | ||
GREEN="$(tput setaf 2)" | ||
YELLOW="$(tput setaf 3)" | ||
BLUE="$(tput setaf 4)" | ||
BOLD="$(tput bold)" | ||
NORMAL="$(tput sgr0)" | ||
else | ||
RED="" | ||
GREEN="" | ||
YELLOW="" | ||
BLUE="" | ||
BOLD="" | ||
NORMAL="" | ||
fi | ||
} | ||
|
||
# if no command specified exit and show usage | ||
if [[ $# < 1 ]]; then | ||
echo $NAME: no command specified | ||
usage | ||
exit 1 | ||
fi | ||
|
||
# if hostname:port specified override defaults | ||
if [[ $# > 1 ]]; then | ||
IFS=':' read -r -a hostport <<< "$2" | ||
if [[ ! -z "${hostport[0]}" ]]; then | ||
HOST=${hostport[0]} | ||
fi | ||
if [[ ! -z "${hostport[1]}" ]]; then | ||
PORT=${hostport[1]} | ||
fi | ||
fi | ||
|
||
# pidfile contents would be hostname:port:pid | ||
PIDFILE=tests/server.pid | ||
LOGFILE=tests/server.log | ||
|
||
validate_server () { | ||
which php &> /dev/null | ||
if [[ $? -eq 1 ]]; then | ||
printf "${YELLOW}Error: PHP not found. ${NORMAL}Please install PHP version 5.4 or greater!\n" | ||
return 1 | ||
fi | ||
|
||
php -h | grep -q -- '-S' | ||
if [[ $? -eq 1 ]]; then | ||
printf "${YELLOW}Error: PHP version must be 5.4 or greater!${NORMAL}\n" | ||
return 1 | ||
fi | ||
|
||
return 0 | ||
} | ||
|
||
start_server () { | ||
validate_server | ||
|
||
if [[ $? -eq 1 ]]; then | ||
return 1 | ||
fi | ||
|
||
if [[ -e "$PIDFILE" ]]; then | ||
printf "${YELLOW}Server seems to be running!${NORMAL}\n" | ||
echo | ||
echo if not, there is probably a zombie "$PIDFILE" in this directory. | ||
echo if you are sure no server is running just remove "$PIDFILE" manually and start again | ||
return 1 | ||
else | ||
printf "${GREEN}"$NAME" started on $HOST:$PORT${NORMAL}\n" | ||
php -S "$HOST":"$PORT" -c tests/php.ini >> "$LOGFILE" 2>&1 & | ||
echo "$HOST":"$PORT":$! > $PIDFILE | ||
return 0 | ||
fi | ||
} | ||
|
||
read_pidfile() { | ||
if [[ -e "$PIDFILE" ]]; then | ||
PIDFILECONTENT=`cat "$PIDFILE"` | ||
IFS=: read HOST PORT PID <<< "$PIDFILECONTENT:" | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
stop_server () { | ||
if read_pidfile; then | ||
kill -9 "$PID" | ||
rm -f "$PIDFILE" | ||
printf "${GREEN}"$NAME" stopped!${NORMAL}\n" | ||
return 0 | ||
else | ||
printf "${YELLOW}"$NAME" is not running!${NORMAL}\n" | ||
return 1 | ||
fi | ||
} | ||
|
||
status_server() { | ||
if read_pidfile && kill -0 "$PID" ; then | ||
printf "${BLUE}"$NAME" is running on ${HOST}:${PORT}${NORMAL}\n" | ||
else | ||
printf "${YELLOW}"$NAME" is not running!${NORMAL}\n" | ||
fi | ||
} | ||
|
||
|
||
log_server() { | ||
if read_pidfile && kill -0 "$PID" ; then | ||
if [[ "$1" = "-f" ]]; then | ||
TAIL_OPTS="-f" | ||
fi | ||
tail $TAIL_OPTS "$LOGFILE" | ||
else | ||
printf "${YELLOW}"$NAME" is not running!${NORMAL}\n" | ||
fi | ||
} | ||
|
||
|
||
setup_colors | ||
|
||
case $1 in | ||
start) start_server;; | ||
stop) stop_server;; | ||
restart) stop_server; start_server ;; | ||
status) status_server;; | ||
log) log_server $2;; | ||
-h) usage ;; | ||
--help) usage ;; | ||
*) usage;; | ||
esac |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pronskiy
According to https://stackoverflow.com/a/28974224/1172545, this should help!