Skip to content

Commit

Permalink
Reorganize PHAR testing
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jul 27, 2021
1 parent becab3f commit 2fc712c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 13 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,11 @@ jobs:
with:
java-version: 1.8

- name: Build unscoped PHAR for testing
run: ant unscoped-phar-snapshot

- name: Run regular tests with unscoped PHAR
run: ./build/artifacts/phpunit-snapshot.phar

- name: Build scoped PHAR for testing
run: ant phar-snapshot
run: ant run-regular-tests-with-unscoped-phar

- name: Run PHAR-specific tests with scoped PHAR
run: ./build/artifacts/phpunit-snapshot.phar --configuration tests/phar/phpunit.xml
run: ant run-phar-specific-tests-with-scoped-phar

- uses: actions/upload-artifact@v2
if: ${{ matrix.php-version == 8.0 }}
Expand Down
34 changes: 32 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
</antcall>
</target>

<target name="unscoped-phar" depends="-phar-prepare,-phar-determine-version" description="Create PHAR archive of PHPUnit and all its dependencies">
<target name="unscoped-phar" depends="-phar-prepare,-phar-determine-version" description="Create unscoped PHAR archive of PHPUnit and all its dependencies">
<antcall target="-phar-build">
<param name="type" value="release"/>
<param name="scope" value="false"/>
Expand All @@ -133,7 +133,7 @@
</antcall>
</target>

<target name="unscoped-phar-snapshot" depends="-phar-prepare" description="Create PHAR archive of PHPUnit and all its dependencies (snapshot)">
<target name="unscoped-phar-snapshot" depends="-phar-prepare" description="Create unscoped PHAR archive of PHPUnit and all its dependencies (snapshot)">
<antcall target="-phar-build">
<param name="type" value="snapshot"/>
<param name="scope" value="false"/>
Expand Down Expand Up @@ -432,6 +432,36 @@
<exec executable="${basedir}/build/scripts/version.php" outputproperty="version" failonerror="true" />
</target>

<target name="run-regular-tests-with-unscoped-phar" depends="clean,unscoped-phar-snapshot" description="Build unscoped PHAR snapshot and run the regular test suite with it">
<exec executable="${basedir}/tools/phpab" taskname="phpab" failonerror="true">
<arg value="--output" />
<arg path="${basedir}/tests/autoload.php" />
<arg path="${basedir}/tests/_files" />
<arg path="${basedir}/tests/end-to-end/execution-order/_files" />
<arg path="${basedir}/tests/unit" />
</exec>

<delete dir="${basedir}/vendor"/>
<delete file="${basedir}/composer.lock"/>

<exec executable="${basedir}/build/artifacts/phpunit-snapshot.phar" taskname="phpunit" failonerror="true">
<arg value="--testsuite" />
<arg value="unit" />
</exec>

<delete file="${basedir}/tests/autoload.php"/>
</target>

<target name="run-phar-specific-tests-with-scoped-phar" depends="clean,phar-snapshot" description="Build scoped PHAR snapshot and run the PHAR-specific tests with it">
<delete dir="${basedir}/vendor"/>
<delete file="${basedir}/composer.lock"/>

<exec executable="${basedir}/build/artifacts/phpunit-snapshot.phar" taskname="phpunit" failonerror="true">
<arg value="--configuration" />
<arg value="tests/phar/phpunit.xml" />
</exec>
</target>

<target name="generate-project-documentation" depends="-phploc,-checkstyle,-phpunit">
<exec executable="${basedir}/tools/phpdox" dir="${basedir}/build/config" taskname="phpdox"/>
</target>
Expand Down
33 changes: 30 additions & 3 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,35 @@
*/
const TEST_FILES_PATH = __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR;

if (!defined('PHPUNIT_COMPOSER_INSTALL')) {
define('PHPUNIT_COMPOSER_INSTALL', dirname(__DIR__) . '/vendor/autoload.php');
if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
if (!defined('PHPUNIT_COMPOSER_INSTALL')) {
define('PHPUNIT_COMPOSER_INSTALL', dirname(__DIR__) . '/vendor/autoload.php');
}

require_once __DIR__ . '/../vendor/autoload.php';

return;
}

if (file_exists(__DIR__ . '/autoload.php')) {
if (!defined('__PHPUNIT_PHAR__')) {
define('__PHPUNIT_PHAR__', realpath($_SERVER['_']));
}

require_once __DIR__ . '/autoload.php';

$jsonFile = dirname(__DIR__) . '/composer.json';
$base = dirname($jsonFile);

foreach (json_decode(file_get_contents($jsonFile), true)['autoload-dev']['files'] as $file) {
require_once $base . DIRECTORY_SEPARATOR . $file;
}

unset($jsonFile, $base, $file);

return;
}

require_once PHPUNIT_COMPOSER_INSTALL;
print 'No test fixture autoloader was registered, exiting.' . \PHP_EOL;

exit(1);

0 comments on commit 2fc712c

Please sign in to comment.