Skip to content

Commit

Permalink
Enhancement: Run unit tests with phpunit/phpunit:^9.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Dec 1, 2023
1 parent 3f77556 commit 47dafad
Show file tree
Hide file tree
Showing 24 changed files with 177 additions and 115 deletions.
2 changes: 1 addition & 1 deletion .github/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ branches:
required_approving_review_count: 1
required_status_checks:
checks:
- context: "Code Coverage (8.1, locked)"
- context: "Code Coverage (8.1, 9.6.0, locked)"
- context: "Coding Standards (8.1, locked)"
- context: "Compile Phar (8.1, locked)"
- context: "Dependency Analysis (8.1, locked)"
Expand Down
18 changes: 12 additions & 6 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
php-version:
- "8.1"

phpunit-version:
- "9.6.0"

dependencies:
- "locked"

Expand Down Expand Up @@ -54,6 +57,9 @@ jobs:
key: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}"
restore-keys: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-"

- name: "Require phpunit/phpunit:^${{ matrix.phpunit-version }}"
run: "composer require phpunit/phpunit:^${{ matrix.phpunit-version }} --ansi --no-interaction --no-progress --update-with-all-dependencies"

- name: "Install ${{ matrix.dependencies }} dependencies with composer"
uses: "ergebnis/.github/actions/composer/install@1.8.0"
with:
Expand Down Expand Up @@ -496,14 +502,14 @@ jobs:
with:
dependencies: "${{ matrix.dependencies }}"

- name: "Run unit tests with phpunit/phpunit:10.4.0"
if: "matrix.phpunit-version == '10.4.0'"
- name: "Run unit tests with phpunit/phpunit:9.6.0"
if: "matrix.phpunit-version == '9.6.0'"
run: "vendor/bin/phpunit --colors=always --configuration=test/Unit/phpunit.xml"

- name: "Run end-to-end tests with phpunit/phpunit:10.4.0"
if: "matrix.phpunit-version == '10.4.0'"
run: "vendor/bin/phpunit --colors=always --configuration=test/EndToEnd/Version10/phpunit.xml"

- name: "Run end-to-end tests with phpunit/phpunit:9.6.0"
if: "matrix.phpunit-version == '9.6.0'"
run: "vendor/bin/phpunit --colors=always --configuration=test/EndToEnd/Version9/phpunit.xml"

- name: "Run end-to-end tests with phpunit/phpunit:10.4.0"
if: "matrix.phpunit-version == '10.4.0'"
run: "vendor/bin/phpunit --colors=always --configuration=test/EndToEnd/Version10/phpunit.xml"
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ it: refactoring coding-standards security-analysis static-code-analysis tests ##
.PHONY: code-coverage
code-coverage: vendor ## Collects coverage from running unit tests with phpunit/phpunit
mkdir -p .build/phpunit/
vendor/bin/phpunit --configuration=test/Unit/phpunit.xml --coverage-text
composer require phpunit/phpunit:9.6.0 --no-interaction --quiet --update-with-all-dependencies; vendor/bin/phpunit --configuration=test/Unit/phpunit.xml --coverage-text; git checkout HEAD -- composer.json composer.lock; composer install --no-interaction --quiet

.PHONY: coding-standards
coding-standards: vendor ## Lints YAML files with yamllint, normalizes composer.json with ergebnis/composer-normalize, and fixes code style issues with friendsofphp/php-cs-fixer
Expand Down Expand Up @@ -59,9 +59,9 @@ static-code-analysis-baseline: vendor ## Generates a baseline for static code an
.PHONY: tests
tests: vendor ## Runs unit and end-to-end tests with phpunit/phpunit
mkdir -p .build/phpunit
composer require phpunit/phpunit:10.4.0 --no-interaction --quiet --update-with-all-dependencies; vendor/bin/phpunit --configuration=test/Unit/phpunit.xml; git checkout HEAD -- composer.json composer.lock; composer install --no-interaction --quiet
composer require phpunit/phpunit:10.4.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 install --no-interaction --quiet
composer require phpunit/phpunit:9.6.0 --no-interaction --quiet --update-with-all-dependencies; vendor/bin/phpunit --configuration=test/Unit/phpunit.xml; git checkout HEAD -- composer.json composer.lock; composer install --no-interaction --quiet
composer require phpunit/phpunit:9.6.0 --no-interaction --quiet --update-with-all-dependencies; vendor/bin/phpunit --configuration=test/EndToEnd/Version9/phpunit.xml; git checkout HEAD -- composer.json composer.lock; composer install --no-interaction --quiet
composer require phpunit/phpunit:10.4.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 install --no-interaction --quiet

