Skip to content
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

Improve test suite with improved directory structure for integration tests #250

Merged
merged 3 commits into from
Mar 5, 2024
Merged
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
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
/.github/workflows/ export-ignore
/.gitignore export-ignore
/docs/ export-ignore
/examples/ export-ignore
/mkdocs.yml export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml.dist export-ignore
Expand Down
38 changes: 21 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ jobs:
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
- run: composer install -d tests/install-as-dep/
- run: php tests/install-as-dep/public/index.php &
- run: composer install -d tests/integration/
- run: php tests/integration/public/index.php &
- run: bash tests/await.sh
- run: bash tests/acceptance.sh
- run: bash tests/integration.bash

Docker:
name: Docker (${{ matrix.dockerfile }})
Expand All @@ -101,11 +101,11 @@ jobs:
- uses: shivammathur/setup-php@v2
with:
php-version: 8.3
- run: composer install -d tests/install-as-dep/
- run: docker build -f tests/${{ matrix.dockerfile }} tests/install-as-dep/
- run: docker run -d -p 8080:8080 -v "$PWD/examples/index.php":/app/public/index.php -v "$PWD/composer.json":/app/composer.json -v "$PWD/LICENSE":/app/LICENSE -v "$PWD/tests/":/app/tests/ $(docker images -q | head -n1)
- run: composer install -d tests/integration/
- run: docker build -f tests/integration/${{ matrix.dockerfile }} tests/integration/
- run: docker run -d -p 8080:8080 -v "$PWD/composer.json":/app/composer.json $(docker images -q | head -n1)
- run: bash tests/await.sh
- run: bash tests/acceptance.sh
- run: bash tests/integration.bash
- run: docker stop $(docker ps -qn1)
- run: docker logs $(docker ps -qn1)
if: ${{ always() }}
Expand All @@ -129,11 +129,13 @@ jobs:
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
- run: composer install -d tests/install-as-dep/
- run: docker run -d -v "$PWD/tests/install-as-dep/":/home/framework-x/ -v "$PWD/examples/index.php":/home/framework-x/public/index.php -v "$PWD/LICENSE":/home/framework-x/LICENSE -v "$PWD/tests/":/home/framework-x/tests/ php:${{ matrix.php }}-fpm
- run: docker run -d -p 80:80 --link $(docker ps -qn1):php -v "$PWD/tests/install-as-dep/":/home/framework-x/ -v "$PWD"/examples/nginx/nginx.conf:/etc/nginx/conf.d/default.conf nginx:stable-alpine
- run: composer install -d tests/integration/
- run: docker run -d -v "$PWD/tests/integration/":/home/framework-x/ php:${{ matrix.php }}-fpm
- run: docker run -d -p 80:80 --link $(docker ps -qn1):php -v "$PWD/tests/integration/":/home/framework-x/ -v "$PWD"/tests/integration/nginx-fpm.conf:/etc/nginx/conf.d/default.conf nginx:stable-alpine
- run: bash tests/await.sh http://localhost
- run: bash tests/acceptance.sh http://localhost
- run: bash tests/integration.bash http://localhost
- run: docker logs $(docker ps -qn1)
if: ${{ always() }}

Apache-webserver:
name: Apache webserver (PHP ${{ matrix.php }})
Expand All @@ -154,10 +156,12 @@ jobs:
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
- run: composer install -d tests/install-as-dep/
- run: docker run -d -p 80:80 -v "$PWD/tests/install-as-dep/":/home/framework-x/ -v "$PWD/examples/index.php":/home/framework-x/public/index.php -v "$PWD/LICENSE":/home/framework-x/LICENSE -v "$PWD/tests/":/home/framework-x/tests/ -v "$PWD/examples/apache/.htaccess":/home/framework-x/public/.htaccess php:${{ matrix.php }}-apache sh -c "rmdir /var/www/html;ln -s /home/framework-x/public /var/www/html;ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled; apache2-foreground"
- run: composer install -d tests/integration/
- run: docker run -d -p 80:80 -v "$PWD/tests/integration/":/home/framework-x/ php:${{ matrix.php }}-apache sh -c "rmdir /var/www/html;ln -s /home/framework-x/public /var/www/html;ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled; apache2-foreground"
- run: bash tests/await.sh http://localhost
- run: bash tests/acceptance.sh http://localhost
- run: bash tests/integration.bash http://localhost
- run: docker logs $(docker ps -qn1)
if: ${{ always() }}

