Skip to content
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

#[RequiresEnvironmentVariable] #6074

Merged

Conversation

nikophil
Copy link
Contributor

@nikophil nikophil commented Dec 8, 2024

Implements #6065

Copy link

codecov bot commented Dec 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.59%. Comparing base (8c85f60) to head (7263676).
Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #6074      +/-   ##
============================================
+ Coverage     94.57%   94.59%   +0.01%     
- Complexity     6615     6632      +17     
============================================
  Files           707      709       +2     
  Lines         20809    20862      +53     
============================================
+ Hits          19681    19734      +53     
  Misses         1128     1128              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sebastianbergmann sebastianbergmann changed the title feat: #[RequiresEnvironmentVariable] #[RequiresEnvironmentVariable] Dec 9, 2024
@sebastianbergmann sebastianbergmann added type/enhancement A new idea that should be implemented feature/test-runner CLI test runner feature/metadata/attributes labels Dec 9, 2024
@sebastianbergmann sebastianbergmann added this to the PHPUnit 12.0 milestone Dec 9, 2024
@sebastianbergmann sebastianbergmann merged commit d35e14f into sebastianbergmann:main Dec 9, 2024
25 checks passed
final readonly class RequiresEnvironmentVariable
{
private string $environmentVariableName;
private null|bool|int|string $value;
Copy link
Contributor

@mvorisek mvorisek Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Environment variable can be strictly only string.

What is the meaning of null, bool, int?

Can I test environment variable presence/absence /wo specific value?

Copy link
Contributor

@mvorisek mvorisek Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I test environment variable presence/absence /wo specific value?

you can only test environment variable presence or with a specific value

it seems bool and int should be removed and as never possible

this was more or less my concern here. I'm also wondering if we should only check the env var in $_ENV , or use getenv() or check at least one of them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any thoughts @sebastianbergmann? I can provide a patch to my PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was more or less my concern here. I'm also wondering if we should only check the env var in $_ENV , or use getenv() or check at least one of them

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.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 '0' would not pass

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion:

  • If an environment variable is tested for a presence (/wo value defined in the Attribute), I would expect '0' to be consideted as set.

  • For binary '1'/'0' detection I would expect user to write #[RequiresEnvironmentVariable('foo', '1')] explicitly.

  • '' should be considered as unset as in many operating systems FOO= unsets the variable. Also, in CI parametrization/matrix empty value might be set, but with "no variable" meaning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'' should be considered as unset as in many operating systems FOO= unsets the variable

yeah, good point

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/metadata/attributes feature/test-runner CLI test runner type/enhancement A new idea that should be implemented
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants