-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#[RequiresPhpunitExtension] attribute
- Loading branch information
Showing
12 changed files
with
431 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of PHPUnit. | ||
* | ||
* (c) Sebastian Bergmann <sebastian@phpunit.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace PHPUnit\Framework\Attributes; | ||
|
||
use Attribute; | ||
use PHPUnit\Runner\Extension\Extension; | ||
|
||
/** | ||
* @immutable | ||
* | ||
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit | ||
*/ | ||
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)] | ||
final readonly class RequiresPhpunitExtension | ||
{ | ||
/** | ||
* @var list<class-string<Extension>> | ||
*/ | ||
private array $extensionClasses; | ||
|
||
/** | ||
* @param class-string<Extension> $extensionClasses | ||
*/ | ||
public function __construct(string ...$extensionClasses) | ||
{ | ||
$this->extensionClasses = $extensionClasses; | ||
} | ||
|
||
/** | ||
* @return list<class-string<Extension>> | ||
*/ | ||
public function extensionClasses(): array | ||
{ | ||
return $this->extensionClasses; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of PHPUnit. | ||
* | ||
* (c) Sebastian Bergmann <sebastian@phpunit.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace PHPUnit\Metadata; | ||
|
||
use PHPUnit\Runner\Extension\Extension; | ||
|
||
/** | ||
* @immutable | ||
* | ||
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit | ||
*/ | ||
final readonly class RequiresPhpunitExtension extends Metadata | ||
{ | ||
/** | ||
* @var list<class-string<Extension>> | ||
*/ | ||
private array $extensionClasses; | ||
|
||
/** | ||
* @param class-string<Extension> $extensionClasses | ||
*/ | ||
public function __construct(int $level, string ...$extensionClasses) | ||
{ | ||
parent::__construct($level); | ||
|
||
$this->extensionClasses = $extensionClasses; | ||
} | ||
|
||
public function isRequiresPhpunitExtension(): true | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* @return list<class-string<Extension>> | ||
*/ | ||
public function extensionClasses(): array | ||
{ | ||
return $this->extensionClasses; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
tests/_files/Metadata/Attribute/tests/RequiresPhpunitExtensionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of PHPUnit. | ||
* | ||
* (c) Sebastian Bergmann <sebastian@phpunit.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace PHPUnit\TestFixture\Metadata\Attribute; | ||
|
||
use PHPUnit\Framework\Attributes\RequiresPhpunitExtension; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[RequiresPhpunitExtension(SomeClass::class)] | ||
final class RequiresPhpunitExtensionTest extends TestCase | ||
{ | ||
#[RequiresPhpunitExtension(SomeClass::class, SomeOtherClass::class)] | ||
public function testOne(): void | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.