Skip to content

Commit 3dbf4b8

Browse files
authored
Merge pull request php-pm#528 from acasademont/gh_actions
Add github actions, remove travis
2 parents b721318 + 27b3501 commit 3dbf4b8

File tree

7 files changed

+134
-95
lines changed

7 files changed

+134
-95
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: "CS & PHPStan & Phpunit & Integration Tests"
2+
3+
on:
4+
pull_request:
5+
push:
6+
7+
jobs:
8+
cs-phpstan-phpunit-integration:
9+
name: "CS & PHPStan & Phpunit & Integration Tests"
10+
runs-on: "ubuntu-18.04"
11+
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
php-version:
16+
- "7.4"
17+
deps:
18+
- "normal"
19+
include:
20+
- deps: "low"
21+
php-version: "7.1"
22+
23+
steps:
24+
- name: "Checkout"
25+
uses: "actions/checkout@v2"
26+
with:
27+
fetch-depth: 0
28+
29+
- name: "Install PHP"
30+
uses: "shivammathur/setup-php@v2"
31+
with:
32+
php-version: "${{ matrix.php-version }}"
33+
extensions: "pcntl"
34+
tools: "cs2pr"
35+
# this is needed in order to remove the pcntl_ restrictions on the php-cgi SAPI
36+
ini-values: "disable_functions="
37+
38+
- name: "Cache dependencies installed with composer"
39+
uses: "actions/cache@v2"
40+
with:
41+
path: "~/.composer/cache"
42+
key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}"
43+
restore-keys: "php-${{ matrix.php-version }}-composer-locked-"
44+
45+
- name: "Install dependencies with composer"
46+
run: "composer update --no-interaction --no-progress --no-suggest --prefer-dist"
47+
if: "${{ matrix.deps == 'normal' }}"
48+
49+
- name: "Install lowest possible dependencies with composer"
50+
run: "composer update --no-interaction --no-progress --no-suggest --prefer-dist --prefer-lowest"
51+
if: "${{ matrix.deps == 'low' }}"
52+
53+
- name: "Run git-phpcs (for pull request)"
54+
if: "${{ github.event_name == 'pull_request' }}"
55+
run: |
56+
CHANGED_PHP_FILES=$(git diff origin/$GITHUB_BASE_REF --name-only --diff-filter=ACMRTUXB | grep -E "\.php$")
57+
php vendor/bin/php-cs-fixer fix --config=.php_cs.php --dry-run --diff -v -- $CHANGED_PHP_FILES
58+
59+
- name: "Run git-phpcs (for push)"
60+
if: "${{ github.event_name != 'pull_request' }}"
61+
run: |
62+
CHANGED_PHP_FILES=$(git diff --name-only --diff-filter=ACMRTUXB HEAD~..HEAD | grep -E "\.php$")
63+
php vendor/bin/php-cs-fixer fix --config=.php_cs.php --dry-run --diff -v -- $CHANGED_PHP_FILES
64+
65+
- name: "Run a static analysis with phpstan/phpstan"
66+
run: "php vendor/bin/phpstan analyse --error-format=checkstyle | cs2pr"
67+
68+
- name: "Run PHPUnit"
69+
run: "vendor/bin/phpunit"
70+
71+
- name: "Run Integration test"
72+
run: "./integration_test.sh"

.travis.yml

Lines changed: 0 additions & 79 deletions
This file was deleted.

