diff --git a/src/Framework/Attributes/RequiresEnvironmentVariable.php b/src/Framework/Attributes/RequiresEnvironmentVariable.php new file mode 100644 index 0000000000..6defb5338e --- /dev/null +++ b/src/Framework/Attributes/RequiresEnvironmentVariable.php @@ -0,0 +1,40 @@ + + * + * 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; + +/** + * @immutable + * + * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit + */ +#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] +final readonly class RequiresEnvironmentVariable +{ + private string $environmentVariableName; + private null|bool|int|string $value; + + public function __construct(string $environmentVariableName, null|bool|int|string $value = null) + { + $this->environmentVariableName = $environmentVariableName; + $this->value = $value; + } + + public function environmentVariableName(): string + { + return $this->environmentVariableName; + } + + public function value(): null|bool|int|string + { + return $this->value; + } +} diff --git a/src/Metadata/Api/Requirements.php b/src/Metadata/Api/Requirements.php index 96951f6a58..d24ebc954b 100644 --- a/src/Metadata/Api/Requirements.php +++ b/src/Metadata/Api/Requirements.php @@ -14,6 +14,7 @@ use const PHP_VERSION; use function addcslashes; use function array_column; +use function array_key_exists; use function assert; use function extension_loaded; use function function_exists; @@ -24,6 +25,7 @@ use function preg_match; use function sprintf; use PHPUnit\Metadata\Parser\Registry; +use PHPUnit\Metadata\RequiresEnvironmentVariable; use PHPUnit\Metadata\RequiresFunction; use PHPUnit\Metadata\RequiresMethod; use PHPUnit\Metadata\RequiresOperatingSystem; @@ -105,6 +107,24 @@ public function requirementsNotSatisfiedFor(string $className, string $methodNam } } + if ($metadata->isRequiresEnvironmentVariable()) { + assert($metadata instanceof RequiresEnvironmentVariable); + + if (!array_key_exists($metadata->environmentVariableName(), $_ENV)) { + $notSatisfied[] = sprintf('Environment variable "%s" is required.', $metadata->environmentVariableName()); + + continue; + } + + if ($metadata->value() !== null && $_ENV[$metadata->environmentVariableName()] !== $metadata->value()) { + $notSatisfied[] = sprintf( + 'Environment variable "%s" is required to be "%s".', + $metadata->environmentVariableName(), + $metadata->value(), + ); + } + } + if ($metadata->isRequiresOperatingSystemFamily()) { assert($metadata instanceof RequiresOperatingSystemFamily); diff --git a/src/Metadata/Metadata.php b/src/Metadata/Metadata.php index 9570f6557e..9f923948fa 100644 --- a/src/Metadata/Metadata.php +++ b/src/Metadata/Metadata.php @@ -391,6 +391,16 @@ public static function requiresPhpunitExtensionOnMethod(string $extensionClass): return new RequiresPhpunitExtension(self::METHOD_LEVEL, $extensionClass); } + public static function requiresEnvironmentVariableOnClass(string $environmentVariableName, null|int|string $value): RequiresEnvironmentVariable + { + return new RequiresEnvironmentVariable(self::CLASS_LEVEL, $environmentVariableName, $value); + } + + public static function requiresEnvironmentVariableOnMethod(string $environmentVariableName, null|int|string $value): RequiresEnvironmentVariable + { + return new RequiresEnvironmentVariable(self::METHOD_LEVEL, $environmentVariableName, $value); + } + /** * @param non-empty-string $setting * @param non-empty-string $value @@ -816,6 +826,14 @@ public function isRequiresPhpunitExtension(): bool return false; } + /** + * @phpstan-assert-if-true RequiresEnvironmentVariable $this + */ + public function isRequiresEnvironmentVariable(): bool + { + return false; + } + /** * @phpstan-assert-if-true RequiresSetting $this */ diff --git a/src/Metadata/MetadataCollection.php b/src/Metadata/MetadataCollection.php index 2bd8ce9aa5..e9c088973e 100644 --- a/src/Metadata/MetadataCollection.php +++ b/src/Metadata/MetadataCollection.php @@ -483,6 +483,16 @@ public function isRequiresPhpunitExtension(): self ); } + public function isRequiresEnvironmentVariable(): self + { + return new self( + ...array_filter( + $this->metadata, + static fn (Metadata $metadata): bool => $metadata->isRequiresEnvironmentVariable(), + ), + ); + } + public function isRequiresSetting(): self { return new self( diff --git a/src/Metadata/Parser/AttributeParser.php b/src/Metadata/Parser/AttributeParser.php index 3fce3dd31f..f94e30c949 100644 --- a/src/Metadata/Parser/AttributeParser.php +++ b/src/Metadata/Parser/AttributeParser.php @@ -54,6 +54,7 @@ use PHPUnit\Framework\Attributes\PostCondition; use PHPUnit\Framework\Attributes\PreCondition; use PHPUnit\Framework\Attributes\PreserveGlobalState; +use PHPUnit\Framework\Attributes\RequiresEnvironmentVariable; use PHPUnit\Framework\Attributes\RequiresFunction; use PHPUnit\Framework\Attributes\RequiresMethod; use PHPUnit\Framework\Attributes\RequiresOperatingSystem; @@ -315,6 +316,16 @@ public function forClass(string $className): MetadataCollection break; + case RequiresEnvironmentVariable::class: + assert($attributeInstance instanceof RequiresEnvironmentVariable); + + $result[] = Metadata::requiresEnvironmentVariableOnClass( + $attributeInstance->environmentVariableName(), + $attributeInstance->value(), + ); + + break; + case RequiresSetting::class: assert($attributeInstance instanceof RequiresSetting); @@ -691,6 +702,16 @@ public function forMethod(string $className, string $methodName): MetadataCollec break; + case RequiresEnvironmentVariable::class: + assert($attributeInstance instanceof RequiresEnvironmentVariable); + + $result[] = Metadata::requiresEnvironmentVariableOnMethod( + $attributeInstance->environmentVariableName(), + $attributeInstance->value(), + ); + + break; + case RequiresSetting::class: assert($attributeInstance instanceof RequiresSetting); diff --git a/src/Metadata/RequiresEnvironmentVariable.php b/src/Metadata/RequiresEnvironmentVariable.php new file mode 100644 index 0000000000..057b87f9bf --- /dev/null +++ b/src/Metadata/RequiresEnvironmentVariable.php @@ -0,0 +1,44 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Metadata; + +/** + * @immutable + * + * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit + */ +final readonly class RequiresEnvironmentVariable extends Metadata +{ + private string $environmentVariableName; + private null|bool|int|string $value; + + public function __construct(int $level, string $environmentVariableName, null|bool|int|string $value) + { + parent::__construct($level); + + $this->environmentVariableName = $environmentVariableName; + $this->value = $value; + } + + public function isRequiresEnvironmentVariable(): true + { + return true; + } + + public function environmentVariableName(): string + { + return $this->environmentVariableName; + } + + public function value(): null|bool|int|string + { + return $this->value; + } +} diff --git a/tests/_files/Metadata/Attribute/tests/RequiresEnvironmentVariableTest.php b/tests/_files/Metadata/Attribute/tests/RequiresEnvironmentVariableTest.php new file mode 100644 index 0000000000..96fefede96 --- /dev/null +++ b/tests/_files/Metadata/Attribute/tests/RequiresEnvironmentVariableTest.php @@ -0,0 +1,23 @@ + + * + * 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\RequiresEnvironmentVariable; +use PHPUnit\Framework\TestCase; + +#[RequiresEnvironmentVariable('foo', 'bar')] +final class RequiresEnvironmentVariableTest extends TestCase +{ + #[RequiresEnvironmentVariable('foo')] + #[RequiresEnvironmentVariable('bar', 'baz')] + public function testOne(): void + { + } +} diff --git a/tests/_files/RequirementsEnvironmentVariableTest.php b/tests/_files/RequirementsEnvironmentVariableTest.php new file mode 100644 index 0000000000..04ea174108 --- /dev/null +++ b/tests/_files/RequirementsEnvironmentVariableTest.php @@ -0,0 +1,23 @@ + + * + * 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\Attributes\RequiresEnvironmentVariable; +use PHPUnit\Framework\TestCase; + +final class RequirementsEnvironmentVariableTest extends TestCase +{ + #[RequiresEnvironmentVariable('foo', 'bar')] + #[RequiresEnvironmentVariable('baz')] + public function testRequiresEnvironmentVariable(): void + { + } +} diff --git a/tests/unit/Metadata/Api/RequirementsTest.php b/tests/unit/Metadata/Api/RequirementsTest.php index 8f09db9589..4348e230ba 100644 --- a/tests/unit/Metadata/Api/RequirementsTest.php +++ b/tests/unit/Metadata/Api/RequirementsTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\Small; use PHPUnit\Framework\TestCase; +use PHPUnit\TestFixture\RequirementsEnvironmentVariableTest; #[CoversClass(Requirements::class)] #[Small] @@ -130,6 +131,12 @@ public static function missingRequirementsProvider(): array ]; } + protected function tearDown(): void + { + parent::tearDown(); + unset($_ENV['foo']); + } + #[DataProvider('missingRequirementsProvider')] public function testGetMissingRequirements(string $test, array $result): void { @@ -138,4 +145,17 @@ public function testGetMissingRequirements(string $test, array $result): void (new Requirements)->requirementsNotSatisfiedFor(\PHPUnit\TestFixture\RequirementsTest::class, $test), ); } + + public function testGetMissingEnvironmentVariableRequirements(): void + { + $_ENV['foo'] = ''; + + $this->assertEquals( + [ + 'Environment variable "foo" is required to be "bar".', + 'Environment variable "baz" is required.', + ], + (new Requirements)->requirementsNotSatisfiedFor(RequirementsEnvironmentVariableTest::class, 'testRequiresEnvironmentVariable'), + ); + } } diff --git a/tests/unit/Metadata/MetadataCollectionTest.php b/tests/unit/Metadata/MetadataCollectionTest.php index 8f7cd49c7a..88dd15d086 100644 --- a/tests/unit/Metadata/MetadataCollectionTest.php +++ b/tests/unit/Metadata/MetadataCollectionTest.php @@ -48,6 +48,7 @@ #[UsesClass(RequiresPhpExtension::class)] #[UsesClass(RequiresPhpunit::class)] #[UsesClass(RequiresPhpunitExtension::class)] +#[UsesClass(RequiresEnvironmentVariable::class)] #[UsesClass(RequiresSetting::class)] #[UsesClass(RunClassInSeparateProcess::class)] #[UsesClass(RunInSeparateProcess::class)] @@ -402,6 +403,14 @@ public function test_Can_be_filtered_for_RequiresPhpunitExtension(): void $this->assertTrue($collection->asArray()[0]->isRequiresPhpunitExtension()); } + public function test_Can_be_filtered_for_RequiresEnvironmentVariable(): void + { + $collection = $this->collectionWithOneOfEach()->isRequiresEnvironmentVariable(); + + $this->assertCount(1, $collection); + $this->assertTrue($collection->asArray()[0]->isRequiresEnvironmentVariable()); + } + public function test_Can_be_filtered_for_RequiresSetting(): void { $collection = $this->collectionWithOneOfEach()->isRequiresSetting(); @@ -553,6 +562,7 @@ private function collectionWithOneOfEach(): MetadataCollection ), ), Metadata::requiresPhpunitExtensionOnClass(stdClass::class), + Metadata::requiresEnvironmentVariableOnClass('foo', 'bar'), Metadata::requiresSettingOnClass('foo', 'bar'), Metadata::runClassInSeparateProcess(), Metadata::runInSeparateProcess(), diff --git a/tests/unit/Metadata/MetadataTest.php b/tests/unit/Metadata/MetadataTest.php index 7d08545a81..c79c286d44 100644 --- a/tests/unit/Metadata/MetadataTest.php +++ b/tests/unit/Metadata/MetadataTest.php @@ -51,6 +51,7 @@ #[CoversClass(RequiresPhpExtension::class)] #[CoversClass(RequiresPhpunit::class)] #[CoversClass(RequiresPhpunitExtension::class)] +#[CoversClass(RequiresEnvironmentVariable::class)] #[CoversClass(RequiresSetting::class)] #[CoversClass(RunClassInSeparateProcess::class)] #[CoversClass(RunInSeparateProcess::class)] @@ -108,7 +109,7 @@ public function testCanBeAfter(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); - $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -164,6 +165,7 @@ public function testCanBeAfterClass(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -219,6 +221,7 @@ public function testCanBeBackupGlobalsOnClass(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -275,6 +278,7 @@ public function testCanBeBackupGlobalsOnMethod(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -331,6 +335,7 @@ public function testCanBeBackupStaticPropertiesOnClass(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -387,6 +392,7 @@ public function testCanBeBackupStaticPropertiesOnMethod(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -443,6 +449,7 @@ public function testCanBeBeforeClass(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -498,6 +505,7 @@ public function testCanBeBefore(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -553,6 +561,7 @@ public function testCanBeCoversClass(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -611,6 +620,7 @@ public function testCanBeCoversClassesThatExtendClass(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -668,6 +678,7 @@ public function testCanBeCoversClassesThatImplementInterface(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -724,6 +735,7 @@ public function testCanBeCoversFunction(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -782,6 +794,7 @@ public function testCanBeCoversMethod(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -841,6 +854,7 @@ public function testCanBeCoversNothingOnMethod(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -896,6 +910,7 @@ public function testCanBeCoversNothingOnClass(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -951,6 +966,7 @@ public function testCanBeDataProvider(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -1009,6 +1025,7 @@ public function testCanBeDependsOnClass(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -1068,6 +1085,7 @@ public function testCanBeDependsOnMethod(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -1128,6 +1146,7 @@ public function testCanBeDisableReturnValueGenerationForTestDoubles(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -1183,6 +1202,7 @@ public function testCanBeDoesNotPerformAssertionsOnClass(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -1238,6 +1258,7 @@ public function testCanBeDoesNotPerformAssertionsOnMethod(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -1293,6 +1314,7 @@ public function testCanBeExcludeGlobalVariableFromBackupOnClass(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -1349,6 +1371,7 @@ public function testCanBeExcludeGlobalVariableFromBackupOnMethod(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -1405,6 +1428,7 @@ public function testCanBeExcludeStaticPropertyFromBackupOnClass(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -1463,6 +1487,7 @@ public function testCanBeExcludeStaticPropertyFromBackupOnMethod(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -1521,6 +1546,7 @@ public function testCanBeGroupOnClass(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -1578,6 +1604,7 @@ public function testCanBeIgnoreDeprecationsOnClass(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -1633,6 +1660,7 @@ public function testCanBeIgnoreDeprecationsOnMethod(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -1688,6 +1716,7 @@ public function testCanBeIgnorePhpunitDeprecationsOnClass(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -1743,6 +1772,7 @@ public function testCanBeIgnorePhpunitDeprecationsOnMethod(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -1798,6 +1828,7 @@ public function testCanBeGroupOnMethod(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -1855,6 +1886,7 @@ public function testCanBeRunTestsInSeparateProcesses(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -1910,6 +1942,7 @@ public function testCanBeRunClassInSeparateProcess(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -1965,6 +1998,7 @@ public function testCanBeRunInSeparateProcess(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -2020,6 +2054,7 @@ public function testCanBeTest(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -2075,6 +2110,7 @@ public function testCanBePreCondition(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -2130,6 +2166,7 @@ public function testCanBePostCondition(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -2182,6 +2219,7 @@ public function testCanBePreserveGlobalStateOnClass(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -2236,6 +2274,7 @@ public function testCanBePreserveGlobalStateOnMethod(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -2293,6 +2332,7 @@ public function testCanBeRequiresMethodOnClass(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -2351,6 +2391,7 @@ public function testCanBeRequiresMethodOnMethod(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -2409,6 +2450,7 @@ public function testCanBeRequiresFunctionOnClass(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -2466,6 +2508,7 @@ public function testCanBeRequiresFunctionOnMethod(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -2523,6 +2566,7 @@ public function testCanBeRequiresOperatingSystemOnClass(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -2580,6 +2624,7 @@ public function testCanBeRequiresOperatingSystemOnMethod(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -2637,6 +2682,7 @@ public function testCanBeRequiresOperatingSystemFamilyOnClass(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -2694,6 +2740,7 @@ public function testCanBeRequiresOperatingSystemFamilyOnMethod(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -2756,6 +2803,7 @@ public function testCanBeRequiresPhpOnClass(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -2818,6 +2866,7 @@ public function testCanBeRequiresPhpOnMethod(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -2875,6 +2924,7 @@ public function testCanBeRequiresPhpExtensionOnClass(): void $this->assertTrue($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -2942,6 +2992,7 @@ public function testCanBeRequiresPhpExtensionWithVersionOnClass(): void $this->assertTrue($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -3001,6 +3052,7 @@ public function testCanBeRequiresPhpExtensionOnMethod(): void $this->assertTrue($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -3068,6 +3120,7 @@ public function testCanBeRequiresPhpExtensionWithVersionOnMethod(): void $this->assertTrue($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -3132,6 +3185,7 @@ public function testCanBeRequiresPhpunitOnClass(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertTrue($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -3189,6 +3243,7 @@ public function testCanBeRequiresPhpunitExtensionOnClass(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertTrue($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -3251,6 +3306,7 @@ public function testCanBeRequiresPhpunitOnMethod(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertTrue($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -3308,6 +3364,7 @@ public function testCanBeRequiresPhpunitExtensionOnMethod(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertTrue($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -3324,6 +3381,124 @@ public function testCanBeRequiresPhpunitExtensionOnMethod(): void $this->assertFalse($metadata->isClassLevel()); } + public function testCanBeRequiresEnvironmentVariableOnMethod(): void + { + $metadata = Metadata::requiresEnvironmentVariableOnMethod('foo', 'bar'); + + $this->assertFalse($metadata->isAfter()); + $this->assertFalse($metadata->isAfterClass()); + $this->assertFalse($metadata->isBackupGlobals()); + $this->assertFalse($metadata->isBackupStaticProperties()); + $this->assertFalse($metadata->isBeforeClass()); + $this->assertFalse($metadata->isBefore()); + $this->assertFalse($metadata->isCoversClass()); + $this->assertFalse($metadata->isCoversClassesThatExtendClass()); + $this->assertFalse($metadata->isCoversClassesThatImplementInterface()); + $this->assertFalse($metadata->isCoversFunction()); + $this->assertFalse($metadata->isCoversMethod()); + $this->assertFalse($metadata->isCoversNothing()); + $this->assertFalse($metadata->isDataProvider()); + $this->assertFalse($metadata->isDependsOnClass()); + $this->assertFalse($metadata->isDependsOnMethod()); + $this->assertFalse($metadata->isDisableReturnValueGenerationForTestDoubles()); + $this->assertFalse($metadata->isDoesNotPerformAssertions()); + $this->assertFalse($metadata->isExcludeGlobalVariableFromBackup()); + $this->assertFalse($metadata->isExcludeStaticPropertyFromBackup()); + $this->assertFalse($metadata->isGroup()); + $this->assertFalse($metadata->isIgnoreDeprecations()); + $this->assertFalse($metadata->isIgnorePhpunitDeprecations()); + $this->assertFalse($metadata->isRunClassInSeparateProcess()); + $this->assertFalse($metadata->isRunInSeparateProcess()); + $this->assertFalse($metadata->isRunTestsInSeparateProcesses()); + $this->assertFalse($metadata->isTest()); + $this->assertFalse($metadata->isPreCondition()); + $this->assertFalse($metadata->isPostCondition()); + $this->assertFalse($metadata->isPreserveGlobalState()); + $this->assertFalse($metadata->isRequiresMethod()); + $this->assertFalse($metadata->isRequiresFunction()); + $this->assertFalse($metadata->isRequiresOperatingSystem()); + $this->assertFalse($metadata->isRequiresOperatingSystemFamily()); + $this->assertFalse($metadata->isRequiresPhp()); + $this->assertFalse($metadata->isRequiresPhpExtension()); + $this->assertFalse($metadata->isRequiresPhpunit()); + $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertTrue($metadata->isRequiresEnvironmentVariable()); + $this->assertFalse($metadata->isRequiresSetting()); + $this->assertFalse($metadata->isTestDox()); + $this->assertFalse($metadata->isTestWith()); + $this->assertFalse($metadata->isUsesClass()); + $this->assertFalse($metadata->isUsesClassesThatExtendClass()); + $this->assertFalse($metadata->isUsesClassesThatImplementInterface()); + $this->assertFalse($metadata->isUsesFunction()); + $this->assertFalse($metadata->isUsesMethod()); + $this->assertFalse($metadata->isWithoutErrorHandler()); + + $this->assertSame('foo', $metadata->environmentVariableName()); + $this->assertSame('bar', $metadata->value()); + + $this->assertTrue($metadata->isMethodLevel()); + $this->assertFalse($metadata->isClassLevel()); + } + + public function testCanBeRequiresEnvironmentVariableOnClass(): void + { + $metadata = Metadata::requiresEnvironmentVariableOnClass('foo', 'bar'); + + $this->assertFalse($metadata->isAfter()); + $this->assertFalse($metadata->isAfterClass()); + $this->assertFalse($metadata->isBackupGlobals()); + $this->assertFalse($metadata->isBackupStaticProperties()); + $this->assertFalse($metadata->isBeforeClass()); + $this->assertFalse($metadata->isBefore()); + $this->assertFalse($metadata->isCoversClass()); + $this->assertFalse($metadata->isCoversClassesThatExtendClass()); + $this->assertFalse($metadata->isCoversClassesThatImplementInterface()); + $this->assertFalse($metadata->isCoversFunction()); + $this->assertFalse($metadata->isCoversMethod()); + $this->assertFalse($metadata->isCoversNothing()); + $this->assertFalse($metadata->isDataProvider()); + $this->assertFalse($metadata->isDependsOnClass()); + $this->assertFalse($metadata->isDependsOnMethod()); + $this->assertFalse($metadata->isDisableReturnValueGenerationForTestDoubles()); + $this->assertFalse($metadata->isDoesNotPerformAssertions()); + $this->assertFalse($metadata->isExcludeGlobalVariableFromBackup()); + $this->assertFalse($metadata->isExcludeStaticPropertyFromBackup()); + $this->assertFalse($metadata->isGroup()); + $this->assertFalse($metadata->isIgnoreDeprecations()); + $this->assertFalse($metadata->isIgnorePhpunitDeprecations()); + $this->assertFalse($metadata->isRunClassInSeparateProcess()); + $this->assertFalse($metadata->isRunInSeparateProcess()); + $this->assertFalse($metadata->isRunTestsInSeparateProcesses()); + $this->assertFalse($metadata->isTest()); + $this->assertFalse($metadata->isPreCondition()); + $this->assertFalse($metadata->isPostCondition()); + $this->assertFalse($metadata->isPreserveGlobalState()); + $this->assertFalse($metadata->isRequiresMethod()); + $this->assertFalse($metadata->isRequiresFunction()); + $this->assertFalse($metadata->isRequiresOperatingSystem()); + $this->assertFalse($metadata->isRequiresOperatingSystemFamily()); + $this->assertFalse($metadata->isRequiresPhp()); + $this->assertFalse($metadata->isRequiresPhpExtension()); + $this->assertFalse($metadata->isRequiresPhpunit()); + $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertTrue($metadata->isRequiresEnvironmentVariable()); + $this->assertFalse($metadata->isRequiresSetting()); + $this->assertFalse($metadata->isTestDox()); + $this->assertFalse($metadata->isTestWith()); + $this->assertFalse($metadata->isUsesClass()); + $this->assertFalse($metadata->isUsesClassesThatExtendClass()); + $this->assertFalse($metadata->isUsesClassesThatImplementInterface()); + $this->assertFalse($metadata->isUsesFunction()); + $this->assertFalse($metadata->isUsesMethod()); + $this->assertFalse($metadata->isWithoutErrorHandler()); + + $this->assertSame('foo', $metadata->environmentVariableName()); + $this->assertSame('bar', $metadata->value()); + + $this->assertFalse($metadata->isMethodLevel()); + $this->assertTrue($metadata->isClassLevel()); + } + public function testCanBeRequiresSettingOnClass(): void { $metadata = Metadata::requiresSettingOnClass('foo', 'bar'); @@ -3365,6 +3540,7 @@ public function testCanBeRequiresSettingOnClass(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertTrue($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -3423,6 +3599,7 @@ public function testCanBeRequiresSettingOnMethod(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertTrue($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -3481,6 +3658,7 @@ public function testCanBeTestDoxOnClass(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertTrue($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -3538,6 +3716,7 @@ public function testCanBeTestDoxOnMethod(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertTrue($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -3595,6 +3774,7 @@ public function testCanBeTestWith(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertTrue($metadata->isTestWith()); @@ -3654,6 +3834,7 @@ public function testCanBeUsesClass(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -3712,6 +3893,7 @@ public function testCanBeUsesClassesThatExtendClass(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -3769,6 +3951,7 @@ public function testCanBeUsesClassesThatImplementInterface(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -3826,6 +4009,7 @@ public function testCanBeUsesFunction(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -3883,6 +4067,7 @@ public function testCanBeUsesMethod(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); @@ -3942,6 +4127,7 @@ public function testCanBeWithoutErrorHandler(): void $this->assertFalse($metadata->isRequiresPhpExtension()); $this->assertFalse($metadata->isRequiresPhpunit()); $this->assertFalse($metadata->isRequiresPhpunitExtension()); + $this->assertFalse($metadata->isRequiresEnvironmentVariable()); $this->assertFalse($metadata->isRequiresSetting()); $this->assertFalse($metadata->isTestDox()); $this->assertFalse($metadata->isTestWith()); diff --git a/tests/unit/Metadata/Parser/AttributeParserTest.php b/tests/unit/Metadata/Parser/AttributeParserTest.php index ab4d3e03a1..1d279e53db 100644 --- a/tests/unit/Metadata/Parser/AttributeParserTest.php +++ b/tests/unit/Metadata/Parser/AttributeParserTest.php @@ -39,6 +39,7 @@ use PHPUnit\Framework\Attributes\PostCondition; use PHPUnit\Framework\Attributes\PreCondition; use PHPUnit\Framework\Attributes\PreserveGlobalState; +use PHPUnit\Framework\Attributes\RequiresEnvironmentVariable; use PHPUnit\Framework\Attributes\RequiresFunction; use PHPUnit\Framework\Attributes\RequiresMethod; use PHPUnit\Framework\Attributes\RequiresOperatingSystem; @@ -103,6 +104,7 @@ #[CoversClass(RequiresPhp::class)] #[CoversClass(RequiresPhpunit::class)] #[CoversClass(RequiresPhpunitExtension::class)] +#[CoversClass(RequiresEnvironmentVariable::class)] #[CoversClass(RequiresSetting::class)] #[CoversClass(RunClassInSeparateProcess::class)] #[CoversClass(RunInSeparateProcess::class)] diff --git a/tests/unit/Metadata/Parser/AttributeParserTestCase.php b/tests/unit/Metadata/Parser/AttributeParserTestCase.php index 3c351fd2ca..dac8a12763 100644 --- a/tests/unit/Metadata/Parser/AttributeParserTestCase.php +++ b/tests/unit/Metadata/Parser/AttributeParserTestCase.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; use PHPUnit\Metadata\DependsOnClass; use PHPUnit\Metadata\DependsOnMethod; +use PHPUnit\Metadata\RequiresEnvironmentVariable; use PHPUnit\Metadata\RequiresPhp; use PHPUnit\Metadata\RequiresPhpExtension; use PHPUnit\Metadata\RequiresPhpunit; @@ -40,6 +41,7 @@ use PHPUnit\TestFixture\Metadata\Attribute\PhpunitAttributeThatDoesNotExistTest; use PHPUnit\TestFixture\Metadata\Attribute\PreserveGlobalStateTest; use PHPUnit\TestFixture\Metadata\Attribute\ProcessIsolationTest; +use PHPUnit\TestFixture\Metadata\Attribute\RequiresEnvironmentVariableTest; use PHPUnit\TestFixture\Metadata\Attribute\RequiresFunctionTest; use PHPUnit\TestFixture\Metadata\Attribute\RequiresMethodTest; use PHPUnit\TestFixture\Metadata\Attribute\RequiresOperatingSystemFamilyTest; @@ -343,6 +345,23 @@ public function test_parses_RequiresPhpunitExtension_attribute_on_class(): void $this->assertSame('PHPUnit\TestFixture\Metadata\Attribute\SomeExtension', $requirement->extensionClass()); } + #[TestDox('Parses #[RequiresEnvironmentVariable] attribute on class')] + public function test_parses_RequiresEnvironmentVariable_attribute_on_class(): void + { + $metadata = $this->parser()->forClass(RequiresEnvironmentVariableTest::class)->isRequiresEnvironmentVariable(); + + $this->assertCount(1, $metadata); + + $requirement = $metadata->asArray()[0]; + + $this->assertTrue($requirement->isRequiresEnvironmentVariable()); + + assert($requirement instanceof RequiresEnvironmentVariable); + + $this->assertSame('foo', $requirement->environmentVariableName()); + $this->assertSame('bar', $requirement->value()); + } + #[TestDox('Parses #[RequiresSetting] attribute on class')] public function test_parses_RequiresSetting_attribute_on_class(): void { @@ -923,6 +942,26 @@ public function test_parses_RequiresPhpunitExtension_attribute_on_method(): void $this->assertSame('PHPUnit\TestFixture\Metadata\Attribute\SomeOtherExtension', $requirement->extensionClass()); } + #[TestDox('Parses #[RequiresEnvironmentVariable] attribute on method')] + public function test_parses_RequiresEnvironmentVariable_attribute_on_method(): void + { + $metadata = $this->parser()->forMethod(RequiresEnvironmentVariableTest::class, 'testOne')->isRequiresEnvironmentVariable(); + + $this->assertCount(2, $metadata); + + $requirement = $metadata->asArray()[0]; + $this->assertTrue($requirement->isRequiresEnvironmentVariable()); + assert($requirement instanceof RequiresEnvironmentVariable); + $this->assertSame('foo', $requirement->environmentVariableName()); + $this->assertNull($requirement->value()); + + $requirement = $metadata->asArray()[1]; + $this->assertTrue($requirement->isRequiresEnvironmentVariable()); + assert($requirement instanceof RequiresEnvironmentVariable); + $this->assertSame('bar', $requirement->environmentVariableName()); + $this->assertSame('baz', $requirement->value()); + } + #[TestDox('Parses #[RequiresSetting] attribute on method')] public function test_parses_RequiresSetting_attribute_on_method(): void {