Symfony

Testing Symfony

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

22 คำถามสัมภาษณ์·
Mid-Level
1

What is the default testing framework used by Symfony?

คำตอบ

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?

คำตอบ

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?

คำตอบ

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 คำถามสัมภาษณ์

เชี่ยวชาญ Symfony สำหรับการสัมภาษณ์ครั้งถัดไป

เข้าถึงคำถามทั้งหมด flashcards แบบทดสอบเทคนิค แบบฝึกหัด code review และตัวจำลองสัมภาษณ์

เริ่มใช้ฟรี