Skip to content

Commit

Permalink
Move to Attributes (#831)
Browse files Browse the repository at this point in the history
  • Loading branch information
Slamdunk authored Jan 8, 2024
1 parent 52b2aec commit 8bfded5
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 26 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@
"phpunit/php-timer": "^6.0",
"phpunit/phpunit": "^10.5.5",
"sebastian/environment": "^6.0.1",
"symfony/console": "^6.3.4 || ^7.0.0",
"symfony/process": "^6.3.4 || ^7.0.0"
"symfony/console": "^6.4.2 || ^7.0.2",
"symfony/process": "^6.4.2 || ^7.0.2"
},
"require-dev": {
"ext-pcov": "*",
"ext-posix": "*",
"doctrine/coding-standard": "^12.0.0",
"infection/infection": "^0.27.9",
"phpstan/phpstan": "^1.10.54",
"phpstan/phpstan": "^1.10.55",
"phpstan/phpstan-deprecation-rules": "^1.1.4",
"phpstan/phpstan-phpunit": "^1.3.15",
"phpstan/phpstan-strict-rules": "^1.5.2",
"squizlabs/php_codesniffer": "^3.8.0",
"symfony/filesystem": "^6.3.1 || ^7.0.0"
"symfony/filesystem": "^6.4.0 || ^7.0.0"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/Util/PhpstormHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Generator;
use ParaTest\Util\PhpstormHelper;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use RuntimeException;

Expand All @@ -31,9 +32,8 @@ public function testThrowExceptionWithInvalidArgv(): void
/**
* @param array<int, string> $argv
* @param array<int, string> $expectedArgv
*
* @dataProvider providePhpstormCases
*/
#[DataProvider('providePhpstormCases')]
public function testPhpStormHelper(
array $argv,
array $expectedArgv,
Expand Down
21 changes: 13 additions & 8 deletions test/Unit/WrapperRunner/WrapperRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
use ParaTest\WrapperRunner\WrapperWorker;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\RequiresOperatingSystemFamily;
use PHPUnit\Framework\Attributes\RequiresPhp;
use PHPUnit\Framework\Attributes\RequiresPhpunit;
use SebastianBergmann\CodeCoverage\CodeCoverage;
use Symfony\Component\Process\Process;

Expand Down Expand Up @@ -57,7 +61,7 @@ final class WrapperRunnerTest extends TestBase

public const PASSTHRU_PHP_CUSTOM = 'PASSTHRU_PHP_CUSTOM';

/** @dataProvider provideForWrapperRunnerHandlesBatchSize */
#[DataProvider('provideForWrapperRunnerHandlesBatchSize')]
public function testWrapperRunnerHandlesBatchSize(int $processes, ?int $batchSize, int $expectedPidCount): void
{
$this->bareOptions['--no-configuration'] = true;
Expand Down Expand Up @@ -118,7 +122,7 @@ private function extractContentFromDirFiles(string $path): array
return array_unique($res);
}

/** @group github */
#[Group('github')]
#[CoversNothing]
public function testReadPhpunitConfigPhpSectionBeforeLoadingTheSuite(): void
{
Expand Down Expand Up @@ -177,7 +181,7 @@ public function testRunnerSortNoSeedProvided(): void
self::assertStringContainsString('Random Seed:', $runnerResult->output);
}

/** @group github */
#[Group('github')]
#[CoversNothing]
public function testErrorsInDataProviderAreHandled(): void
{
Expand Down Expand Up @@ -227,7 +231,7 @@ public function testPassthrus(): void
self::assertSame(RunnerInterface::SUCCESS_EXIT, $runnerResult->exitCode);
}

/** @group github */
#[Group('github')]
#[CoversNothing]
public function testReadPhpunitConfigPhpSectionBeforeLoadingTheSuiteManualBootstrap(): void
{
Expand Down Expand Up @@ -267,7 +271,7 @@ public function testExitCodesPathWithoutTests(): void
self::assertSame(RunnerInterface::SUCCESS_EXIT, $runnerResult->exitCode);
}

/** @requires OSFAMILY Linux */
#[RequiresOperatingSystemFamily('Linux')]
public function testTeamcityLogHandlesFifoFiles(): void
{
$outputPath = $this->tmpDir . DIRECTORY_SEPARATOR . 'test-output.teamcity';
Expand Down Expand Up @@ -433,7 +437,7 @@ public function testRunnerReversed(): void
self::assertSame($defaultOrder, $reverseOrderReversed);
}

/** @group github */
#[Group('github')]
#[CoversNothing]
public function testTokensAreAbsentWhenNoTestTokensIsSpecified(): void
{
Expand Down Expand Up @@ -518,8 +522,9 @@ public function testHandleCollisionWithSymfonyOutput(): void
self::assertStringContainsString('<bg=%s>', $runnerResult->output);
}

/** @group github */
#[Group('github')]
#[CoversNothing]
#[RequiresPhpunit('10')]
public function testIgnoreAttributes(): void
{
$this->bareOptions['--configuration'] = $this->fixture('github' . DIRECTORY_SEPARATOR . 'GH756' . DIRECTORY_SEPARATOR . 'phpunit.xml');
Expand Down Expand Up @@ -580,7 +585,7 @@ public function testHandleUnexpectedOutput(): void
self::assertStringMatchesFormat($expectedOutput, $runnerResult->output);
}

/** @group github */
#[Group('github')]
#[CoversNothing]
public function testGroupOptionWithDataProviderAndCodeCoverageEnabled(): void
{
Expand Down
5 changes: 2 additions & 3 deletions test/fixtures/fatal_tests/UnitTestWithFatalParseErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@

namespace ParaTest\Tests\fixtures\fatal_tests;

use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;

/**
* @runParallel
*/
final class UnitTestWithFatalParseErrorTest extends TestCase
{
/**
* @group fixtures
*/
#[Group('fixtures')]
public function testTruth(): void
{
I will fail fataly because this is not a php statement .
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace ParaTest\Tests\fixtures\function_parallelization_tests;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

/** @internal */
Expand All @@ -29,13 +30,13 @@ public static function dataProvider2(): array
];
}

/** @dataProvider dataProvider1 */
#[DataProvider('dataProvider1')]
public function testDataProvider1(string $a, string $b): void
{
self::assertEquals($a, $b);
}

/** @dataProvider dataProvider2 */
#[DataProvider('dataProvider2')]
public function testDataProvider2(string $a, string $b): void
{
self::assertEquals($a, $b);
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/github/GH420/IssueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace ParaTest\Tests\fixtures\github\GH420;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

use function defined;
Expand All @@ -12,7 +13,7 @@
/** @internal */
final class IssueTest extends TestCase
{
/** @dataProvider provideCases */
#[DataProvider('provideCases')]
public function testCases(bool $true): void
{
self::assertTrue($true);
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/github/GH420bis/IssueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

namespace ParaTest\Tests\fixtures\github\GH420bis;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

use function defined;

/** @internal */
final class IssueTest extends TestCase
{
/** @dataProvider provideCases */
#[DataProvider('provideCases')]
public function testCases(string $constant): void
{
self::assertStringContainsString('ISSUE_420_BIS_', $constant);
Expand Down
7 changes: 4 additions & 3 deletions test/fixtures/github/GH565/IssueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
namespace ParaTest\Tests\fixtures\github\GH565;

use LogicException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

/** @internal */
final class IssueTest extends TestCase
{
/** @dataProvider provideIncomplete */
#[DataProvider('provideIncomplete')]
public function testIncompleteByDataProvider(): void
{
}
Expand All @@ -20,7 +21,7 @@ public static function provideIncomplete(): void
self::markTestIncomplete('foo');
}

/** @dataProvider provideSkipped */
#[DataProvider('provideSkipped')]
public function testSkippedByDataProvider(): void
{
}
Expand All @@ -30,7 +31,7 @@ public static function provideSkipped(): void
self::markTestSkipped('bar');
}

/** @dataProvider provideError */
#[DataProvider('provideError')]
public function testErrorByDataProvider(): void
{
}
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/paratest_only_tests/EnvironmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace ParaTest\Tests\fixtures\paratest_only_tests;

use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;

use function getenv;
Expand All @@ -12,7 +13,7 @@
/** @internal */
final class EnvironmentTest extends TestCase
{
/** @group fixtures */
#[Group('fixtures')]
public function testParatestVariableIsDefined(): void
{
$this->assertEquals(1, getenv('PARATEST'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace ParaTest\Tests\fixtures\special_chars;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

use function array_map;
Expand All @@ -12,7 +13,7 @@

final class UnitTestWithDataProviderSpecialCharsTest extends TestCase
{
/** @dataProvider provideSpecialChars */
#[DataProvider('provideSpecialChars')]
public function testIsItFalse(string $specialChar): void
{
self::assertFalse($specialChar, (string) ord($specialChar));
Expand Down

0 comments on commit 8bfded5

Please sign in to comment.