Skip to content

Commit

Permalink
Enhancement: Run end-to-end tests asserting an HTTP response status code
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Dec 14, 2023
1 parent b95f3e7 commit 0ba2609
Show file tree
Hide file tree
Showing 621 changed files with 11,921 additions and 6 deletions.
26 changes: 24 additions & 2 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
extensions: "none, json, mbstring, tokenizer"
extensions: "none, curl, json, mbstring, tokenizer"
php-version: "${{ matrix.php-version }}"

- name: "Set up problem matchers for PHP"
Expand Down Expand Up @@ -64,6 +64,9 @@ jobs:
php-version:
- "8.2"

env:
HTTP_HOST: "localhost:8080"

steps:
- name: "Checkout"
uses: "actions/checkout@v4"
Expand All @@ -72,11 +75,30 @@ jobs:
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
extensions: "none"
extensions: "none, curl, mbstring, tokenizer"
php-version: "${{ matrix.php-version }}"

- name: "Set up problem matchers for PHP"
run: "echo \"::add-matcher::${{ runner.tool_cache }}/php.json\""

- name: "Validate composer.json and composer.lock"
run: "composer validate --ansi --strict"

- name: "Determine composer cache directory"
run: "echo \"COMPOSER_CACHE_DIR=$(composer config cache-dir)\" >> $GITHUB_ENV"

- name: "Cache dependencies installed with composer"
uses: "actions/cache@v3"
with:
path: "${{ env.COMPOSER_CACHE_DIR }}"
key: "php-${{ matrix.php-version }}-composer-${{ hashFiles('composer.lock') }}"
restore-keys: "php-${{ matrix.php-version }}-composer-"

- name: "Install dependencies with composer"
run: "composer install --ansi --no-interaction --no-progress"

- name: "Start built-in web server for PHP"
run: "php -S ${{ env.HTTP_HOST }} .router.php &"

- name: "Run tests"
run: "php tests/run-tests.php -j3 -q --show-diff"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ vendor/
.idea
.DS_Store
.DS_Store?
tests/server.log
tests/server.pid
.php-cs-fixer.cache
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.EXPORT_ALL_VARIABLES:

HTTP_HOST:=localhost:8080

.PHONY: help
help: ## Displays this list of targets with descriptions
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}'
Expand All @@ -7,8 +11,8 @@ coding-standards: vendor ## Fixes code style issues with friendsofphp/php-cs-fix
vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --diff --verbose

.PHONY: tests
tests: ## Runs tests
php tests/run-tests.php -j3 -q
tests: vendor ## Runs tests
tests/server start; php tests/run-tests.php -j3 -q; tests/server stop

