Category: phpunit

Symfony, WebTestCase case, crashes because of a service not used in a test

I’m writing Symfony 4.3 phpunit funcional tests. And When I try to to launch the tests I get this error message: SymfonyComponentDependencyInjectionExceptionRuntimeException: Cannot autowire service “fixtures class”: argument “$encoder” of method “__construct()” references interface “SymfonyComponentSecurityCoreEncoderUserPasswordEncoderInterface” but no such service exists….

How to change locale in Symfony5 / PHPUnit before calling request?

I need to change locale in my functional test: <?php namespace AppTestsController; use SymfonyBundleFrameworkBundleTestWebTestCase; class TranslationControllerTest extends WebTestCase { public function testIndex() { $client = static::createClient(); $client->request(‘GET’, ‘/translation.js’); $client->getRequest()->setLocale(‘en’); $content = $client->getResponse()->getContent(); $trans = json_decode(substr($content, strpos($content, “‘{“) + 1, strpos($content,…

Mocking custom constraints in test where the constraints are used

I have a class that injects symfony’s validator (and other services) and then uses that validator with some custom constraints. These custom constraints have their own dependencies, including accessing the DB through Repository classes. I have successfully mocked the construction…