-
- Notifications
You must be signed in to change notification settings - Fork 2.2k
#[RequiresEnvironmentVariable] #6074
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| <?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; | ||
| | ||
| /** | ||
| * @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; | ||
| Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Environment variable can be strictly only string. What is the meaning of Can I test environment variable presence/absence /wo specific value? Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on https://github.com/sebastianbergmann/phpunit/pull/6074/files#diff-8f0e8d461aea381bf08d49440fbc5da892d38eb782518cd44bfe1dddce7638f4R119 it seems Contributor Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
you can only test environment variable presence or with a specific value
this was more or less my concern here. I'm also wondering if we should only check the env var in Contributor Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any thoughts @sebastianbergmann? I can provide a patch to my PR Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Please test the behaviour with E2E test and some tests in separate process. The separate process must see the same environment variables in both linux and Windows. Owner There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough. Contributor Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you think in the case of "no value", I check if the env var exist, or should I check it is ok-ish? empty string and Contributor Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my opinion:
Contributor Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yeah, good point | ||
| | ||
| 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; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| <?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; | ||
| | ||
| /** | ||
| * @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; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?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\RequiresEnvironmentVariable; | ||
| use PHPUnit\Framework\TestCase; | ||
| | ||
| #[RequiresEnvironmentVariable('foo', 'bar')] | ||
| final class RequiresEnvironmentVariableTest extends TestCase | ||
| { | ||
| #[RequiresEnvironmentVariable('foo')] | ||
| #[RequiresEnvironmentVariable('bar', 'baz')] | ||
| public function testOne(): void | ||
| { | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?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\Attributes\RequiresEnvironmentVariable; | ||
| use PHPUnit\Framework\TestCase; | ||
| | ||
| final class RequirementsEnvironmentVariableTest extends TestCase | ||
| { | ||
| #[RequiresEnvironmentVariable('foo', 'bar')] | ||
| #[RequiresEnvironmentVariable('baz')] | ||
| public function testRequiresEnvironmentVariable(): void | ||
| { | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.