Skip to content

Commit 2713ec1

Browse files
authored
test: Add an e2e test for PHPUnit (#881)
Closes #640
1 parent 1bc4dda commit 2713ec1

File tree

5 files changed

+114
-9
lines changed

5 files changed

+114
-9
lines changed

.github/workflows/e2e-tests.yaml

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
types: [ created ]
99
schedule:
1010
# Do not make it the first of the month and/or midnight since it is a very busy time
11-
- cron: "* 10 5 * *"
11+
- cron: "* 10 5 * *"
1212

1313
# See https://stackoverflow.com/a/72408109
1414
concurrency:
@@ -149,6 +149,72 @@ jobs:
149149
- name: Run e2e ${{ matrix.e2e }}
150150
run: make ${{ matrix.e2e }} --debug
151151

152+
153+
# Most of the job definitions come from https://github.com/sebastianbergmann/phpunit/blob/main/.github/workflows/ci.yml#L228
154+
# (job name "test-phar").
155+
test-phpunit-scoping:
156+
runs-on: ubuntu-latest
157+
needs: build-test-phar
158+
159+
env:
160+
PHP_EXTENSIONS: none, curl, dom, json, fileinfo, iconv, libxml, mbstring, phar, soap, tokenizer, xml, xmlwriter
161+
PHP_INI_VALUES: assert.exception=1, phar.readonly=0, zend.assertions=1
162+
163+
strategy:
164+
fail-fast: false
165+
matrix:
166+
php-version:
167+
- '8.2'
168+
coverage:
169+
- xdebug
170+
171+
steps:
172+
- name: Checkout PHPUnit code
173+
uses: actions/checkout@v4
174+
with:
175+
repository: 'sebastianbergmann/phpunit'
176+
177+
178+
- name: Install PHP with extensions
179+
uses: shivammathur/setup-php@v2
180+
with:
181+
php-version: ${{ matrix.php-version }}
182+
coverage: ${{ matrix.coverage }}
183+
extensions: ${{ env.PHP_EXTENSIONS }}
184+
ini-values: ${{ env.PHP_INI_VALUES }}
185+
tools: none
186+
187+
- name: Install java
188+
uses: actions/setup-java@v3
189+
with:
190+
distribution: zulu
191+
java-version: 11
192+
193+
- name: Retrieve built PHP-Scoper PHAR
194+
uses: actions/download-artifact@v3
195+
with:
196+
name: php-scoper-phar-${{ matrix.php-version }}
197+
path: bin
198+
199+
# See https://github.com/actions/download-artifact#limitations
200+
# the permissions are not guaranteed to be preserved
201+
- name: Ensure PHAR is executable
202+
run: chmod 755 bin/php-scoper.phar
203+
204+
- name: Make the downloaded PHP-Scoper PHAR the PHPUnit scoper used
205+
run: mv -f bin/php-scoper.phar tools/php-scoper
206+
207+
- name: Check that the PHP-Scoper PHAR works
208+
run: tools/php-scoper --version
209+
210+
- name: Build PHPUnit scoped PHAR
211+
run: ant phar-snapshot
212+
213+
# To keep in sync with e2e.file#e2e_038
214+
- name: Run PHPUnit PHAR-specific tests
215+
run: ant run-phar-specific-tests
216+
217+
152218
# This is a "trick", a meta task which does not change, and we can use in
153219
# the protected branch rules as opposed to the E2E tests one above which
154220
# may change regularly.
@@ -160,12 +226,13 @@ jobs:
160226
needs:
161227
- build-test-phar
162228
- e2e-tests
229+
- test-phpunit-scoping
163230
if: always()
164231
steps:
165-
- name: Successful run
166-
if: ${{ !(contains(needs.*.result, 'failure')) }}
167-
run: exit 0
232+
- name: Successful run
233+
if: ${{ !(contains(needs.*.result, 'failure')) }}
234+
run: exit 0
168235

169-
- name: Failing run
170-
if: ${{ contains(needs.*.result, 'failure') }}
171-
run: exit 1
236+
- name: Failing run
237+
if: ${{ contains(needs.*.result, 'failure') }}
238+
run: exit 1

.makefile/e2e.file

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
E2E_PHPUNIT_DIR = 'build/set038/phpunit'
2+
E2E_PHPUNIT_PHPUNIT_PHP_SCOPER = '$(E2E_PHPUNIT_DIR)/tools/php-scoper'
3+
E2E_PHPUNIT_SCOPED_PHPUNIT = 'build/artifacts/phpunit-snapshot.phar'
4+
15
.PHONY: e2e_004
26
e2e_004: # Runs end-to-end tests for the fixture set 004 — Minimalistic codebase
37
e2e_004: $(PHP_SCOPER_PHAR_BIN)
@@ -370,6 +374,24 @@ e2e_037: $(PHP_SCOPER_PHAR_BIN) build/set011/bin/greet.phar
370374
diff fixtures/set037-double-scoping/expected-output build/set037/output
371375

372376

377+
.PHONY: e2e_038
378+
e2e_038: # Runs end-to-end tests for the PHPUnit integration
379+
e2e_038: $(PHP_SCOPER_PHAR_BIN)
380+
rm -rf $(E2E_PHPUNIT_DIR) || true
381+
$(MAKE) $(E2E_PHPUNIT_DIR)
382+
383+
rm -rf $(E2E_PHPUNIT_PHPUNIT_PHP_SCOPER) || true
384+
cp $(PHP_SCOPER_PHAR_BIN) $(E2E_PHPUNIT_PHPUNIT_PHP_SCOPER)
385+
386+
cd $(E2E_PHPUNIT_DIR); ant phar-snapshot
387+
$(MAKE) _e2e_038
388+
389+
.PHONY: _e2e_038
390+
_e2e_038:
391+
@# To keep in sync with .github/workflows/e2e-tests.yaml#test-phpunit-scoping
392+
cd $(E2E_PHPUNIT_DIR); XDEBUG_MODE=coverage ant run-phar-specific-tests
393+
394+
373395
#
374396
# Rules from files
375397
#---------------------------------------------------------------------------
@@ -507,3 +529,8 @@ fixtures/set035-composer-files-autoload/guzzle5-include/vendor: fixtures/set035-
507529
fixtures/set035-composer-files-autoload/guzzle5-include/composer.lock: fixtures/set035-composer-files-autoload/guzzle5-include/composer.json
508530
@echo "$(@) is not up to date. You may want to run the following command:"
509531
@echo "$$ composer --working-dir=fixtures/set035-composer-files-autoload/guzzle5-include update --lock && touch -c $(@)"
532+
533+
build/set038/phpunit:
534+
rm -rf $(E2E_PHPUNIT_DIR) || true
535+
git clone --depth=1 --single-branch [email protected]:sebastianbergmann/phpunit.git $@
536+
touch -c $@

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ e2e: e2e_004 \
170170
e2e_034 \
171171
e2e_035 \
172172
e2e_036 \
173-
e2e_037
173+
e2e_037 \
174+
e2e_038
174175

175176
.PHONY: blackfire
176177
blackfire: ## Runs Blackfire profiling

tests/AutoReview/E2ECollector.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ final class E2ECollector
4444
'set012',
4545
];
4646

