Skip to content

Commit

Permalink
Merge pull request #491 from ergebnis/feature/phpunit-9
Browse files Browse the repository at this point in the history
Enhancement: Add support for using Phar with `phpunit/phpunit:^9.0.0`
  • Loading branch information
localheinz committed Feb 5, 2024
2 parents 03b8466 + 7a6038e commit f07b094
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 6 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/integrate.yaml
Expand Up @@ -598,7 +598,7 @@ jobs:
run: "vendor/bin/phpunit --colors=always --configuration=test/EndToEnd/Version11/phpunit.xml"

- name: "Download Phar"
if: "matrix.phpunit-version == '10.0.0'"
if: "matrix.phpunit-version == '9.0.0' || matrix.phpunit-version == '10.0.0'"
uses: "actions/download-artifact@v4.1.1"
with:
name: "phpunit-slow-test-detector-phar"
Expand All @@ -607,6 +607,10 @@ jobs:
- name: "Remove autoloader for composer"
run: "composer install --ansi --no-autoloader --no-interaction"

- name: "Run phar tests with phpunit/phpunit:9.0.0"
if: "matrix.phpunit-version == '9.0.0'"
run: "vendor/bin/phpunit --colors=always --configuration=test/Phar/Version09/phpunit.xml"

- name: "Run phar tests with phpunit/phpunit:10.0.0"
if: "matrix.phpunit-version == '10.0.0'"
run: "vendor/bin/phpunit --colors=always --configuration=test/Phar/Version10/phpunit.xml"
4 changes: 2 additions & 2 deletions .phive/phars.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="humbug/box" version="^4.4.0" installed="4.4.0" location="./.phive/box" copy="false"/>
<phar name="composer-require-checker" version="~3.8.0" installed="3.8.0" location="./.phive/composer-require-checker" copy="false"/>
<phar name="humbug/box" version="~3.16.0" installed="3.16.0" location="./.phive/box" copy="false"/>
<phar name="composer-require-checker" version="~3.8.0" installed="3.8.0" location="./.phive/composer-require-checker" copy="false"/>
</phive>
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

For a full diff see [`2.9.0...main`][2.9.0...main].

### Changed