composer.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"license": "MIT",
55
"require": {
66
"php": "^7.1",
7+
"ext-pcntl": "*",
78
"symfony/console": "^3.4|^4|^5",
89
"symfony/error-handler": "^4.4|^5",
910
"symfony/process": "^3.4|^4|^5",
@@ -13,11 +14,17 @@
1314
"react/socket": "^1.0",
1415
"react/child-process": "^0.6",
1516
"psr/http-server-handler": "^1.0",
16-
"ringcentral/psr7": "^1.2"
17+
"ringcentral/psr7": "^1.2",
18+
"psr/http-message": "^1.0.1",
19+
"react/cache": "^0.4",
20+
"react/promise": "^2.0"
1721
},
1822
"require-dev": {
1923
"mockery/mockery": "^1.0",
20-
"phpunit/phpunit": "^7.0"
24+
"phpunit/phpunit": "^7.0",
25+
"friendsofphp/php-cs-fixer": "^2.16.7",
26+
"phpstan/phpstan": "^0.12.58",
27+
"drew/debug-statements-fixers": "^0.5.0"
2128
},
2229
"autoload": {
2330
"psr-4": {

integration_test.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
# exit when any command fails
3+
set -e
4+
5+
# Integration test
6+
mkdir web && echo "Hello" > web/index.html
7+
bin/ppm start --workers=1 --bridge=StaticBridge --static-directory=web --max-requests=1 -v &
8+
sleep 5
9+
bin/ppm status
10+
curl -v -f "http://127.0.0.1:8080"
11+
bin/ppm status
12+
curl -v -f "http://127.0.0.1:8080"
13+
bin/ppm status
14+
bin/ppm stop
15+
# Test memory limit
16+
bin/ppm start --workers=1 --bridge=PHPPM\\Tests\\TestBridge --static-directory=web --memory-limit=5 -v > /tmp/ppmout &
17+
sleep 5
18+
# Memory limit: Nothing should happen
19+
curl -f --silent "http://127.0.0.1:8080/test?memory=0" &
20+
sleep 5
21+
bash -c 'grep -q "because it reached memory limit of 5" /tmp/ppmout || exit 0'
22+
bin/ppm status
23+
sleep 5
24+
# Memory limit: Worker should restart
25+
curl -f --silent "http://127.0.0.1:8080/test?memory=10" &
26+
sleep 5
27+
bash -c 'grep -q "because it reached memory limit of 5" /tmp/ppmout && exit 0'
28+
bin/ppm status
29+
bin/ppm stop
30+
# Trigger 502 error by triggering an exit() in the worker
31+
bin/ppm start --workers=1 --bridge=PHPPM\\Tests\\TestBridge --static-directory=web --max-requests=1 --max-execution-time=15 -v > /tmp/ppmout &
32+
sleep 5
33+
bash -c 'if [[ $(curl --write-out %{http_code} --silent --output /dev/null "http://127.0.0.1:8080/test?exit_prematurely=1") == "502" ]]; then exit 0; else exit 1; fi'
34+
bin/ppm status
35+
# Trigger 503 error by tying up the worker and making a second request
36+
curl -f --silent "http://127.0.0.1:8080/test?sleep=10000" &
37+
bash -c 'if [[ $(curl --write-out %{http_code} --silent --output /dev/null "http://127.0.0.1:8080") == "503" ]]; then exit 0; else exit 1; fi'
38+
bin/ppm status
39+
# Trigger 504 error by making a sleep request and waiting until the timeout
40+
bash -c 'if [[ $(curl --write-out %{http_code} --silent --output /dev/null "http://127.0.0.1:8080/test?sleep=10000") == "504" ]]; then exit 0; else exit 1; fi'
41+
bin/ppm status
42+
# Trigger 502 error by making the bridge throw an exception
43+
bash -c 'if [[ $(curl --write-out %{http_code} --silent --output /dev/null "http://127.0.0.1:8080/test?exception=1") == "502" ]]; then exit 0; else exit 1; fi'
44+
bash -c 'grep -q "An exception was thrown by the bridge. Forcing restart of the worker. The exception was" /tmp/ppmout && exit 0'
45+
bash -c 'grep -q "This is a very bad exception" /tmp/ppmout && exit 0'
46+
bash -c 'grep -q "Shutdown function triggered" /tmp/ppmoutshutdownfunc && exit 0'
47+
bin/ppm status
48+
bin/ppm stop

phpstan.neon.dist

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ parameters:
33
paths:
44
- src/
55
ignoreErrors:
6-
# For version 2.x and 3.x of \Symfony\Component\Process\Process package
7-
- '#^Call to an undefined static method Symfony\\Component\\Process\\ProcessUtils::escapeArgument\(\)\.$#'
86
# Actually called on implementations of PromiseInterface
97
- '#^Call to an undefined method React\\Promise\\PromiseInterface::done\(\)\.$#'
108
# Actually returns an implementation of PromiseInterface

src/ProcessManager.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,6 @@ protected function newSlaveInstance($port)
12511251
PHP_BINARY
12521252
)
12531253
);
1254-
exit();
12551254
}
12561255
12571256
if (!pcntl_enabled()) {
@@ -1272,15 +1271,9 @@ protected function newSlaveInstance($port)
12721271
// we can not use -q since this disables basically all header support
12731272
// but since this is necessary at least in Symfony we can not use it.
12741273
// e.g. headers_sent() returns always true, although wrong.
1275-
// For version 2.x and 3.x of \Symfony\Component\Process\Process package
1276-
if (\method_exists('\Symfony\Component\Process\ProcessUtils', 'escapeArgument')) {
1277-
$commandline = 'exec ' . $this->phpCgiExecutable . ' -C ' . ProcessUtils::escapeArgument($file);
1278-
} else {
1279-
//For version 4.x of \Symfony\Component\Process\Process package
1280-
$commandline = ['exec', $this->phpCgiExecutable, '-C', $file];
1281-
$processInstance = new \Symfony\Component\Process\Process($commandline);
1282-
$commandline = $processInstance->getCommandLine();
1283-
}
1274+
$commandline = ['exec', $this->phpCgiExecutable, '-C', $file];
1275+
$processInstance = new \Symfony\Component\Process\Process($commandline);
1276+
$commandline = $processInstance->getCommandLine();
12841277

12851278
// use exec to omit wrapping shell
12861279
$process = new Process($commandline);

src/functions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ function console_log($expression, $_ = null)
3030
}
3131

3232
/**
33-
* Checks that PCNTL is actually enabled in this installation.
33+
* Checks that PCNTL extension is installed and loaded in this installation.
3434
*
3535
* @return bool
3636
*/
3737
function pcntl_installed()
3838
{
39-
return \function_exists('pcntl_signal');
39+
return \extension_loaded('pcntl');
4040
}
4141

4242
/**

0 commit comments

Comments
 (0)