8000 Add default env vars for PHPUnit by fabpot · Pull Request #170 · symfony/recipes · GitHub
[go: up one dir, main page]

Skip to content

Add default env vars for PHPUnit #170

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

Merged
merged 1 commit into from
Sep 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion phpunit/phpunit/4.7/phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
>
<php>
<ini name="error_reporting" value="-1" />
<server name="KERNEL_CLASS" value="App\Kernel" />
<env name="KERNEL_CLASS" value="App\Kernel" />
Copy link
Member

Choose a reason for hiding this comment

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

Why using env here when we just started checking $_SERVER (see e.g. #156)?

Copy link
Member

Choose a reason for hiding this comment

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

because it's the correct concept, and maps to the .env file
_SERVER mixes several sources, so it's confusing

Copy link
Member

Choose a reason for hiding this comment

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

But the difference if I don't miss anything is that PHPUnit unline the Dotenv component does not populate the $_SERVER array with this config.

For example, take this config:

    <php>
        <server name="foo" value="bar" />
        <env name="foobar" value="baz" />
    </php>

It ends up with this output:

(
    [DOCUMENT_ROOT] => 
    [PATH_TRANSLATED] => ./phpunit
    [PHP_SELF] => ./phpunit
    [PWD] => /Users/christian/symfony
    [REQUEST_TIME] => 1504717866
    [REQUEST_TIME_FLOAT] => 1504717866.6028
    [SCRIPT_FILENAME] => ./phpunit
    [SCRIPT_NAME] => ./phpunit
    [TMPDIR] => /var/folders/9_/wkjkz_ms2hn7rkr4vm4b68t00000gn/T/
    [USER] => christian
    [_] => ./phpunit
    [argc] => 3
    [argv] => Array
        (
            [0] => ./phpunit
            [1] => --colors=always
            [2] => src/Symfony/Component/Filesystem/
        )

    [foo] => bar
)
Array
(
    [foobar] => baz
)

Produced by:

ksort($_SERVER);
print_r($_SERVER);
ksort($_ENV);
print_r($_ENV);

Copy link
Member

Choose a reason for hiding this comment

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

That's stupid :)
Anyway, since getenv('foo') returns only from <env>, I think we have no choice but use it.

Copy link
Member
@yceruto yceruto Sep 6, 2017

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

@yceruto good catch, can you send a PR to fix this? it should work!

Copy link
Member

Choose a reason for hiding this comment

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

Not sure what I should fix here? you mean check both vars $_SERVER and $_ENV in KernelTestCase?

Copy link
Member

Choose a reason for hiding this comment

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

yes, that's what I mean

<env name="APP_ENV" value="test" />
<env name="APP_DEBUG" value="1" />
<env name="APP_SECRET" value="s$cretf0rt3st" />
<!-- define your env variables for the test env here -->
</php>

<testsuites>
Expand Down
6 changes: 5 additions & 1 deletion symfony/phpunit-bridge/3.3/phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
>
<php>
<ini name="error_reporting" value="-1" />
<server name="KERNEL_CLASS" value="App\Kernel" />
<env name="KERNEL_CLASS" value="App\Kernel" />
<env name="APP_ENV" value="test" />
<env name="APP_DEBUG" value="1" />
<env name="APP_SECRET" value="s$cretf0rt3st" />
<!-- define your env variables for the test env here -->
</php>

<testsuites>
Expand Down
0