A
A
Alexey Dabalaev2020-11-01 19:19:08
symfony
Alexey Dabalaev, 2020-11-01 19:19:08

How to get configs from services.yaml in tests?

Hello.
Symfony is not my profile )), but it is necessary.

It got stuck and I can't reach the /config/services.yaml configs to use parameters in unit tests.
And there are a kiloton of docks, and I don’t understand what I need to use.

Please tell me how to check it to make it work.

class MyTest extends WebTestCase
{
    private array $params;

    // так работать не будет
    public function __construct(ParameterBagInterface $params, $name = null, array $data = [], $dataName = '')
    {
        parent::__construct($name, $data, $dataName);

        $this->params = $params->get('my_config');;
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daria Motorina, 2020-11-02
@AleksDab

There are two points in the task:
1) it is not clear whether you configured the
Symfony dock environment to run under test and a note about setting up environments
2) The parameters can be accessed through the container

$client = self::createClient();
    $normalContainer = $client->getContainer();
    $param = $normalContainer->getParameter('param_name');

or by doing autowiring (describe in services.yaml the parameter injection into the class constructor, but it seems that this number does not pass with tests)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question