|
1 | 1 | # Installation |
2 | 2 |
|
3 | | -## Step 1: Download the Bundle |
| 3 | +## Step 1: Install the Bundle |
4 | 4 |
|
5 | | -Open a command console, enter your project directory and execute: |
6 | | - |
7 | | -### Applications that use Symfony Flex |
| 5 | +Run the following command in your project directory to install the bundle as a development dependency: |
8 | 6 |
|
9 | 7 | ```bash |
10 | 8 | composer require --dev macpaw/behat-orm-context |
11 | | -``` |
12 | | - |
13 | | -### Applications that don't use Symfony Flex |
| 9 | +```` |
14 | 10 |
|
15 | | -Open a command console, enter your project directory and execute the following command to download the latest stable |
16 | | -version of this bundle: |
17 | | - |
18 | | -```bash |
19 | | - composer require --dev macpaw/behat-orm-context |
20 | | -``` |
| 11 | +> If you are using Symfony Flex, the bundle will be registered automatically. |
| 12 | +> Otherwise, follow Step 2 to register the bundle manually. |
21 | 13 |
|
22 | | -This command requires you to have Composer installed globally, as explained |
23 | | -in the [installation chapter](https://getcomposer.org/doc/00-intro.md) |
24 | | -of the Composer documentation. |
| 14 | +## Step 2: Register the Bundle |
25 | 15 |
|
26 | | -Then, enable the bundle by adding it to the list of registered bundles |
27 | | -in the `app/AppKernel.php` file of your project: |
| 16 | +If your project does **not** use Symfony Flex or the bundle does not provide a recipe, manually register it in `config/bundles.php`: |
28 | 17 |
|
29 | 18 | ```php |
30 | 19 | <?php |
31 | | -// app/AppKernel.php |
32 | | - |
33 | | -// ... |
34 | | -class AppKernel extends Kernel |
35 | | -{ |
36 | | - public function registerBundles() |
37 | | - { |
38 | | - $bundles = array( |
39 | | - // ... |
40 | | - BehatOrmContext\BehatOrmContextBundle::class => ['test' => true], |
41 | | - ); |
42 | | - |
43 | | - // ... |
44 | | - } |
| 20 | +// config/bundles.php |
45 | 21 |
|
| 22 | +return [ |
46 | 23 | // ... |
47 | | -} |
| 24 | + BehatOrmContext\BehatOrmContextBundle::class => ['test' => true], |
| 25 | +]; |
48 | 26 | ``` |
49 | 27 |
|
50 | | -## Step 2: Configure Behat |
| 28 | +> ℹ️ The bundle should only be enabled in the `test` environment. |
| 29 | + |
| 30 | +## Step 3: Configure Behat |
51 | 31 |
|
52 | | -Go to `behat.yml`: |
| 32 | +Add the ORM context to your `behat.yml`: |
53 | 33 |
|
54 | 34 | ```yaml |
55 | | -# ... |
56 | | -contexts: |
57 | | - - BehatOrmContext\Context\OrmContext |
58 | | -# ... |
| 35 | +default: |
| 36 | + suites: |
| 37 | + default: |
| 38 | + contexts: |
| 39 | + - BehatOrmContext\Context\ORMContext |
59 | 40 | ``` |
60 | 41 |
|
61 | | -## Configuration |
| 42 | +## Step 4 (Optional): Inject a Custom ObjectManager |
62 | 43 |
|
63 | | -By default, the bundle has the following configuration: |
| 44 | +By default, `ORMContext` uses the `doctrine.orm.entity_manager` service. |
| 45 | +To override this and inject a custom Doctrine ObjectManager (which implements `Doctrine\ORM\EntityManagerInterface`), |
| 46 | +update your service configuration in `config/services.yaml` under the `test` environment: |
64 | 47 |
|
65 | 48 | ```yaml |
66 | | -behat_orm_context: |
67 | | - # Currently no specific configuration options are available |
| 49 | +when@test: |
| 50 | + services: |
| 51 | + BehatOrmContext\Context\ORMContext: |
| 52 | + arguments: |
| 53 | + $manager: '@doctrine.orm.other_entity_manager' |
68 | 54 | ``` |
69 | 55 |
|
70 | | -You can override it manually in your `config/packages/test/behat_orm_context.yaml`. |
| 56 | +This allows you to swap the ObjectManager used by the context without modifying the class itself. |
0 commit comments