From 3b4192b7775eda031b96ed38fc02f790480b4c41 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 12:14:31 +0000 Subject: [PATCH 01/26] Add code quality checks via GHA --- .github/workflows/code-quality.yml | 102 +++++++++++++++++++++++++++++ composer.json | 3 +- 2 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/code-quality.yml diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml new file mode 100644 index 000000000..2431651b0 --- /dev/null +++ b/.github/workflows/code-quality.yml @@ -0,0 +1,102 @@ +name: Code Quality Checks + +on: pull_request + +jobs: + + lint: #----------------------------------------------------------------------- + name: Lint PHP files + runs-on: ubuntu-latest + steps: + - name: Check out source code + uses: actions/checkout@v2 + + - name: Check existence of composer.json file + id: check_composer_file + uses: andstor/file-existence-action@v1 + with: + files: "composer.json" + + - name: Set up PHP envirnoment + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + tools: cs2pr + + - name: Get Composer cache Directory + if: steps.check_composer_file.outputs.files_exists == 'true' + id: composer-cache + run: | + echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Use Composer cache + if: steps.check_composer_file.outputs.files_exists == 'true' + uses: actions/cache@v1 + with: + path: ${{ steps['composer-cache'].outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + + - name: Install dependencies + if: steps.check_composer_file.outputs.files_exists == 'true' + run: COMPOSER_ROOT_VERSION=dev-master composer install --prefer-dist --no-progress --no-suggest + + - name: Check existence of vendor/bin/parallel-lint file + id: check_linter_file + uses: andstor/file-existence-action@v1 + with: + files: "vendor/bin/parallel-lint" + + - name: Run Linter + if: steps.check_linter_file.outputs.files_exists == 'true' + run: vendor/bin/parallel-lint -j 10 . --exclude vendor --checkstyle | cs2pr + + phpcs: #---------------------------------------------------------------------- + name: PHPCS + runs-on: ubuntu-latest + + steps: + - name: Check out source code + uses: actions/checkout@v2 + + - name: Check existence of composer.json & phpcs.xml.dist files + id: check_files + uses: andstor/file-existence-action@v1 + with: + files: "composer.json, .phpcs.xml.dist" + + - name: Set up PHP envirnoment + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + tools: cs2pr + + - name: Get Composer cache Directory + if: steps.check_files.outputs.files_exists == 'true' + id: composer-cache + run: | + echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Use Composer cache + if: steps.check_files.outputs.files_exists == 'true' + uses: actions/cache@v1 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + + - name: Install dependencies + if: steps.check_files.outputs.files_exists == 'true' + run: COMPOSER_ROOT_VERSION=dev-master composer install --prefer-dist --no-progress --no-suggest + + - name: Check existence of vendor/bin/phpcs file + id: check_phpcs_binary_file + uses: andstor/file-existence-action@v1 + with: + files: "vendor/bin/phpcs" + + - name: Run PHPCS + if: steps.check_phpcs_binary_file.outputs.files_exists == 'true' + run: vendor/bin/phpcs -q --report=checkstyle | cs2pr diff --git a/composer.json b/composer.json index 6d78734fe..5107e5a55 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,8 @@ "phpcompatibility/php-compatibility": "^9.0", "wp-coding-standards/wpcs": "^2.0", "dealerdirect/phpcodesniffer-composer-installer": "^0.7", - "yoast/phpunit-polyfills": "^0.2.0" + "yoast/phpunit-polyfills": "^0.2.0", + "php-parallel-lint/php-parallel-lint": "^1.2" }, "type": "library", "autoload": { From 71523d2603ec9acb487013eec48dc16fd6b0ae0b Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 12:18:59 +0000 Subject: [PATCH 02/26] Simplify CS workflow --- .github/workflows/code-quality.yml | 32 ------------------------------ 1 file changed, 32 deletions(-) diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index 2431651b0..8ded2a351 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -11,12 +11,6 @@ jobs: - name: Check out source code uses: actions/checkout@v2 - - name: Check existence of composer.json file - id: check_composer_file - uses: andstor/file-existence-action@v1 - with: - files: "composer.json" - - name: Set up PHP envirnoment uses: shivammathur/setup-php@v2 with: @@ -24,13 +18,11 @@ jobs: tools: cs2pr - name: Get Composer cache Directory - if: steps.check_composer_file.outputs.files_exists == 'true' id: composer-cache run: | echo "::set-output name=dir::$(composer config cache-files-dir)" - name: Use Composer cache - if: steps.check_composer_file.outputs.files_exists == 'true' uses: actions/cache@v1 with: path: ${{ steps['composer-cache'].outputs.dir }} @@ -39,17 +31,9 @@ jobs: ${{ runner.os }}-composer- - name: Install dependencies - if: steps.check_composer_file.outputs.files_exists == 'true' run: COMPOSER_ROOT_VERSION=dev-master composer install --prefer-dist --no-progress --no-suggest - - name: Check existence of vendor/bin/parallel-lint file - id: check_linter_file - uses: andstor/file-existence-action@v1 - with: - files: "vendor/bin/parallel-lint" - - name: Run Linter - if: steps.check_linter_file.outputs.files_exists == 'true' run: vendor/bin/parallel-lint -j 10 . --exclude vendor --checkstyle | cs2pr phpcs: #---------------------------------------------------------------------- @@ -60,12 +44,6 @@ jobs: - name: Check out source code uses: actions/checkout@v2 - - name: Check existence of composer.json & phpcs.xml.dist files - id: check_files - uses: andstor/file-existence-action@v1 - with: - files: "composer.json, .phpcs.xml.dist" - - name: Set up PHP envirnoment uses: shivammathur/setup-php@v2 with: @@ -73,13 +51,11 @@ jobs: tools: cs2pr - name: Get Composer cache Directory - if: steps.check_files.outputs.files_exists == 'true' id: composer-cache run: | echo "::set-output name=dir::$(composer config cache-files-dir)" - name: Use Composer cache - if: steps.check_files.outputs.files_exists == 'true' uses: actions/cache@v1 with: path: ${{ steps.composer-cache.outputs.dir }} @@ -88,15 +64,7 @@ jobs: ${{ runner.os }}-composer- - name: Install dependencies - if: steps.check_files.outputs.files_exists == 'true' run: COMPOSER_ROOT_VERSION=dev-master composer install --prefer-dist --no-progress --no-suggest - - name: Check existence of vendor/bin/phpcs file - id: check_phpcs_binary_file - uses: andstor/file-existence-action@v1 - with: - files: "vendor/bin/phpcs" - - name: Run PHPCS - if: steps.check_phpcs_binary_file.outputs.files_exists == 'true' run: vendor/bin/phpcs -q --report=checkstyle | cs2pr From 4318db1d390ae67065ac00c53633f2677784bc02 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 12:21:02 +0000 Subject: [PATCH 03/26] Add basic unit testing workflow --- .github/workflows/testing.yml | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/testing.yml diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml new file mode 100644 index 000000000..1a846e893 --- /dev/null +++ b/.github/workflows/testing.yml @@ -0,0 +1,46 @@ +name: Testing + +on: pull_request + +jobs: + + unit: + name: Unit test / PHP ${{ matrix.php }} + strategy: + fail-fast: false + matrix: + php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0'] + runs-on: ubuntu-latest + + steps: + - name: Check out source code + uses: actions/checkout@v2 + + - name: Set up PHP environment + uses: shivammathur/setup-php@v2 + with: + php-version: '${{ matrix.php }}' + coverage: none + tools: composer,cs2pr + + - name: Get Composer cache Directory + id: composer-cache + run: | + echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Use Composer cache + uses: actions/cache@master + with: + path: ${{ steps['composer-cache'].outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + + - name: Install dependencies + run: COMPOSER_ROOT_VERSION=dev-master composer install --prefer-dist --no-progress --no-suggest + + - name: Setup problem matcher to provide annotations for PHPUnit + run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Run PHPUnit + run: composer test From f599b11a349136b1077f70f57d550ddce3b6c2bd Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 12:26:38 +0000 Subject: [PATCH 04/26] Avoid resetting Composer root version --- .github/workflows/code-quality.yml | 4 ++-- .github/workflows/testing.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index 8ded2a351..688968286 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -31,7 +31,7 @@ jobs: ${{ runner.os }}-composer- - name: Install dependencies - run: COMPOSER_ROOT_VERSION=dev-master composer install --prefer-dist --no-progress --no-suggest + run: composer install --prefer-dist --no-progress --no-suggest - name: Run Linter run: vendor/bin/parallel-lint -j 10 . --exclude vendor --checkstyle | cs2pr @@ -64,7 +64,7 @@ jobs: ${{ runner.os }}-composer- - name: Install dependencies - run: COMPOSER_ROOT_VERSION=dev-master composer install --prefer-dist --no-progress --no-suggest + run: composer install --prefer-dist --no-progress --no-suggest - name: Run PHPCS run: vendor/bin/phpcs -q --report=checkstyle | cs2pr diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 1a846e893..0e5507e34 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -37,7 +37,7 @@ jobs: ${{ runner.os }}-composer- - name: Install dependencies - run: COMPOSER_ROOT_VERSION=dev-master composer install --prefer-dist --no-progress --no-suggest + run: composer install --prefer-dist --no-progress --no-suggest - name: Setup problem matcher to provide annotations for PHPUnit run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" From a3ba0e72eca12dc2ef47593d2e32a6fa8e133be8 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 12:28:21 +0000 Subject: [PATCH 05/26] Add missing TestCase file --- tests/TestCase.php | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 tests/TestCase.php diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 000000000..841ae15d0 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,5 @@ + Date: Tue, 9 Feb 2021 12:36:33 +0000 Subject: [PATCH 06/26] Start and stop proxy server --- .github/workflows/testing.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 0e5507e34..db165d7fa 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -42,5 +42,31 @@ jobs: - name: Setup problem matcher to provide annotations for PHPUnit run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + - name: Setup proxy server + run: pip install --user mitmproxy==0.18.2 + + - name: Start test server + run: | + PORT=8080 vendor/bin/start.sh + export REQUESTS_TEST_HOST_HTTP="localhost:8080" + + - name: Start proxy server + run: | + PROXYBIN="$HOME/.local/bin/mitmdump" PORT=9002 tests/utils/proxy/start.sh + PROXYBIN="$HOME/.local/bin/mitmdump" PORT=9003 AUTH="test:pass" tests/utils/proxy/start.sh + export REQUESTS_HTTP_PROXY="localhost:9002" + export REQUESTS_HTTP_PROXY_AUTH="localhost:9003" + export REQUESTS_HTTP_PROXY_AUTH_USER="test" + export REQUESTS_HTTP_PROXY_AUTH_PASS="pass" + + - name: Ensure the HTTPS test instance on Heroku is spun up + run: curl -s -I http://requests-php-tests.herokuapp.com/ > /dev/null + - name: Run PHPUnit run: composer test + + - name: Stop proxy server + run: tests/utils/proxy/stop.sh + + - name: Stop test server + run: vendor/bin/stop.sh From b0763cc15cf2eac7509e784557d737aaa9cea173 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 12:40:51 +0000 Subject: [PATCH 07/26] Install pip requirements first before using pip --- .github/workflows/testing.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index db165d7fa..81aa37324 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -42,6 +42,9 @@ jobs: - name: Setup problem matcher to provide annotations for PHPUnit run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + - name: Install pip requirements + run: sudo apt-get install python-dev libxml2-dev libxslt-dev libz-dev + - name: Setup proxy server run: pip install --user mitmproxy==0.18.2 From 44115c1bf176ffbeafce5372bd0e283a68c00d7f Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 12:43:52 +0000 Subject: [PATCH 08/26] Install pip wheel --- .github/workflows/testing.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 81aa37324..c498b1a2d 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -43,7 +43,9 @@ jobs: run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Install pip requirements - run: sudo apt-get install python-dev libxml2-dev libxslt-dev libz-dev + run: | + sudo apt-get install python-dev libxml2-dev libxslt-dev libz-dev + pip install wheel - name: Setup proxy server run: pip install --user mitmproxy==0.18.2 From 341725389dd244c98904ec259afb05b30caa3039 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 12:46:37 +0000 Subject: [PATCH 09/26] Avoid forcing an old version of the proxy server --- .github/workflows/testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index c498b1a2d..b246506ed 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -48,7 +48,7 @@ jobs: pip install wheel - name: Setup proxy server - run: pip install --user mitmproxy==0.18.2 + run: pip install --user mitmproxy - name: Start test server run: | From 9d12893d597311a322fca54b455f9bd8513e7276 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 12:56:25 +0000 Subject: [PATCH 10/26] Try to use apt to install mitmproxy --- .github/workflows/testing.yml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index b246506ed..fd768a60a 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -42,13 +42,8 @@ jobs: - name: Setup problem matcher to provide annotations for PHPUnit run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - - name: Install pip requirements - run: | - sudo apt-get install python-dev libxml2-dev libxslt-dev libz-dev - pip install wheel - - name: Setup proxy server - run: pip install --user mitmproxy + run: sudo apt-get install mitmproxy - name: Start test server run: | @@ -57,8 +52,8 @@ jobs: - name: Start proxy server run: | - PROXYBIN="$HOME/.local/bin/mitmdump" PORT=9002 tests/utils/proxy/start.sh - PROXYBIN="$HOME/.local/bin/mitmdump" PORT=9003 AUTH="test:pass" tests/utils/proxy/start.sh + PORT=9002 tests/utils/proxy/start.sh + PORT=9003 AUTH="test:pass" tests/utils/proxy/start.sh export REQUESTS_HTTP_PROXY="localhost:9002" export REQUESTS_HTTP_PROXY_AUTH="localhost:9003" export REQUESTS_HTTP_PROXY_AUTH_USER="test" From 73244c76a31f9c37a6846c3dc857202a617f60e5 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 13:06:45 +0000 Subject: [PATCH 11/26] Use GITHUB_ENV to pass env variables between steps --- .github/workflows/testing.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index fd768a60a..ec123b019 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -48,16 +48,17 @@ jobs: - name: Start test server run: | PORT=8080 vendor/bin/start.sh - export REQUESTS_TEST_HOST_HTTP="localhost:8080" + echo 'export REQUESTS_TEST_HOST_HTTP="localhost:8080"' >> $GITHUB_ENV - name: Start proxy server run: | PORT=9002 tests/utils/proxy/start.sh PORT=9003 AUTH="test:pass" tests/utils/proxy/start.sh - export REQUESTS_HTTP_PROXY="localhost:9002" - export REQUESTS_HTTP_PROXY_AUTH="localhost:9003" - export REQUESTS_HTTP_PROXY_AUTH_USER="test" - export REQUESTS_HTTP_PROXY_AUTH_PASS="pass" + echo 'REQUESTS_HTTP_PROXY="localhost:9002"' >> $GITHUB_ENV + echo 'REQUESTS_HTTP_PROXY="localhost:9002"' >> $GITHUB_ENV + echo 'REQUESTS_HTTP_PROXY_AUTH="localhost:9003"' >> $GITHUB_ENV + echo 'REQUESTS_HTTP_PROXY_AUTH_USER="test"' >> $GITHUB_ENV + echo 'REQUESTS_HTTP_PROXY_AUTH_PASS="pass"' >> $GITHUB_ENV - name: Ensure the HTTPS test instance on Heroku is spun up run: curl -s -I http://requests-php-tests.herokuapp.com/ > /dev/null From 80f1c26bb5d8b8a33840f29e9350b884a50b4a40 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 13:08:50 +0000 Subject: [PATCH 12/26] Remove left-over export keyword --- .github/workflows/testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index ec123b019..c5fd0cb0e 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -48,7 +48,7 @@ jobs: - name: Start test server run: | PORT=8080 vendor/bin/start.sh - echo 'export REQUESTS_TEST_HOST_HTTP="localhost:8080"' >> $GITHUB_ENV + echo 'REQUESTS_TEST_HOST_HTTP="localhost:8080"' >> $GITHUB_ENV - name: Start proxy server run: | From a14d4108d082831156431ac09d90ffb04db78ca8 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 13:13:31 +0000 Subject: [PATCH 13/26] Improve quotes --- .github/workflows/testing.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index c5fd0cb0e..3a6c0ae28 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -48,17 +48,17 @@ jobs: - name: Start test server run: | PORT=8080 vendor/bin/start.sh - echo 'REQUESTS_TEST_HOST_HTTP="localhost:8080"' >> $GITHUB_ENV + echo "REQUESTS_TEST_HOST_HTTP=localhost:8080" >> $GITHUB_ENV - name: Start proxy server run: | PORT=9002 tests/utils/proxy/start.sh PORT=9003 AUTH="test:pass" tests/utils/proxy/start.sh - echo 'REQUESTS_HTTP_PROXY="localhost:9002"' >> $GITHUB_ENV - echo 'REQUESTS_HTTP_PROXY="localhost:9002"' >> $GITHUB_ENV - echo 'REQUESTS_HTTP_PROXY_AUTH="localhost:9003"' >> $GITHUB_ENV - echo 'REQUESTS_HTTP_PROXY_AUTH_USER="test"' >> $GITHUB_ENV - echo 'REQUESTS_HTTP_PROXY_AUTH_PASS="pass"' >> $GITHUB_ENV + echo "REQUESTS_HTTP_PROXY=localhost:9002" >> $GITHUB_ENV + echo "REQUESTS_HTTP_PROXY=localhost:9002" >> $GITHUB_ENV + echo "REQUESTS_HTTP_PROXY_AUTH=localhost:9003" >> $GITHUB_ENV + echo "REQUESTS_HTTP_PROXY_AUTH_USER=test" >> $GITHUB_ENV + echo "REQUESTS_HTTP_PROXY_AUTH_PASS=pass" >> $GITHUB_ENV - name: Ensure the HTTPS test instance on Heroku is spun up run: curl -s -I http://requests-php-tests.herokuapp.com/ > /dev/null From 3dfb3269b5e5780c5f8afa6fefcc77c3e9e044fb Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 14:29:54 +0000 Subject: [PATCH 14/26] Use IP instead of localhost --- .github/workflows/testing.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 3a6c0ae28..6421560c3 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -48,15 +48,15 @@ jobs: - name: Start test server run: | PORT=8080 vendor/bin/start.sh - echo "REQUESTS_TEST_HOST_HTTP=localhost:8080" >> $GITHUB_ENV + echo "REQUESTS_TEST_HOST_HTTP=127.0.0.1:8080" >> $GITHUB_ENV - name: Start proxy server run: | PORT=9002 tests/utils/proxy/start.sh PORT=9003 AUTH="test:pass" tests/utils/proxy/start.sh - echo "REQUESTS_HTTP_PROXY=localhost:9002" >> $GITHUB_ENV - echo "REQUESTS_HTTP_PROXY=localhost:9002" >> $GITHUB_ENV - echo "REQUESTS_HTTP_PROXY_AUTH=localhost:9003" >> $GITHUB_ENV + echo "REQUESTS_HTTP_PROXY=127.0.0.1:9002" >> $GITHUB_ENV + echo "REQUESTS_HTTP_PROXY=127.0.0.1:9002" >> $GITHUB_ENV + echo "REQUESTS_HTTP_PROXY_AUTH=127.0.0.1:9003" >> $GITHUB_ENV echo "REQUESTS_HTTP_PROXY_AUTH_USER=test" >> $GITHUB_ENV echo "REQUESTS_HTTP_PROXY_AUTH_PASS=pass" >> $GITHUB_ENV From 0001052bb091f0b60628064ff77c607f25efdcb9 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 14:51:54 +0000 Subject: [PATCH 15/26] Revert "Use IP instead of localhost" This reverts commit 3dfb3269b5e5780c5f8afa6fefcc77c3e9e044fb. --- .github/workflows/testing.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 6421560c3..3a6c0ae28 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -48,15 +48,15 @@ jobs: - name: Start test server run: | PORT=8080 vendor/bin/start.sh - echo "REQUESTS_TEST_HOST_HTTP=127.0.0.1:8080" >> $GITHUB_ENV + echo "REQUESTS_TEST_HOST_HTTP=localhost:8080" >> $GITHUB_ENV - name: Start proxy server run: | PORT=9002 tests/utils/proxy/start.sh PORT=9003 AUTH="test:pass" tests/utils/proxy/start.sh - echo "REQUESTS_HTTP_PROXY=127.0.0.1:9002" >> $GITHUB_ENV - echo "REQUESTS_HTTP_PROXY=127.0.0.1:9002" >> $GITHUB_ENV - echo "REQUESTS_HTTP_PROXY_AUTH=127.0.0.1:9003" >> $GITHUB_ENV + echo "REQUESTS_HTTP_PROXY=localhost:9002" >> $GITHUB_ENV + echo "REQUESTS_HTTP_PROXY=localhost:9002" >> $GITHUB_ENV + echo "REQUESTS_HTTP_PROXY_AUTH=localhost:9003" >> $GITHUB_ENV echo "REQUESTS_HTTP_PROXY_AUTH_USER=test" >> $GITHUB_ENV echo "REQUESTS_HTTP_PROXY_AUTH_PASS=pass" >> $GITHUB_ENV From c0a101120aff25354da3dfbdc5d9d1b16580d146 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 14:58:14 +0000 Subject: [PATCH 16/26] Use pip to install mitmproxy --- .github/workflows/testing.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 3a6c0ae28..df623ff89 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -42,8 +42,13 @@ jobs: - name: Setup problem matcher to provide annotations for PHPUnit run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: '3.8' + - name: Setup proxy server - run: sudo apt-get install mitmproxy + run: pip3 install mitmproxy - name: Start test server run: | @@ -63,6 +68,13 @@ jobs: - name: Ensure the HTTPS test instance on Heroku is spun up run: curl -s -I http://requests-php-tests.herokuapp.com/ > /dev/null + - name: Verify environment + run: | + php -v + mitmdump -v + ping -c1 localhost + + - name: Run PHPUnit run: composer test From ca378506729d42587df73bfcd8fb5b8be25b1bce Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 14:58:51 +0000 Subject: [PATCH 17/26] Ping proxy domain --- .github/workflows/testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index df623ff89..03e916556 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -73,7 +73,7 @@ jobs: php -v mitmdump -v ping -c1 localhost - + curl http://localhost:9002 - name: Run PHPUnit run: composer test From e1348f966932dd5fa2490a5166289cec4055ec7c Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 15:00:54 +0000 Subject: [PATCH 18/26] Use --version instead of -v for mitmproxy check --- .github/workflows/testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 03e916556..9db1dee40 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -71,7 +71,7 @@ jobs: - name: Verify environment run: | php -v - mitmdump -v + mitmdump --version ping -c1 localhost curl http://localhost:9002 From a10ea71f04ffc0ffc414dfc9502a45d94066ec87 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 15:05:28 +0000 Subject: [PATCH 19/26] Add 8080 to env checks --- .github/workflows/testing.yml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 9db1dee40..b5b79365e 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -68,12 +68,17 @@ jobs: - name: Ensure the HTTPS test instance on Heroku is spun up run: curl -s -I http://requests-php-tests.herokuapp.com/ > /dev/null - - name: Verify environment - run: | - php -v - mitmdump --version - ping -c1 localhost - curl http://localhost:9002 + - name: Check mitmproxy version + run: mitmdump --version + + - name: Ping localhost domain + run: ping -c1 localhost + + - name: Access localhost on port 8080 + run: curl http://localhost:8080 + + - name: Access localhost on port 9002 + run: curl http://localhost:9002 - name: Run PHPUnit run: composer test From e83ad7df5a8b89c721f7fd23cbc4b30b0410effb Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 15:46:03 +0000 Subject: [PATCH 20/26] Fix proxy scripts to work with newest mitmproxy release --- tests/utils/proxy/start.sh | 14 +++++++++++--- tests/utils/proxy/stop.sh | 9 +++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/tests/utils/proxy/start.sh b/tests/utils/proxy/start.sh index 4e7edeca6..14ac2fdd8 100755 --- a/tests/utils/proxy/start.sh +++ b/tests/utils/proxy/start.sh @@ -1,11 +1,19 @@ +#!/usr/bin/env bash + PROXYDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" PORT=${PORT:-9000} PROXYBIN=${PROXYBIN:-"$(which mitmdump)"} ARGS="-s '$PROXYDIR/proxy.py' -p $PORT" if [[ ! -z "$AUTH" ]]; then - ARGS="$ARGS --singleuser=$AUTH" + ARGS="$ARGS --proxyauth $AUTH" fi -PIDFILE="$PROXYDIR/proxy.pid" +PIDFILE="$PROXYDIR/proxy-$PORT.pid" + +set -x + +start-stop-daemon --verbose --start --background --pidfile $PIDFILE --make-pidfile --exec $PROXYBIN -- $ARGS -start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --exec $PROXYBIN -- $ARGS +ps -p $(cat $PIDFILE) -u +sleep 2 +ps -p $(cat $PIDFILE) -u diff --git a/tests/utils/proxy/stop.sh b/tests/utils/proxy/stop.sh index 9854d04f5..8cb0eb92f 100755 --- a/tests/utils/proxy/stop.sh +++ b/tests/utils/proxy/stop.sh @@ -1,5 +1,10 @@ +#!/usr/bin/env bash + PROXYDIR="$PWD/$(dirname $0)" +PORT=${PORT:-9000} + +PIDFILE="$PROXYDIR/proxy-$PORT.pid" -PIDFILE="$PROXYDIR/proxy.pid" +set -x -start-stop-daemon --stop --pidfile $PIDFILE --make-pidfile && rm $PROXYDIR/proxy.pid +start-stop-daemon --verbose --stop --pidfile $PIDFILE --remove-pidfile From 3fa16bc5b92b4641eb22733c9208c5a512a8897b Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 15:50:05 +0000 Subject: [PATCH 21/26] Show header on curl requests --- .github/workflows/testing.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index b5b79365e..4ab0c9afb 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -75,10 +75,10 @@ jobs: run: ping -c1 localhost - name: Access localhost on port 8080 - run: curl http://localhost:8080 + run: curl -i http://localhost:8080 - name: Access localhost on port 9002 - run: curl http://localhost:9002 + run: curl -i http://localhost:9002 - name: Run PHPUnit run: composer test From dd776cc26dd2cc31e4529c11bcc6374cc7db922d Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 15:56:40 +0000 Subject: [PATCH 22/26] Add edge case TODO for fsockopen invalid auth test --- tests/Proxy/HTTP.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/Proxy/HTTP.php b/tests/Proxy/HTTP.php index a06b1a682..0f243b62c 100644 --- a/tests/Proxy/HTTP.php +++ b/tests/Proxy/HTTP.php @@ -126,6 +126,13 @@ public function testConnectWithInvalidAuth($transport) { ), 'transport' => $transport, ); + + if ($transport === 'Requests_Transport_fsockopen') { + // @TODO fsockopen connection times out on invalid auth instead of returning 407. + $this->expectException('Requests_Exception'); + $this->expectExceptionMessage('fsocket timed out'); + } + $response = Requests::get(httpbin('/get'), array(), $options); $this->assertSame(407, $response->status_code); } From 1ba6d61d5c83221d327bd899a49f6576bde793a2 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 16:02:02 +0000 Subject: [PATCH 23/26] Test from PHP 5.3 onwards --- .github/workflows/testing.yml | 2 +- .phpcs.xml.dist | 2 +- tests/Proxy/HTTP.php | 2 +- tests/TestCase.php | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 4ab0c9afb..f2a73ceb1 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -9,7 +9,7 @@ jobs: strategy: fail-fast: false matrix: - php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0'] + php: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0'] runs-on: ubuntu-latest steps: diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index 8381fb896..dbd1278fb 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -40,7 +40,7 @@ ############################################################################# --> - + /examples/*\.php$ diff --git a/tests/Proxy/HTTP.php b/tests/Proxy/HTTP.php index 0f243b62c..45e290b5c 100644 --- a/tests/Proxy/HTTP.php +++ b/tests/Proxy/HTTP.php @@ -118,7 +118,7 @@ public function testConnectWithAuth($transport) { public function testConnectWithInvalidAuth($transport) { $this->checkProxyAvailable('auth'); - $options = array( + $options = array( 'proxy' => array( REQUESTS_HTTP_PROXY_AUTH, REQUESTS_HTTP_PROXY_AUTH_USER . '!', diff --git a/tests/TestCase.php b/tests/TestCase.php index 841ae15d0..c005b9928 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -1,5 +1,5 @@ - Date: Tue, 9 Feb 2021 16:07:58 +0000 Subject: [PATCH 24/26] Terminate proxy servers properly --- .github/workflows/testing.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index f2a73ceb1..44af2b5b8 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -84,7 +84,9 @@ jobs: run: composer test - name: Stop proxy server - run: tests/utils/proxy/stop.sh + run: | + PORT=9002 tests/utils/proxy/stop.sh + PORT=9003 tests/utils/proxy/stop.sh - name: Stop test server run: vendor/bin/stop.sh From 793b2ca0b633c0241f1d2a83cc04df67f5685c96 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 9 Feb 2021 16:09:25 +0000 Subject: [PATCH 25/26] Bump testing to PHP 5.5+ --- .github/workflows/testing.yml | 2 +- .phpcs.xml.dist | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 44af2b5b8..a8606159f 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -9,7 +9,7 @@ jobs: strategy: fail-fast: false matrix: - php: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0'] + php: ['5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0'] runs-on: ubuntu-latest steps: diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index dbd1278fb..4e95aa118 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -40,11 +40,8 @@ ############################################################################# --> - - - - /examples/*\.php$ - + +