- Added support for using `phpunit-slow-test-detector.phar` with `phpunit/phpunit:^9.0.0` ([#491]), by [@localheinz]

## [`2.9.0`][2.9.0]

For a full diff see [`2.8.0...2.9.0`][2.8.0...2.9.0].
Expand Down Expand Up @@ -263,6 +267,7 @@ For a full diff see [`7afa59c...1.0.0`][7afa59c...1.0.0].
[#396]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/396
[#447]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/447
[#448]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/448
[#491]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/491

[@HypeMC]: https://github.com/HypeMC
[@localheinz]: https://github.com/localheinz
Expand Down
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -58,6 +58,7 @@ tests: phar ## Runs unit, end-to-end, and phar tests with phpunit/phpunit
composer config platform.php --unset; composer remove ergebnis/php-cs-fixer-config psalm/plugin-phpunit vimeo/psalm --dev --no-interaction --quiet; composer require phpunit/phpunit:^9.0.0 --no-interaction --quiet --update-with-all-dependencies; vendor/bin/phpunit --configuration=test/EndToEnd/Version09/phpunit.xml; git checkout HEAD -- composer.json composer.lock
composer config platform.php --unset; composer remove ergebnis/php-cs-fixer-config psalm/plugin-phpunit vimeo/psalm --dev --no-interaction --quiet; composer require phpunit/phpunit:^10.0.0 --no-interaction --quiet --update-with-all-dependencies; vendor/bin/phpunit --configuration=test/EndToEnd/Version10/phpunit.xml; git checkout HEAD -- composer.json composer.lock
composer config platform.php --unset; composer remove ergebnis/php-cs-fixer-config psalm/plugin-phpunit vimeo/psalm --dev --no-interaction --quiet; composer require phpunit/phpunit:11.0.x-dev --no-interaction --quiet --update-with-all-dependencies; vendor/bin/phpunit --configuration=test/EndToEnd/Version11/phpunit.xml; git checkout HEAD -- composer.json composer.lock
composer config platform.php --unset; composer remove ergebnis/php-cs-fixer-config psalm/plugin-phpunit vimeo/psalm --dev --no-interaction --quiet; composer require phpunit/phpunit:^9.0.0 --no-interaction --quiet --update-with-all-dependencies; composer install --no-autoloader --no-interaction --quiet; vendor/bin/phpunit --configuration=test/Phar/Version09/phpunit.xml; git checkout HEAD -- composer.json composer.lock
composer config platform.php --unset; composer remove ergebnis/php-cs-fixer-config psalm/plugin-phpunit vimeo/psalm --dev --no-interaction --quiet; composer require phpunit/phpunit:^10.0.0 --no-interaction --quiet --update-with-all-dependencies; composer install --no-autoloader --no-interaction --quiet; vendor/bin/phpunit --configuration=test/Phar/Version10/phpunit.xml; git checkout HEAD -- composer.json composer.lock

vendor: composer.json composer.lock
Expand Down
23 changes: 22 additions & 1 deletion README.md
Expand Up @@ -35,7 +35,7 @@ to install `ergebnis/phpunit-slow-test-detector` as a `composer` package when us

### Installation as Phar

Download `phpunit-slow-test-detector.phar` from the [latest release](https://github.com/ergebnis/phpunit-slow-test-detector/releases/latest) when using `phpunit/phpunit:^10.0.0`.
Download `phpunit-slow-test-detector.phar` from the [latest release](https://github.com/ergebnis/phpunit-slow-test-detector/releases/latest) when using `phpunit/phpunit:^9.0.0` or `phpunit/phpunit:^10.0.0`.

## Usage

Expand Down Expand Up @@ -106,6 +106,27 @@ To bootstrap the extension as a `composer` package when using `phpunit/phpunit:^
</phpunit>
```

### Bootstrapping the extension as a PHAR when using `phpunit/phpunit:^10.0.0`

To bootstrap the extension as a PHAR when using `phpunit/phpunit:^9.0.0`, adjust your `phpunit.xml` configuration file and configure the [`extensionsDirectory` attribute](https://docs.phpunit.de/en/9.6/configuration.html#the-extensionsdirectory-attribute) of the [`<phpunit>` element](https://docs.phpunit.de/en/9.6/configuration.html#the-phpunit-element):

```diff
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
+ extensionsDirectory="directory/where/you/saved/the/extension/phars"
>
+ <extensions>
+ <extension class="Ergebnis\PHPUnit\SlowTestDetector\Extension"/>
+ </extensions>
<testsuites>
<testsuite name="unit">
<directory>test/Unit/</directory>
</testsuite>
</testsuites>
</phpunit>
```
### Bootstrapping the extension as a `composer` package when using `phpunit/phpunit:^10.0.0`

To bootstrap the extension as a `composer` package when using `phpunit/phpunit:^10.0.0`, adjust your `phpunit.xml` configuration file and configure the [`extensions` element](https://docs.phpunit.de/en/10.5/configuration.html#the-extensions-element):
Expand Down
4 changes: 2 additions & 2 deletions manifest.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<phar xmlns="https://phar.io/xml/manifest/1.0">
<contains name="ergebnis/phpunit-slow-test-detector" version="2.9.0" type="extension">
<extension for="phpunit/phpunit" compatible="^10.0"/>
<extension for="phpunit/phpunit" compatible="^9.0 || ^10.0"/>
</contains>

<copyright>
Expand All @@ -10,6 +10,6 @@
</copyright>

<requires>
<php version="^8.1"/>
<php version="^7.4"/>
</requires>
</phar>
45 changes: 45 additions & 0 deletions test/Phar/Version09/SleeperTest.php
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2021-2024 Andreas Möller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/phpunit-slow-test-detector
*/

namespace Ergebnis\PHPUnit\SlowTestDetector\Test\Phar\Version09;

use Ergebnis\PHPUnit\SlowTestDetector\Test;
use PHPUnit\Framework;

/**
* @covers \Ergebnis\PHPUnit\SlowTestDetector\Test\Fixture\Sleeper
*/
final class SleeperTest extends Framework\TestCase
{
public function testSleeperDoesNotSleepAtAll(): void
{
$milliseconds = 0;

$sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds);

$sleeper->sleep();

self::assertSame($milliseconds, $sleeper->milliseconds());
}

public function testSleeperSleepsJustAboveDefaultMaximumDuration(): void
{
$milliseconds = 600;

$sleeper = Test\Fixture\Sleeper::fromMilliseconds($milliseconds);

$sleeper->sleep();

self::assertSame($milliseconds, $sleeper->milliseconds());
}
}
14 changes: 14 additions & 0 deletions test/Phar/Version09/bootstrap.php
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2021-2024 Andreas Möller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/phpunit-slow-test-detector
*/

require_once __DIR__ . '/../../Fixture/Sleeper.php';
28 changes: 28 additions & 0 deletions test/Phar/Version09/phpunit.xml
@@ -0,0 +1,28 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.0/phpunit.xsd"
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutTodoAnnotatedTests="true"
bootstrap="bootstrap.php"
cacheResult="false"
colors="true"
columns="max"
executionOrder="random"
extensionsDirectory="../../../.build/phar/"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
verbose="true"
>
<extensions>
<extension class="Ergebnis\PHPUnit\SlowTestDetector\Extension"/>
</extensions>
<testsuites>
<testsuite name="Unit Tests">
<directory>.</directory>
</testsuite>
</testsuites>
</phpunit>

0 comments on commit f07b094

Please sign in to comment.