Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DI] Add tests for EnvVarProcessor #26542

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

Closed
wants to merge 2 commits into from

Conversation

mcfedr
Copy link
Contributor

@mcfedr mcfedr commented Mar 15, 2018

Q A
Branch? 3.4
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR n/a

Add tests for the EnvVarProcessor as it doesn't have any at the moment.

Originally from this PR against master, #26498

$processor = new EnvVarProcessor($container);

$result = $processor->getEnv('string', 'foo', function () {
throw new LogicException('Shouldnt be called');
Copy link
Member

Choose a reason for hiding this comment

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

Minor typo: Shouldnt -> Shouldn\'t or Should not

Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we use $this->fail() instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, I couldn't remember what the function was called, I knew it existed

return '1';
});

$this->assertTrue($result);
Copy link
Member

Choose a reason for hiding this comment

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

Just asking: assertTrue() accepts as true anything that PHP considers true ... or does it a strict true === ... comparison? We're getting a bool value here, so we need to be sure that a boolean is returned.

Copy link
Member

Choose a reason for hiding this comment

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

use Symfony\Component\DependencyInjection\EnvVarProcessor;
use Symfony\Component\DependencyInjection\Exception\LogicException;

class EnvVarProcessorTest extends TestCase
Copy link
Member

Choose a reason for hiding this comment

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

Just asking: should we add a data provider with some edge cases to better test this feature? Empty strings, null values, zeros, etc. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree completely, updated with far more examples for each case

Copy link
Member

@derrabus derrabus left a comment

Choose a reason for hiding this comment

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

For base64 and json, I'd suggest to add test cases with badly encoded strings.

$processor = new EnvVarProcessor($container);

$result = $processor->getEnv('string', 'foo', function () {
throw new LogicException('Shouldnt be called');
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we use $this->fail() instead?

$processor->getEnv('const', 'foo', function ($name) {
$this->assertSame('foo', $name);

return 'Symfony\Component\DependencyInjection\Tests\EnvVarProcessorTest::TEST_CONST_OTHER';
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest to use a name here that tells the reader that you've been using an undefined constant by design here, e.g. TEST_CONST_INVALID or TEST_CONST_UNDEFINED.

@mcfedr mcfedr force-pushed the env_var_processor_tests branch from a907f07 to 90bc19f Compare March 16, 2018 13:13
@mcfedr
Copy link
Contributor Author

mcfedr commented Mar 16, 2018

@derrabus Checking for badly encoded base64 is an option, but actually the current EnvVarProcessor just ignores bad base64, and this would be a breaking change, I have pushed a commit (90bc19f) that checks this, but as it would be break backwards compatibility, its probably not a good idea.

@mcfedr mcfedr force-pushed the env_var_processor_tests branch from 90bc19f to 532c579 Compare March 16, 2018 13:16
array(1),
array(1.1),
array(true),
array(false),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I left out null as it would conflict with my other PR, #26498

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or should I better include it here and update in second PR assuming this gets merged first?

@derrabus
Copy link
Member

@mcfedr I wasn't aware of the current behavior of the base64 decoder. I agree that this PR should not change the behavior. We could tackle this with a later PR, maybe.

@mcfedr
Copy link
Contributor Author

mcfedr commented Mar 16, 2018

@derrabus I guess its one of PHPs fun features, where its just trying to be helpful...

@mcfedr mcfedr force-pushed the env_var_processor_tests branch from 532c579 to 8e735b7 Compare March 19, 2018 10:41
@nicolas-grekas nicolas-grekas changed the title Add tests for EnvVarProcessor [DI] Add tests for EnvVarProcessor Mar 19, 2018
@nicolas-grekas
Copy link
Member

Thank you @mcfedr.

nicolas-grekas added a commit that referenced this pull request Mar 19, 2018
This PR was squashed before being merged into the 3.4 branch (closes #26542).

Discussion
----------

[DI] Add tests for EnvVarProcessor

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        | n/a

Add tests for the `EnvVarProcessor` as it doesn't have any at the moment.

Originally from this PR against master, #26498

Commits
-------

2992bb3 [DI] Add tests for EnvVarProcessor
@mcfedr mcfedr deleted the env_var_processor_tests branch March 19, 2018 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants