Symfony

Testing Symfony

PHPUnit, test cases, functional tests, database fixtures, mocking, code coverage, Panther

22 perguntas de entrevistaยท
Mid-Level
1

What is the default testing framework used by Symfony?

Resposta

PHPUnit is the official testing framework integrated into Symfony. Symfony provides the symfony/test-pack package which includes PHPUnit and base classes like WebTestCase and KernelTestCase for easier testing. PHPUnit is the de facto standard for PHP testing and offers a rich ecosystem of assertions and features.

2

Which base class should be used to test a Symfony service without loading the HTTP kernel?

Resposta

KernelTestCase is the base class for integration tests that need access to the service container without loading the HTTP layer. It boots the Symfony kernel and allows access to services via self::getContainer(). It's lighter than WebTestCase as it doesn't initialize the HTTP client.

3

How to access the service container in a test extending KernelTestCase?

Resposta

In Symfony 5.3+, the static method self::getContainer() is the recommended way to access the container after booting the kernel with self::bootKernel(). This method returns a test container that makes all services public for easier testing. The old self::$container syntax is deprecated.

4

Which class should be used to test controllers with HTTP request simulation?

5

How to verify that an HTTP request returns a 200 status code in a functional test?

+19 perguntas de entrevista

Domine Symfony para sua proxima entrevista

Acesse todas as perguntas, flashcards, testes tecnicos, exercicios de code review e simuladores de entrevista.

Comece gratis