47+
private const E2E_TEST_WITHOUT_FIXTURE_DIR = [
48+
'e2e_038',
49+
];
50+
4751
/**
4852
* @return list<string>
4953
*/
@@ -74,6 +78,7 @@ private static function findE2ENames(): array
7478
iterator_to_array($finder, false),
7579
),
7680
);
81+
$names = [...$names, ...self::E2E_TEST_WITHOUT_FIXTURE_DIR];
7782

7883
sort($names, SORT_STRING);
7984

tests/AutoReview/GAE2ETest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
namespace Humbug\PhpScoper\AutoReview;
1616

1717
use PHPUnit\Framework\TestCase;
18+
use function array_diff;
1819

1920
/**
2021
* @coversNothing
@@ -23,9 +24,13 @@
2324
*/
2425
class GAE2ETest extends TestCase
2526
{
27+
private const IGNORED_E2E_TESTS = [
28+
'e2e_038',
29+
];
30+
2631
public function test_github_actions_executes_all_the_e2e_tests(): void
2732
{
28-
$expected = E2ECollector::getE2ENames();
33+
$expected = array_diff(E2ECollector::getE2ENames(), self::IGNORED_E2E_TESTS);
2934
$actual = GAE2ECollector::getExecutedE2ETests();
3035

3136
self::assertEqualsCanonicalizing($expected, $actual);

0 commit comments

Comments
 (0)