Skip to content

Commit 18dd720

Browse files
authored
Merge pull request #68 from ThomasLandauer/patch-2
Recommending against `grab()` methods for Symfony users
2 parents be8228d + 3c414e3 commit 18dd720

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/Codeception/Module/Doctrine2.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,24 @@
8888
* purge_mode: 1 # 1: DELETE (=default), 2: TRUNCATE
8989
* ```
9090
*
91+
* ## Grabbing Entities with Symfony
92+
*
93+
* For Symfony users, the recommended way to query for entities is not to use this module's `grab...()` methods, but rather
94+
* "inject" Doctrine's repository:
95+
*
96+
* ```php
97+
* public function _before(FunctionalTester $I): void
98+
* {
99+
* $this->fooRepository = $I->grabService(FooRepository::class);
100+
* }
101+
* ```
102+
*
103+
* Now you have access to all your familiar repository methods in your tests, e.g.:
104+
*
105+
* ```php
106+
* $greenFoo = $this->fooRepository->findOneBy(['color' => 'green']);
107+
* ```
108+
*
91109
* ## Public Properties
92110
*
93111
* * `em` - Entity Manager

0 commit comments

Comments
 (0)