Skip to main content
Version: 2026.1

Testing Symfony Services

When writing integration tests for Symfony services, you can retrieve them directly from the Symfony container regardless of whether they are public or private.

The symfony default way is described here and can be used in context within Pimcore too.

In combination with codeception, where is the codeception symfony module that provides additional functionality as also grabbing services from the container.

Currently, we are not using the codeception symfony module though, to reduce test complexity and due to lack of compatibility with symfony 6.

To still have the grab service functionality available, just use the Pimcore\Tests\Support\Helper\Pimcore module and call grabService as below:

use Pimcore\Tests\Support\Helper\Pimcore;

/** @var Pimcore $pimcoreModule */
$pimcoreModule = $this->getModule('\\' . Pimcore::class);
$mailerService = $pimcoreModule->grabService('mailer');