Run the following command in your project directory to install the bundle as a development dependency:
composer require --dev macpaw/behat-orm-contextIf you are using Symfony Flex, the bundle will be registered automatically. Otherwise, follow Step 2 to register the bundle manually.
If your project does not use Symfony Flex or the bundle does not provide a recipe, manually register it in config/bundles.php:
<?php
// config/bundles.php
return [
// ...
BehatOrmContext\BehatOrmContextBundle::class => ['test' => true],
];ℹ️ The bundle should only be enabled in the
testenvironment.
Add the ORM context to your behat.yml:
default:
suites:
default:
contexts:
- BehatOrmContext\Context\ORMContextBy default, ORMContext uses the doctrine.orm.entity_manager service.
To override this and inject a custom Doctrine ObjectManager (which implements Doctrine\ORM\EntityManagerInterface),
update your service configuration in config/services.yaml under the test environment:
when@test:
services:
BehatOrmContext\Context\ORMContext:
arguments:
$manager: '@doctrine.orm.other_entity_manager'This allows you to swap the ObjectManager used by the context without modifying the class itself.