PHP-webserver:
name: PHP webserver (PHP ${{ matrix.php }})
Expand All @@ -178,7 +182,7 @@ jobs:
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
- run: composer install -d tests/install-as-dep/
- run: php -S localhost:8080 tests/install-as-dep/public/index.php &
- run: composer install -d tests/integration/
- run: php -S localhost:8080 tests/integration/public/index.php &
- run: bash tests/await.sh
- run: bash tests/acceptance.sh
- run: bash tests/integration.bash
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ generate a code coverage report locally like this:
$ XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-text
```

Additionally, you can run some simple acceptance tests to verify the framework
examples work as expected behind your web server. Use your web server of choice
(see deployment documentation) and execute the tests with the URL to your
installation like this:
Additionally, you can run our sophisticated integration tests to verify the
framework examples work as expected behind your web server. Use your web server
of choice (see deployment documentation) and execute the tests with the URL to
your installation like this:

```bash
$ php examples/index.php
$ tests/acceptance.sh http://localhost:8080
$ php tests/integration/public/index.php
$ tests/integration.bash http://localhost:8080
```

## License
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ parameters:
level: max

paths:
- examples/
- src/
- tests/

Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<testsuites>
<testsuite name="Framework X test suite">
<directory>./tests/</directory>
<exclude>./tests/install-as-dep/</exclude>
<exclude>./tests/integration/</exclude>
</testsuite>
</testsuites>
<coverage>
Expand Down
5 changes: 0 additions & 5 deletions tests/install-as-dep/public/index.php

This file was deleted.

17 changes: 10 additions & 7 deletions tests/acceptance.sh → tests/integration.bash
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ notmatch() {
skipif() {
echo "$out" | grep "$@" >/dev/null && echo -n S && return 1 || return 0
}
skipifnot() {
echo "$out" | grep "$@" >/dev/null && return 0 || echo -n S && return 1
}

out=$(curl -v $base/ 2>&1); match "HTTP/.* 200" && match -iP "Content-Type: text/plain; charset=utf-8[\r\n]"
out=$(curl -v $base/invalid 2>&1); match "HTTP/.* 404" && match -iP "Content-Type: text/html; charset=utf-8[\r\n]"
Expand Down Expand Up @@ -81,15 +84,15 @@ out=$(curl -v $base/users 2>&1); match "HTTP/.* 404"
out=$(curl -v $base/users/ 2>&1); match "HTTP/.* 404"
out=$(curl -v $base/users/a/b 2>&1); match "HTTP/.* 404"

out=$(curl -v $base/LICENSE 2>&1); match "HTTP/.* 200" && match -iP "Content-Type: text/plain[\r\n]"
out=$(curl -v $base/robots.txt 2>&1); match "HTTP/.* 200" && match -iP "Content-Type: text/plain[\r\n]"
out=$(curl -v $base/source 2>&1); match -i "Location: /source/" && match -iP "Content-Type: text/html; charset=utf-8[\r\n]"
out=$(curl -v $base/source/ 2>&1); match "HTTP/.* 200"
out=$(curl -v $base/source/composer.json 2>&1); match "HTTP/.* 200" && match -iP "Content-Type: application/json[\r\n]"
out=$(curl -v $base/source/LICENSE 2>&1); match "HTTP/.* 200" && match -iP "Content-Type: text/plain[\r\n]"
out=$(curl -v $base/source/LICENSE/ 2>&1); match -i "Location: ../LICENSE" && match -iP "Content-Type: text/html; charset=utf-8[\r\n]"
out=$(curl -v $base/source/LICENSE// 2>&1); match "HTTP/.* 404"
out=$(curl -v $base/source//LICENSE 2>&1); match "HTTP/.* 404"
out=$(curl -v $base/source/tests 2>&1); match -i "Location: tests/" && match -iP "Content-Type: text/html; charset=utf-8[\r\n]"
out=$(curl -v $base/source/public/robots.txt 2>&1); match "HTTP/.* 200" && match -iP "Content-Type: text/plain[\r\n]"
out=$(curl -v $base/source/public/robots.txt/ 2>&1); match -i "Location: ../robots.txt" && match -iP "Content-Type: text/html; charset=utf-8[\r\n]"
out=$(curl -v $base/source/public/robots.txt// 2>&1); match "HTTP/.* 404"
out=$(curl -v $base/source//public/robots.txt 2>&1); match "HTTP/.* 404"
out=$(curl -v $base/source/public 2>&1); match -i "Location: public/" && match -iP "Content-Type: text/html; charset=utf-8[\r\n]"
out=$(curl -v $base/source/invalid 2>&1); match "HTTP/.* 404"
out=$(curl -v $base/source/bin%00ary 2>&1); match "HTTP/.* 40[40]" # expects 404, but not processed with nginx (400) and Apache (404)

Expand Down Expand Up @@ -121,7 +124,7 @@ out=$(curl -v $base/headers -H 'Content-Length: 0' 2>&1); match "HTTP/.* 200"
out=$(curl -v $base/headers -H 'Empty;' 2>&1); match "HTTP/.* 200" && match "\"Empty\": \"\""
out=$(curl -v $base/headers -H 'Content-Type;' 2>&1); skipif "Server: Apache" && match "HTTP/.* 200" && match "\"Content-Type\": \"\"" # skip Apache (discards empty Content-Type)
out=$(curl -v $base/headers -H 'DNT: 1' 2>&1); skipif "Server: nginx" && match "HTTP/.* 200" && match "\"DNT\"" && notmatch "\"Dnt\"" # skip nginx which doesn't report original case (DNT->Dnt)
out=$(curl -v $base/headers -H 'V: a' -H 'V: b' 2>&1); skipif "Server: nginx" && skipif -v "Server:" && match "HTTP/.* 200" && match "\"V\": \"a, b\"" # skip nginx (last only) and PHP webserver (first only)
out=$(curl -v $base/headers -H 'V: a' -H 'V: b' 2>&1); skipif "Server: nginx" && skipifnot "Server:" && match "HTTP/.* 200" && match "\"V\": \"a, b\"" # skip nginx (last only) and PHP webserver (first only)

out=$(curl -v $base/set-cookie 2>&1); match "HTTP/.* 200" && match "Set-Cookie: 1=1" && match "Set-Cookie: 2=2"

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 5 additions & 4 deletions examples/index.php → tests/integration/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
use React\Stream\ThroughStream;

// example uses `@include` for test suite only, real-world examples should use `require` instead
// require __DIR__ . '/../vendor/autoload.php';
@include __DIR__ . '/../vendor/autoload.php';
if(!@include __DIR__ . '/../vendor/autoload.php') {
require __DIR__ . '/../../../vendor/autoload.php';
}

$app = new FrameworkX\App();

Expand Down Expand Up @@ -104,8 +105,8 @@
);
});

$app->get('/LICENSE', new FrameworkX\FilesystemHandler(dirname(__DIR__) . '/LICENSE'));
$app->get('/source/{path:.*}', new FrameworkX\FilesystemHandler(dirname(__DIR__)));
$app->get('/robots.txt', new FrameworkX\FilesystemHandler(__DIR__ . '/robots.txt'));
$app->get('/source/{path:.*}', new FrameworkX\FilesystemHandler(__DIR__ . '/../'));
$app->redirect('/source', '/source/');

$app->any('/method', function (ServerRequestInterface $request) {
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
User-agent: *
Disallow: /