Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Dependabot configuration.
#
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
open-pull-requests-limit: 5
commit-message:
prefix: "GH Actions:"
Comment thread
jrfnl marked this conversation as resolved.
labels:
- "testing/chores/QA"
67 changes: 67 additions & 0 deletions .github/workflows/cs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: CS

on:
# Run on all pushes and on all pull requests.
push:
pull_request:
# Allow manually triggering the workflow.
workflow_dispatch:

# Cancels all previous workflow runs for the same branch that have not yet completed.
concurrency:
# The concurrency group contains the workflow name and the branch name.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
actionlint: #----------------------------------------------------------------------
name: 'Check GHA workflows'
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Add problem matcher
if: ${{ github.event_name == 'pull_request' }}
shell: bash
run: |
curl -o actionlint-matcher.json https://raw.githubusercontent.com/rhysd/actionlint/main/.github/actionlint-matcher.json
echo "::add-matcher::actionlint-matcher.json"

- name: Check workflow files
uses: docker://rhysd/actionlint:latest
with:
args: -color

phpcs: #----------------------------------------------------------------------
name: 'PHPCS'
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: 'latest'
coverage: none
tools: cs2pr

# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
- name: Install Composer dependencies
uses: "ramsey/composer-install@v3"
with:
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")

# Check the code-style consistency of the PHP files.
- name: Check PHP code style
id: phpcs
run: composer checkcs -- --report-full --report-checkstyle=./phpcs-report.xml

- name: Show PHPCS results in PR
if: ${{ always() && steps.phpcs.outcome == 'failure' }}
Comment thread
jrfnl marked this conversation as resolved.
run: cs2pr ./phpcs-report.xml
50 changes: 50 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Lint

on:
# Run on all pushes and on all pull requests.
push:
pull_request:
# Allow manually triggering the workflow.
workflow_dispatch:

# Cancels all previous workflow runs for the same branch that have not yet completed.
concurrency:
# The concurrency group contains the workflow name and the branch name.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint: #----------------------------------------------------------------------
runs-on: ubuntu-latest

strategy:
matrix:
php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']

