-
-
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.
Handle invalid version requirements in annotations by ignoring them a…
…nd emitting a warning instead of crashing
- Loading branch information
1 parent
f251c09
commit 3ce3114
Showing
5 changed files
with
135 additions
and
14 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
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,26 @@ | ||
<?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; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @requires PHP ~~9.0 | ||
*/ | ||
final class InvalidRequirementsTest extends TestCase | ||
{ | ||
/** | ||
* @requires PHP ~~9.0 | ||
*/ | ||
public function testInvalidVersionConstraint(): void | ||
{ | ||
$this->assertTrue(true); | ||
} | ||
} |
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,28 @@ | ||
--TEST-- | ||
phpunit --no-configuration ../_files/InvalidRequirementsTest.php | ||
--FILE-- | ||
<?php declare(strict_types=1); | ||
require_once(__DIR__ . '/../../bootstrap.php'); | ||
|
||
$_SERVER['argv'][] = '--do-not-cache-result'; | ||
$_SERVER['argv'][] = '--no-configuration'; | ||
$_SERVER['argv'][] = \realpath(__DIR__ . '/../../_files/InvalidRequirementsTest.php'); | ||
|
||
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']); | ||
--EXPECTF-- | ||
PHPUnit %s by Sebastian Bergmann and contributors. | ||
|
||
Runtime: %s | ||
|
||
. 1 / 1 (100%) | ||
|
||
Time: %s, Memory: %s | ||
|
||
There were 2 PHPUnit test runner warnings: | ||
|
||
1) Method PHPUnit\TestFixture\InvalidRequirementsTest::testInvalidVersionConstraint is annotated using an invalid version requirement: Version constraint ~~9.0 is not supported. | ||
|
||
2) Class PHPUnit\TestFixture\InvalidRequirementsTest is annotated using an invalid version requirement: Version constraint ~~9.0 is not supported. | ||
|
||
WARNINGS! | ||
Tests: 1, Assertions: 1, Warnings: 2. |
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,41 @@ | ||
<?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\Annotation; | ||
|
||
use Exception; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\Group; | ||
use PHPUnit\Framework\Attributes\Small; | ||
use PHPUnit\Framework\TestCase; | ||
use PHPUnit\Metadata\Annotation\Parser\DocBlock; | ||
use PHPUnit\Metadata\AnnotationsAreNotSupportedForInternalClassesException; | ||
use ReflectionClass; | ||
use ReflectionMethod; | ||
|
||
#[CoversClass(DocBlock::class)] | ||
#[Small] | ||
#[Group('metadata')] | ||
#[Group('metadata/annotations')] | ||
final class DocBlockTest extends TestCase | ||
{ | ||
public function testDoesNotSupportInternalClasses(): void | ||
{ | ||
$this->expectException(AnnotationsAreNotSupportedForInternalClassesException::class); | ||
|
||
DocBlock::ofClass(new ReflectionClass(Exception::class)); | ||
} | ||
|
||
public function testDoesNotSupportInternalMethods(): void | ||
{ | ||
$this->expectException(AnnotationsAreNotSupportedForInternalClassesException::class); | ||
|
||
DocBlock::ofMethod(new ReflectionMethod(Exception::class, 'getMessage')); | ||
} | ||
} |