Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

WebTestCase always carries Parameters from previous test case #20024

Copy link
Copy link
Closed
@stampycode

Description

@stampycode
Issue body actions

Just recreated this on Symfony 3.1, also occurs on 2.7.

When a WebTestCase is run, any subsequent iterations of running that WebTestCase will have the same parameters set, even if the parameters.php config file is using different values from previous test cases.

I have narrowed the problem as I see it, down to the instance of appTestDebugProjectContainer.php which has an old set of parameters, but I can't see where it's retrieved them from. I suspect a rogue static var being used somewhere, perhaps in a Reflection class or similar.

Reproduction:

Create a new Symfony 3.1 project, and modify the following files:

app/config/config.yml

imports:
    - { resource: parameters.yml }
    - { resource: parameters.php } <-- add this line

app/config/parameters.yml append to the end of the file

    test_param: hello

app/config/parameters.php

<?php

echo "SETTING PARAM " . getenv('TEST_PARAM') ."\n";
$container->setParameter('test_param', getenv('TEST_PARAM'));

tests/AppBundle/EnvResetTest.php

<?php
namespace AppBundle;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class EnvResetTest extends WebTestCase
{
    public function setUp()
    {
        `rm -rf var/cache/*`;
        `rm -rf var/sessions/*`;
        `php bin/console cache:warmup --env=test`;
    }
    public function testConfigSettingPart1()
    {
        echo "TEST ONE..\n";
        putenv('TEST_PARAM=testone');
        $param = static::createClient()->getKernel()->getContainer()->getParameter('test_param');
        echo $this->getActualOutput();
        $this->assertEquals('testone', $param); //passes
    }
    public function testConfigSettingPart2()
    {
        echo "TEST TWO..\n";
        //no env, should use default value of "hello"
        $param = static::createClient()->getKernel()->getContainer()->getParameter('test_param');
        echo $this->getActualOutput();
        $this->assertEquals('hello', $param); //fails
    }
    public function testConfigSettingPart3()
    {
        echo "TEST THREE..\n";
        putenv('TEST_PARAM=testthree');
        $param = static::createClient()->getKernel()->getContainer()->getParameter('test_param');
        echo $this->getActualOutput();
        $this->assertEquals('testthree', $param); //fails
    }
}

The outcome varies depending on whether you enable the line php bin/console cache:warmup --env=test in the test setUp method, but only one of the tests will ever pass, regardless of this.
Test1 passes if the line is disabled, Test2 passes if the line is enabled. The other tests will fail.

This proves the parameter values are carried from one execution to the next, despite proving that the parameters.php file being executed for each test.

It feels like this shouldn't happen, I haven't seen any documentation to suggest this behaviour should be expected... If there is a workaround I can use in the meantime, like for resetting some statically cached parameters somewhere, that would be very much appreciated.

This is the last hurdle to overcome in order for my webTestCase scripts to enable testing of my application in different configurations, from a single test suite.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.