name: "Lint: PHP ${{ matrix.php }}"
continue-on-error: ${{ matrix.php == '8.5' }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
ini-values: error_reporting=-1, display_errors=On, log_errors_max_len=0
coverage: none
tools: cs2pr

# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
- name: Install Composer dependencies
uses: "ramsey/composer-install@v3"
with:
# For PHP "nightly", we need to install with ignore platform reqs.
composer-options: ${{ matrix.php == '8.5' && '--ignore-platform-req=php+' || '' }}
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")

- name: Lint against parse errors
run: composer lint -- --checkstyle | cs2pr
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Ignore temporary files.
/bin/http.log
/bin/http.pid

# Ignore composer related files
/composer.lock
/vendor

# Ignore local overrides of the PHPCS config file.
.phpcs.xml
phpcs.xml
72 changes: 72 additions & 0 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="Requests Test Server"
xsi:noNamespaceSchemaLocation="./vendor/squizlabs/php_codesniffer/phpcs.xsd">

<description>Requests Test Server rules for PHP_CodeSniffer</description>

<!--
#############################################################################
COMMAND LINE ARGUMENTS
https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
#############################################################################
-->

<!-- Scan all files. -->
<file>.</file>

<!-- Third party files and build files don't need to comply with these coding standards. -->
<exclude-pattern>*/vendor/*</exclude-pattern>

<!-- Only check PHP files. -->
<arg name="extensions" value="php"/>

<!-- Show progress, show the error codes for each message (source). -->
<arg value="ps"/>

<!-- Strip the filepaths down to the relevant bit. -->
<arg name="basepath" value="./"/>

<!-- Check up to 8 files simultaneously. -->
<arg name="parallel" value="8"/>

<!-- Default tab width for indentation fixes and such. -->
<arg name="tab-width" value="4"/>

<!--
#############################################################################
CHECK FOR PHP CROSS-VERSION COMPATIBILITY
#############################################################################
-->

<config name="testVersion" value="5.6-"/>
<rule ref="PHPCompatibility"/>


<!--
#############################################################################
CODING STYLE RULES
#############################################################################
-->

<!-- Use PSR-12 as a basis, but with tweaks. -->
<rule ref="PSR12">
<exclude name="Generic.WhiteSpace.DisallowTabIndent"/>
</rule>

<!-- ==========================================================================
Enforce tab indentation.
========================================================================== -->
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>

<!-- ==========================================================================
Disallow Yoda conditions.
========================================================================== -->
<rule ref="Generic.ControlStructures.DisallowYodaConditions"/>

<!-- ==========================================================================
Enforce short arrays.
========================================================================== -->
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>

</ruleset>
2 changes: 0 additions & 2 deletions bin/.gitignore

This file was deleted.

36 changes: 18 additions & 18 deletions bin/serve.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?php

if ( ! function_exists( 'Requests\\TestServer\\get_routes' ) ) {
require dirname( __DIR__ ) . '/lib/utils.php';
require dirname( __DIR__ ) . '/lib/routes.php';
if (! function_exists('Requests\\TestServer\\get_routes')) {
require dirname(__DIR__) . '/lib/utils.php';
require dirname(__DIR__) . '/lib/routes.php';
}

ini_set('html_errors', false);
header('Content-Type: application/json; charset=utf-8');

$is_secure = false;
if (isset($_SERVER['HTTPS']) && ! empty($_SERVER['HTTPS']) ) {
if (isset($_SERVER['HTTPS']) && ! empty($_SERVER['HTTPS'])) {
$is_secure = true;
}
elseif ((!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
|| (!empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
} elseif (
(!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https')
|| (!empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] === 'on')
) {
$is_secure = true;
}
Expand All @@ -24,12 +24,10 @@
$headers = null;
if (function_exists('apache_request_headers')) {
$headers = apache_request_headers();
}
elseif (function_exists('getallheaders')) {
} elseif (function_exists('getallheaders')) {
$headers = getallheaders();
}
else {
$headers = array();
} else {
$headers = [];
foreach ($_SERVER as $name => $value) {
if ($name === 'CONTENT_TYPE') {
if ($value !== '') {
Expand Down Expand Up @@ -66,7 +64,9 @@
'url' => $scheme . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
'headers' => $headers,
'origin' => $_SERVER['REMOTE_ADDR'],
'args' => empty($_SERVER['QUERY_STRING']) ? new stdClass : Requests\TestServer\parse_params_rfc( $_SERVER['QUERY_STRING'] ),
'args' => empty($_SERVER['QUERY_STRING'])
? new stdClass()
: Requests\TestServer\parse_params_rfc($_SERVER['QUERY_STRING']),
];

$routes = Requests\TestServer\get_routes();
Expand All @@ -81,8 +81,9 @@
foreach ($routes as $route => $callback) {
$route = preg_replace('#<(\w+)>#i', '(?P<\1>\w+)', $route);
$match = preg_match('#^' . $route . '$#i', $here, $matches);
if (empty($match))
if (empty($match)) {
continue;
}

$data = $callback;
break;
Expand All @@ -95,10 +96,9 @@
while (is_callable($data)) {
$data = call_user_func($data, $matches);
}
}
catch (Exception $e) {
} catch (Exception $e) {
http_response_code($e->getCode());
$data = [ 'message' => $e->getMessage() ];
$data = ['message' => $e->getMessage()];
}

echo json_encode($data, JSON_PRETTY_PRINT);
echo json_encode($data, JSON_PRETTY_PRINT);
55 changes: 51 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,65 @@
{
"name": "requests/test-server",
"description": "Test server to respond to Requests' tests!",
"homepage": "http://github.com/RequestsPHP/test-server",
"license": "ISC",
"keywords": ["http", "test"],
"type": "library",
"keywords": [
"http",
"test"
],
"authors": [
{
"name": "Ryan McCue",
"homepage": "http://ryanmccue.info"
},
{
"name": "Alain Schlesser",
"homepage": "https://github.com/schlessera"
},
{
"name": "Juliette Reinders Folmer",
"homepage": "https://github.com/jrfnl"
},
{
"name": "Contributors",
"homepage": "https://github.com/RequestsPHP/test-server/graphs/contributors"
}
],
"homepage": "http://github.com/RequestsPHP/test-server",
"require": {
"php": ">=5.6"
},
"type": "library",
"bin": [ "bin/start.sh", "bin/stop.sh", "bin/serve.php" ]
"require-dev": {
"php-parallel-lint/php-console-highlighter": "^1.0",
"php-parallel-lint/php-parallel-lint": "^1.4",
"phpcompatibility/php-compatibility": "dev-develop",
"squizlabs/php_codesniffer": "^3.11"
},
"bin": [
"bin/serve.php",
"bin/start.sh",
"bin/stop.sh"
],
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
},
"lock": false
},
"scripts": {
"checkcs": [
"@php ./vendor/squizlabs/php_codesniffer/bin/phpcs"
],
"fixcs": [
"@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf"
],
"lint": [
"@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . --show-deprecated -e php --exclude vendor --exclude .git"
]
},
"scripts-descriptions": {
"checkcs": "Check the entire codebase for code-style issues.",
"fixcs": "Fix all auto-fixable code-style issues in the entire codebase.",
"lint": "Lint PHP files to find parse errors."
}
}
Loading