vendor: composer.json composer.lock
composer validate --strict
Expand Down
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@
"php": "~8.2.0"
},
"require-dev": {
"ext-curl": "*",
"friendsofphp/php-cs-fixer": "^3.40.2"
},
"autoload": {
"psr-4": {
"phpweb\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"phpweb\\Test\\": "tests/"
}
},
"config": {
"platform": {
"php": "8.2.0"
Expand Down
6 changes: 4 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
/ChangeLog-4.php returns HTTP response status code 200
--FILE--
<?php

declare(strict_types=1);

require_once __DIR__ . '/../../vendor/autoload.php';

use phpweb\Test\Util\Http\CurlClient;

$httpClient = CurlClient::fromEnvironment(getenv());

$response = $httpClient->get('/ChangeLog-4.php');

var_dump($response->statusCode);
?>
--EXPECT--
int(200)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
/ChangeLog-5.php returns HTTP response status code 200
--FILE--
<?php

declare(strict_types=1);

require_once __DIR__ . '/../../vendor/autoload.php';

use phpweb\Test\Util\Http\CurlClient;

$httpClient = CurlClient::fromEnvironment(getenv());

$response = $httpClient->get('/ChangeLog-5.php');

var_dump($response->statusCode);
?>
--EXPECT--
int(200)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
/ChangeLog-7.php returns HTTP response status code 200
--FILE--
<?php

declare(strict_types=1);

require_once __DIR__ . '/../../vendor/autoload.php';

use phpweb\Test\Util\Http\CurlClient;

$httpClient = CurlClient::fromEnvironment(getenv());

$response = $httpClient->get('/ChangeLog-7.php');

var_dump($response->statusCode);
?>
--EXPECT--
int(200)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
/ChangeLog-8.php returns HTTP response status code 200
--FILE--
<?php

declare(strict_types=1);

require_once __DIR__ . '/../../vendor/autoload.php';

use phpweb\Test\Util\Http\CurlClient;

$httpClient = CurlClient::fromEnvironment(getenv());

$response = $httpClient->get('/ChangeLog-8.php');

var_dump($response->statusCode);
?>
--EXPECT--
int(200)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
/archive/1998.php returns HTTP response status code 200
--FILE--
<?php

declare(strict_types=1);

require_once __DIR__ . '/../../../vendor/autoload.php';

use phpweb\Test\Util\Http\CurlClient;

$httpClient = CurlClient::fromEnvironment(getenv());

$response = $httpClient->get('/archive/1998.php');

var_dump($response->statusCode);
?>
--EXPECT--
int(200)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
/archive/1999.php returns HTTP response status code 200
--FILE--
<?php

declare(strict_types=1);

require_once __DIR__ . '/../../../vendor/autoload.php';

use phpweb\Test\Util\Http\CurlClient;

$httpClient = CurlClient::fromEnvironment(getenv());

$response = $httpClient->get('/archive/1999.php');

var_dump($response->statusCode);
?>
--EXPECT--
int(200)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
/archive/2000.php returns HTTP response status code 200
--FILE--
<?php

declare(strict_types=1);

require_once __DIR__ . '/../../../vendor/autoload.php';

use phpweb\Test\Util\Http\CurlClient;

$httpClient = CurlClient::fromEnvironment(getenv());

$response = $httpClient->get('/archive/2000.php');

var_dump($response->statusCode);
?>
--EXPECT--
int(200)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
/archive/2001.php returns HTTP response status code 200
--FILE--
<?php

declare(strict_types=1);

require_once __DIR__ . '/../../../vendor/autoload.php';

use phpweb\Test\Util\Http\CurlClient;

$httpClient = CurlClient::fromEnvironment(getenv());

$response = $httpClient->get('/archive/2001.php');

var_dump($response->statusCode);
?>
--EXPECT--
int(200)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
/archive/2002.php returns HTTP response status code 200
--FILE--
<?php

declare(strict_types=1);

require_once __DIR__ . '/../../../vendor/autoload.php';

use phpweb\Test\Util\Http\CurlClient;

$httpClient = CurlClient::fromEnvironment(getenv());

$response = $httpClient->get('/archive/2002.php');

var_dump($response->statusCode);
?>
--EXPECT--
int(200)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
/archive/2003.php returns HTTP response status code 200
--FILE--
<?php

declare(strict_types=1);

require_once __DIR__ . '/../../../vendor/autoload.php';

use phpweb\Test\Util\Http\CurlClient;

$httpClient = CurlClient::fromEnvironment(getenv());

$response = $httpClient->get('/archive/2003.php');

var_dump($response->statusCode);
?>
--EXPECT--
int(200)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
/archive/2004.php returns HTTP response status code 200
--FILE--
<?php

declare(strict_types=1);

require_once __DIR__ . '/../../../vendor/autoload.php';

use phpweb\Test\Util\Http\CurlClient;

$httpClient = CurlClient::fromEnvironment(getenv());

$response = $httpClient->get('/archive/2004.php');

var_dump($response->statusCode);
?>
--EXPECT--
int(200)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
/archive/2005.php returns HTTP response status code 200
--FILE--
<?php

declare(strict_types=1);

require_once __DIR__ . '/../../../vendor/autoload.php';

use phpweb\Test\Util\Http\CurlClient;

$httpClient = CurlClient::fromEnvironment(getenv());

$response = $httpClient->get('/archive/2005.php');

var_dump($response->statusCode);
?>
--EXPECT--
int(200)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
/archive/2006.php returns HTTP response status code 200
--FILE--
<?php

declare(strict_types=1);

require_once __DIR__ . '/../../../vendor/autoload.php';

use phpweb\Test\Util\Http\CurlClient;

$httpClient = CurlClient::fromEnvironment(getenv());

$response = $httpClient->get('/archive/2006.php');

var_dump($response->statusCode);
?>
--EXPECT--
int(200)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
/archive/2007.php returns HTTP response status code 200
--FILE--
<?php

declare(strict_types=1);

require_once __DIR__ . '/../../../vendor/autoload.php';

use phpweb\Test\Util\Http\CurlClient;

$httpClient = CurlClient::fromEnvironment(getenv());

$response = $httpClient->get('/archive/2007.php');

var_dump($response->statusCode);
?>
--EXPECT--
int(200)
Loading

0 comments on commit 0ba2609

Please sign in to comment.