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

test: Add an e2e test for PHPUnit #881

Merged
merged 7 commits into from
Nov 2, 2023
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
81 changes: 74 additions & 7 deletions .github/workflows/e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
types: [ created ]
schedule:
# Do not make it the first of the month and/or midnight since it is a very busy time
- cron: "* 10 5 * *"
- cron: "* 10 5 * *"

# See https://stackoverflow.com/a/72408109
concurrency:
Expand Down Expand Up @@ -149,6 +149,72 @@ jobs:
- name: Run e2e ${{ matrix.e2e }}
run: make ${{ matrix.e2e }} --debug


# Most of the job definitions come from https://github.com/sebastianbergmann/phpunit/blob/main/.github/workflows/ci.yml#L228
# (job name "test-phar").
test-phpunit-scoping:
runs-on: ubuntu-latest
needs: build-test-phar

env:
PHP_EXTENSIONS: none, curl, dom, json, fileinfo, iconv, libxml, mbstring, phar, soap, tokenizer, xml, xmlwriter
PHP_INI_VALUES: assert.exception=1, phar.readonly=0, zend.assertions=1

strategy:
fail-fast: false
matrix:
php-version:
- '8.2'
coverage:
- xdebug

steps:
- name: Checkout PHPUnit code
uses: actions/checkout@v4
with:
repository: 'sebastianbergmann/phpunit'


- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: ${{ matrix.coverage }}
extensions: ${{ env.PHP_EXTENSIONS }}
ini-values: ${{ env.PHP_INI_VALUES }}
tools: none

- name: Install java
uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 11

- name: Retrieve built PHP-Scoper PHAR
uses: actions/download-artifact@v3
with:
name: php-scoper-phar-${{ matrix.php-version }}
path: bin

# See https://github.com/actions/download-artifact#limitations
# the permissions are not guaranteed to be preserved
- name: Ensure PHAR is executable
run: chmod 755 bin/php-scoper.phar

- name: Make the downloaded PHP-Scoper PHAR the PHPUnit scoper used
run: mv -f bin/php-scoper.phar tools/php-scoper

- name: Check that the PHP-Scoper PHAR works
run: tools/php-scoper --version

- name: Build PHPUnit scoped PHAR
run: ant phar-snapshot

# To keep in sync with e2e.file#e2e_038
- name: Run PHPUnit PHAR-specific tests
run: ant run-phar-specific-tests


# This is a "trick", a meta task which does not change, and we can use in
# the protected branch rules as opposed to the E2E tests one above which
# may change regularly.
Expand All @@ -160,12 +226,13 @@ jobs:
needs:
- build-test-phar
- e2e-tests
- test-phpunit-scoping
if: always()
steps:
- name: Successful run
if: ${{ !(contains(needs.*.result, 'failure')) }}
run: exit 0
- name: Successful run
if: ${{ !(contains(needs.*.result, 'failure')) }}
run: exit 0

- name: Failing run
if: ${{ contains(needs.*.result, 'failure') }}
run: exit 1
- name: Failing run
if: ${{ contains(needs.*.result, 'failure') }}
run: exit 1
27 changes: 27 additions & 0 deletions .makefile/e2e.file
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
E2E_PHPUNIT_DIR = 'build/set038/phpunit'
E2E_PHPUNIT_PHPUNIT_PHP_SCOPER = '$(E2E_PHPUNIT_DIR)/tools/php-scoper'
E2E_PHPUNIT_SCOPED_PHPUNIT = 'build/artifacts/phpunit-snapshot.phar'

.PHONY: e2e_004
e2e_004: # Runs end-to-end tests for the fixture set 004 — Minimalistic codebase
e2e_004: $(PHP_SCOPER_PHAR_BIN)
Expand Down Expand Up @@ -370,6 +374,24 @@ e2e_037: $(PHP_SCOPER_PHAR_BIN) build/set011/bin/greet.phar
diff fixtures/set037-double-scoping/expected-output build/set037/output


.PHONY: e2e_038
e2e_038: # Runs end-to-end tests for the PHPUnit integration
e2e_038: $(PHP_SCOPER_PHAR_BIN)
rm -rf $(E2E_PHPUNIT_DIR) || true
$(MAKE) $(E2E_PHPUNIT_DIR)

rm -rf $(E2E_PHPUNIT_PHPUNIT_PHP_SCOPER) || true
cp $(PHP_SCOPER_PHAR_BIN) $(E2E_PHPUNIT_PHPUNIT_PHP_SCOPER)

cd $(E2E_PHPUNIT_DIR); ant phar-snapshot
$(MAKE) _e2e_038

.PHONY: _e2e_038
_e2e_038:
@# To keep in sync with .github/workflows/e2e-tests.yaml#test-phpunit-scoping
cd $(E2E_PHPUNIT_DIR); XDEBUG_MODE=coverage ant run-phar-specific-tests


#
# Rules from files
#---------------------------------------------------------------------------
Expand Down Expand Up @@ -507,3 +529,8 @@ fixtures/set035-composer-files-autoload/guzzle5-include/vendor: fixtures/set035-
fixtures/set035-composer-files-autoload/guzzle5-include/composer.lock: fixtures/set035-composer-files-autoload/guzzle5-include/composer.json
@echo "$(@) is not up to date. You may want to run the following command:"
@echo "$$ composer --working-dir=fixtures/set035-composer-files-autoload/guzzle5-include update --lock && touch -c $(@)"

build/set038/phpunit:
rm -rf $(E2E_PHPUNIT_DIR) || true
git clone --depth=1 --single-branch [email protected]:sebastianbergmann/phpunit.git $@
touch -c $@
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ e2e: e2e_004 \
e2e_034 \
e2e_035 \
e2e_036 \
e2e_037
e2e_037 \
e2e_038

.PHONY: blackfire
blackfire: ## Runs Blackfire profiling
Expand Down
5 changes: 5 additions & 0 deletions tests/AutoReview/E2ECollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ final class E2ECollector
'set012',
];

private const E2E_TEST_WITHOUT_FIXTURE_DIR = [
'e2e_038',
];

/**
* @return list<string>
*/
Expand Down Expand Up @@ -74,6 +78,7 @@ private static function findE2ENames(): array
iterator_to_array($finder, false),
),
);
$names = [...$names, ...self::E2E_TEST_WITHOUT_FIXTURE_DIR];

sort($names, SORT_STRING);

Expand Down
7 changes: 6 additions & 1 deletion tests/AutoReview/GAE2ETest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace Humbug\PhpScoper\AutoReview;

use PHPUnit\Framework\TestCase;
use function array_diff;

/**
* @coversNothing
Expand All @@ -23,9 +24,13 @@
*/
class GAE2ETest extends TestCase
{
private const IGNORED_E2E_TESTS = [
'e2e_038',
];

public function test_github_actions_executes_all_the_e2e_tests(): void
{
$expected = E2ECollector::getE2ENames();
$expected = array_diff(E2ECollector::getE2ENames(), self::IGNORED_E2E_TESTS);
$actual = GAE2ECollector::getExecutedE2ETests();

self::assertEqualsCanonicalizing($expected, $actual);
Expand Down