vendor: composer.json composer.lock
composer validate --strict
Expand Down
22 changes: 3 additions & 19 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,9 @@
<code><![CDATA[$this->milliseconds * 1000]]></code>
</ArgumentTypeCoercion>
</file>
<file src="test/Unit/DurationTest.php">
<PossiblyUnusedMethod>
<code>provideMillisecondsSecondsAndNanoseconds</code>
</PossiblyUnusedMethod>
</file>
<file src="test/Unit/Formatter/DefaultDurationFormatterTest.php">
<PossiblyUnusedMethod>
<code>provideDurationAndFormattedDuration</code>
</PossiblyUnusedMethod>
</file>
<file src="test/Unit/Reporter/DefaultReporterTest.php">
<PossiblyUnusedMethod>
<code>provideExpectedReportMaximumDurationMaximumCountAndSlowTests</code>
</PossiblyUnusedMethod>
</file>
<file src="test/Unit/TimeTest.php">
<PossiblyUnusedMethod>
<code>provideStartEndAndDuration</code>
<code>provideStartGreaterThanEnd</code>
</PossiblyUnusedMethod>
<MixedInferredReturnType>
<code>iterable</code>
</MixedInferredReturnType>
</file>
</files>
2 changes: 1 addition & 1 deletion src/Reporter/DefaultReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
final class DefaultReporter implements Reporter
{
private readonly Comparator\DurationComparator $durationComparator;
private Comparator\DurationComparator $durationComparator;

public function __construct(
private readonly Formatter\DurationFormatter $durationFormatter,
Expand Down
15 changes: 10 additions & 5 deletions test/Unit/Attribute/MaximumDurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@
use Ergebnis\PHPUnit\SlowTestDetector\Test;
use PHPUnit\Framework;

#[Framework\Attributes\CoversClass(Attribute\MaximumDuration::class)]
#[Framework\Attributes\UsesClass(Duration::class)]
#[Framework\Attributes\UsesClass(Exception\InvalidMilliseconds::class)]
/**
* @covers \Ergebnis\PHPUnit\SlowTestDetector\Attribute\MaximumDuration
*
* @uses \Ergebnis\PHPUnit\SlowTestDetector\Duration
* @uses \Ergebnis\PHPUnit\SlowTestDetector\Exception\InvalidMilliseconds
*/
final class MaximumDurationTest extends Framework\TestCase
{
use Test\Util\Helper;

#[Framework\Attributes\DataProviderExternal(DataProvider\IntProvider::class, 'lessThanZero')]
#[Framework\Attributes\DataProviderExternal(DataProvider\IntProvider::class, 'zero')]
/**
* @dataProvider \Ergebnis\DataProvider\IntProvider::lessThanZero
* @dataProvider \Ergebnis\DataProvider\IntProvider::zero
*/
public function testConstructorRejectsInvalidValue(int $milliseconds): void
{
$this->expectException(Exception\InvalidMilliseconds::class);
Expand Down
11 changes: 7 additions & 4 deletions test/Unit/Collector/DefaultCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
use Ergebnis\PHPUnit\SlowTestDetector\TestIdentifier;
use PHPUnit\Framework;

#[Framework\Attributes\CoversClass(Collector\DefaultCollector::class)]
#[Framework\Attributes\UsesClass(Duration::class)]
#[Framework\Attributes\UsesClass(SlowTest::class)]
#[Framework\Attributes\UsesClass(TestIdentifier::class)]
/**
* @covers \Ergebnis\PHPUnit\SlowTestDetector\Collector\DefaultCollector
*
* @uses \Ergebnis\PHPUnit\SlowTestDetector\Duration
* @uses \Ergebnis\PHPUnit\SlowTestDetector\SlowTest
* @uses \Ergebnis\PHPUnit\SlowTestDetector\TestIdentifier
*/
final class DefaultCollectorTest extends Framework\TestCase
{
use Test\Util\Helper;
Expand Down
7 changes: 5 additions & 2 deletions test/Unit/Comparator/DurationComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
use Ergebnis\PHPUnit\SlowTestDetector\Test;
use PHPUnit\Framework;

#[Framework\Attributes\CoversClass(Comparator\DurationComparator::class)]
#[Framework\Attributes\UsesClass(Duration::class)]
/**
* @covers \Ergebnis\PHPUnit\SlowTestDetector\Comparator\DurationComparator
*
* @uses \Ergebnis\PHPUnit\SlowTestDetector\Duration
*/
final class DurationComparatorTest extends Framework\TestCase
{
use Test\Util\Helper;
Expand Down
10 changes: 7 additions & 3 deletions test/Unit/Console/ColorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@
use Ergebnis\PHPUnit\SlowTestDetector\Test;
use PHPUnit\Framework;

#[Framework\Attributes\CoversClass(Console\Color::class)]
/**
* @covers \Ergebnis\PHPUnit\SlowTestDetector\Console\Color
*/
final class ColorTest extends Framework\TestCase
{
use Test\Util\Helper;

#[Framework\Attributes\DataProviderExternal(DataProvider\StringProvider::class, 'blank')]
#[Framework\Attributes\DataProviderExternal(DataProvider\StringProvider::class, 'empty')]
/**
* @dataProvider \Ergebnis\DataProvider\StringProvider::blank
* @dataProvider \Ergebnis\DataProvider\StringProvider::empty
*/
public function testDimReturnsOriginalStringWhenItIsWhitespaceOnly(string $output): void
{
self::assertSame($output, Console\Color::dim($output));
Expand Down
17 changes: 12 additions & 5 deletions test/Unit/CountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,27 @@
use Ergebnis\PHPUnit\SlowTestDetector\Exception;
use PHPUnit\Framework;

#[Framework\Attributes\CoversClass(Count::class)]
#[Framework\Attributes\UsesClass(Exception\InvalidCount::class)]
/**
* @covers \Ergebnis\PHPUnit\SlowTestDetector\Count
*
* @uses \Ergebnis\PHPUnit\SlowTestDetector\Exception\InvalidCount
*/
final class CountTest extends Framework\TestCase
{
#[Framework\Attributes\DataProviderExternal(DataProvider\IntProvider::class, 'lessThanZero')]
#[Framework\Attributes\DataProviderExternal(DataProvider\IntProvider::class, 'zero')]
/**
* @dataProvider \Ergebnis\DataProvider\IntProvider::lessThanZero
* @dataProvider \Ergebnis\DataProvider\IntProvider::zero
*/
public function testFromIntRejectsInvalidValue(int $value): void
{
$this->expectException(Exception\InvalidCount::class);

Count::fromInt($value);
}

#[Framework\Attributes\DataProviderExternal(DataProvider\IntProvider::class, 'greaterThanZero')]
/**
* @dataProvider \Ergebnis\DataProvider\IntProvider::greaterThanZero
*/
public function testFromIntReturnsCount(int $value): void
{
$count = Count::fromInt($value);
Expand Down
35 changes: 24 additions & 11 deletions test/Unit/DurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@
use Ergebnis\PHPUnit\SlowTestDetector\Test;
use PHPUnit\Framework;

#[Framework\Attributes\CoversClass(Duration::class)]
#[Framework\Attributes\UsesClass(Exception\InvalidMilliseconds::class)]
#[Framework\Attributes\UsesClass(Exception\InvalidNanoseconds::class)]
#[Framework\Attributes\UsesClass(Exception\InvalidSeconds::class)]
/**
* @covers \Ergebnis\PHPUnit\SlowTestDetector\Duration
*
* @uses \Ergebnis\PHPUnit\SlowTestDetector\Exception\InvalidMilliseconds
* @uses \Ergebnis\PHPUnit\SlowTestDetector\Exception\InvalidNanoseconds
* @uses \Ergebnis\PHPUnit\SlowTestDetector\Exception\InvalidSeconds
*/
final class DurationTest extends Framework\TestCase
{
use Test\Util\Helper;

#[Framework\Attributes\DataProviderExternal(DataProvider\IntProvider::class, 'lessThanZero')]
/**
* @dataProvider \Ergebnis\DataProvider\IntProvider::lessThanZero
*/
public function testFromSecondsAndNanosecondsRejectsSecondsLessThanZero(int $seconds): void
{
$nanoseconds = self::faker()->numberBetween(0, 999_999_999);
Expand All @@ -40,7 +45,9 @@ public function testFromSecondsAndNanosecondsRejectsSecondsLessThanZero(int $sec
);
}

#[Framework\Attributes\DataProviderExternal(DataProvider\IntProvider::class, 'lessThanZero')]
/**
* @dataProvider \Ergebnis\DataProvider\IntProvider::lessThanZero
*/
public function testFromSecondsAndNanosecondsRejectsNanosecondsLessThanZero(int $nanoseconds): void
{
$seconds = self::faker()->numberBetween(0, 123);
Expand All @@ -53,7 +60,9 @@ public function testFromSecondsAndNanosecondsRejectsNanosecondsLessThanZero(int
);
}

#[Framework\Attributes\DataProviderExternal(DataProvider\IntProvider::class, 'greaterThanOne')]
/**
* @dataProvider \Ergebnis\DataProvider\IntProvider::greaterThanOne
*/
public function testFromSecondsAndNanosecondsRejectsNanosecondsGreaterThan999999999(int $offset): void
{
$seconds = self::faker()->numberBetween(0, 123);
Expand Down Expand Up @@ -83,16 +92,20 @@ public function testFromSecondsAndNanosecondsReturnsDuration(): void
self::assertSame($nanoseconds, $duration->nanoseconds());
}

#[Framework\Attributes\DataProviderExternal(DataProvider\IntProvider::class, 'lessThanZero')]
#[Framework\Attributes\DataProviderExternal(DataProvider\IntProvider::class, 'zero')]
/**
* @dataProvider \Ergebnis\DataProvider\IntProvider::lessThanZero
* @dataProvider \Ergebnis\DataProvider\IntProvider::zero
*/
public function testFromMillisecondsRejectsInvalidValue(int $milliseconds): void
{
$this->expectException(Exception\InvalidMilliseconds::class);

Duration::fromMilliseconds($milliseconds);
}

#[Framework\Attributes\DataProvider('provideMillisecondsSecondsAndNanoseconds')]
/**
* @dataProvider provideMillisecondsSecondsAndNanoseconds
*/
public function testFromMillisecondsReturnsDuration(
int $milliseconds,
int $seconds,
Expand All @@ -107,7 +120,7 @@ public function testFromMillisecondsReturnsDuration(
/**
* @return \Generator<string, array{0: int, 1: int, 2: int}>
*/
public static function provideMillisecondsSecondsAndNanoseconds(): \Generator
public static function provideMillisecondsSecondsAndNanoseconds(): iterable
{
$values = [
'one' => [
Expand Down
4 changes: 3 additions & 1 deletion test/Unit/Exception/InvalidCountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
use Ergebnis\PHPUnit\SlowTestDetector\Test;
use PHPUnit\Framework;

#[Framework\Attributes\CoversClass(Exception\InvalidCount::class)]
/**
* @covers \Ergebnis\PHPUnit\SlowTestDetector\Exception\InvalidCount
*/
final class InvalidCountTest extends Framework\TestCase
{
use Test\Util\Helper;
Expand Down
4 changes: 3 additions & 1 deletion test/Unit/Exception/InvalidMillisecondsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
use Ergebnis\PHPUnit\SlowTestDetector\Test;
use PHPUnit\Framework;

#[Framework\Attributes\CoversClass(Exception\InvalidMilliseconds::class)]
/**
* @covers \Ergebnis\PHPUnit\SlowTestDetector\Exception\InvalidMilliseconds
*/
final class InvalidMillisecondsTest extends Framework\TestCase
{
use Test\Util\Helper;
Expand Down
4 changes: 3 additions & 1 deletion test/Unit/Exception/InvalidNanosecondsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
use Ergebnis\PHPUnit\SlowTestDetector\Test;
use PHPUnit\Framework;

#[Framework\Attributes\CoversClass(Exception\InvalidNanoseconds::class)]
/**
* @covers \Ergebnis\PHPUnit\SlowTestDetector\Exception\InvalidNanoseconds
*/
final class InvalidNanosecondsTest extends Framework\TestCase
{
use Test\Util\Helper;
Expand Down
4 changes: 3 additions & 1 deletion test/Unit/Exception/InvalidSecondsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
use Ergebnis\PHPUnit\SlowTestDetector\Test;
use PHPUnit\Framework;

#[Framework\Attributes\CoversClass(Exception\InvalidSeconds::class)]
/**
* @covers \Ergebnis\PHPUnit\SlowTestDetector\Exception\InvalidSeconds
*/
final class InvalidSecondsTest extends Framework\TestCase
{
use Test\Util\Helper;
Expand Down
4 changes: 3 additions & 1 deletion test/Unit/Exception/InvalidStartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
use Ergebnis\PHPUnit\SlowTestDetector\Exception;
use PHPUnit\Framework;

#[Framework\Attributes\CoversClass(Exception\InvalidStart::class)]
/**
* @covers \Ergebnis\PHPUnit\SlowTestDetector\Exception\InvalidStart
*/
final class InvalidStartTest extends Framework\TestCase
{
public function testNotLessThanOrEqualToEndReturnsException(): void
Expand Down
4 changes: 3 additions & 1 deletion test/Unit/Exception/InvalidTestIdentifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
use Ergebnis\PHPUnit\SlowTestDetector\Test;
use PHPUnit\Framework;

#[Framework\Attributes\CoversClass(Exception\InvalidTestIdentifier::class)]
/**
* @covers \Ergebnis\PHPUnit\SlowTestDetector\Exception\InvalidTestIdentifier
*/
final class InvalidTestIdentifierTest extends Framework\TestCase
{
use Test\Util\Helper;
Expand Down
13 changes: 9 additions & 4 deletions test/Unit/Formatter/DefaultDurationFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@
use Ergebnis\PHPUnit\SlowTestDetector\Test;
use PHPUnit\Framework;

#[Framework\Attributes\CoversClass(Formatter\DefaultDurationFormatter::class)]
#[Framework\Attributes\UsesClass(Duration::class)]
/**
* @covers \Ergebnis\PHPUnit\SlowTestDetector\Formatter\DefaultDurationFormatter
*
* @uses \Ergebnis\PHPUnit\SlowTestDetector\Duration
*/
final class DefaultDurationFormatterTest extends Framework\TestCase
{
use Test\Util\Helper;

#[Framework\Attributes\DataProvider('provideDurationAndFormattedDuration')]
/**
* @dataProvider provideDurationAndFormattedDuration
*/
public function testFormatFormats(
Duration $duration,
string $formattedDuration,
Expand All @@ -37,7 +42,7 @@ public function testFormatFormats(
/**
* @return \Generator<string, array{0: Duration, 1: string}>
*/
public static function provideDurationAndFormattedDuration(): \Generator
public static function provideDurationAndFormattedDuration(): iterable
{
$values = [
'zero' => [
Expand Down
Loading

0 comments on commit 47dafad

Please sign in to comment.