Warning: You are browsing the documentation from version 4 to 10 of Pimcore. Please visit https://pimcore.com/docs/platform/ for the latest versions of Pimcore.
Version: Edit on GitHub

Testing Symfony Services

For integration tests of symfony services in context of their configuration in container, there are multiple ways for retrieving them directly from the symfony container (regardless if there 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\Helper\Pimcore module and call grabService as below:

use Pimcore\Tests\Helper\Pimcore;

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