Pierre de LESPINAY
Pierre de LESPINAY

Reputation: 46188

Application parameter not found in test env

I'm using LiipFunctionalTestBundle with AliceBundle to test my Symfony 3.4 application with fixtures.

Everything is working fine but this specific case: Accessing application parameters from within a fixture loaded from a test in a Liip WebTestCase extension.

Let's consider this setup:

config.yml

parameters:
    img_url: 'http://images.url'

my-fixture.yml

AppBundle\Entity\Item:
    Item-0:
        name: 'First Item'
        image: '<{img_url}>/item0.png'

MyTest.php

use Liip\FunctionalTestBundle\Test\WebTestCase;

class MyTest extends WebTestCase
{
# ...

    public function testMy()
    {
        echo $this->getContainer()->getParameter('img_url');
        $this->loadFixtureFiles(['my-fixture.yml']);
        # ...
    }

Here is the result of the test:

$ phpunit --filter /MyTest::testMy$/
http://images.url
Nelmio\Alice\Throwable\Exception\Generator\Resolver\UnresolvableValueDuringGenerationException:
  Could not resolve value during the generation process
[...]
Nelmio\Alice\Throwable\Exception\Generator\Resolver\UnresolvableValueException:
  Could not find the parameter "img_url"
[...]

However, my fixture can be loaded successfully from the command line:

$ console hautelook:fixtures:load -vv
13:37:42 INFO      [app] fixtures found ["files" => ["my-fixture.yml"]] []
13:37:42 INFO      [app] Purging database with purge mode "DELETE_MODE". [] []
13:37:42 INFO      [app] [...]
13:37:42 INFO      [app] fixtures loaded [] []

Why can't my fixture access the parameter from the test ?
How can I debug that ?

Upvotes: 2

Views: 213

Answers (0)

Related Questions