2e86c939
xu
“首次提交”
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
# Doctrine2
Access the database using [Doctrine2 ORM](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/).
When used with Zend Framework 2 or Symfony2, Doctrine's Entity Manager is automatically retrieved from Service Locator.
Set up your `functional.suite.yml` like this:
```
modules:
enabled:
- Symfony # 'ZF2' or 'Symfony'
- Doctrine2:
depends: Symfony
cleanup: true # All doctrine queries will be wrapped in a transaction, which will be rolled back at the end of each test
```
If you don't use Symfony or Zend Framework, you need to specify a callback function to retrieve the Entity Manager:
```
modules:
enabled:
- Doctrine2:
connection_callback: ['MyDb', 'createEntityManager']
cleanup: true # All doctrine queries will be wrapped in a transaction, which will be rolled back at the end of each test
```
This will use static method of `MyDb::createEntityManager()` to establish the Entity Manager.
By default, the module will wrap everything into a transaction for each test and roll it back afterwards. By doing this
tests will run much faster and will be isolated from each other.
## Status
* Maintainer: **davert**
* Stability: **stable**
* Contact: codecept@davert.mail.ua
## Config
## Public Properties
* `em` - Entity Manager
## Actions
### dontSeeInRepository
Flushes changes to database and performs `findOneBy()` call for current repository.
* `param` $entity
* `param array` $params
### flushToDatabase
Performs $em->flush();
### grabEntitiesFromRepository
Selects entities from repository.
It builds query based on array of parameters.
You can use entity associations to build complex queries.
Example:
``` php
<?php
$users = $I->grabEntitiesFromRepository('AppBundle:User', array('name' => 'davert'));
?>
```
* `Available since` 1.1
* `param` $entity
* `param array` $params
* `return` array
### grabEntityFromRepository
Selects a single entity from repository.
It builds query based on array of parameters.
You can use entity associations to build complex queries.
Example:
``` php
<?php
$user = $I->grabEntityFromRepository('User', array('id' => '1234'));
?>
```
* `Available since` 1.1
* `param` $entity
* `param array` $params
* `return` object
### grabFromRepository
Selects field value from repository.
It builds query based on array of parameters.
You can use entity associations to build complex queries.
Example:
``` php
<?php
$email = $I->grabFromRepository('User', 'email', array('name' => 'davert'));
?>
```
* `Available since` 1.1
* `param` $entity
* `param` $field
* `param array` $params
* `return` array
### haveFakeRepository
Mocks the repository.
With this action you can redefine any method of any repository.
Please, note: this fake repositories will be accessible through entity manager till the end of test.
Example:
``` php
<?php
$I->haveFakeRepository('Entity\User', array('findByUsername' => function($username) { return null; }));
```
This creates a stub class for Entity\User repository with redefined method findByUsername,
which will always return the NULL value.
* `param` $classname
* `param array` $methods
### haveInRepository
Persists record into repository.
This method crates an entity, and sets its properties directly (via reflection).
Setters of entity won't be executed, but you can create almost any entity and save it to database.
Returns id using `getId` of newly created entity.
```php
$I->haveInRepository('Entity\User', array('name' => 'davert'));
```
### persistEntity
Adds entity to repository and flushes. You can redefine it's properties with the second parameter.
Example:
``` php
<?php
$I->persistEntity(new \Entity\User, array('name' => 'Miles'));
$I->persistEntity($user, array('name' => 'Miles'));
```
* `param` $obj
* `param array` $values
### seeInRepository
Flushes changes to database, and executes a query with parameters defined in an array.
You can use entity associations to build complex queries.
Example:
``` php
<?php
$I->seeInRepository('AppBundle:User', array('name' => 'davert'));
$I->seeInRepository('User', array('name' => 'davert', 'Company' => array('name' => 'Codegyre')));
$I->seeInRepository('Client', array('User' => array('Company' => array('name' => 'Codegyre')));
?>
```
Fails if record for given criteria can\'t be found,
* `param` $entity
* `param array` $params
<p> </p><div class="alert alert-warning">Module reference is taken from the source code. <a href="https://github.com/Codeception/Codeception/tree/2.3/src/Codeception/Module/Doctrine2.php">Help us to improve documentation. Edit module reference</a></div>
|