53
53
* modules:
54
54
* enabled:
55
55
* - Doctrine2:
56
- * connection_callback: ['MyDb', 'createEntityManager']
57
- * cleanup: true # All doctrine queries will be wrapped in a transaction, which will be rolled back at the end of each test
56
+ * connection_callback: ['MyDb', 'createEntityManager'] # Call the static method `MyDb::createEntityManager()` to get the Entity Manager
58
57
* ```
59
58
*
60
- * This will use static method of `MyDb::createEntityManager()` to establish the Entity Manager.
61
- *
62
59
* By default, the module will wrap everything into a transaction for each test and roll it back afterwards
63
60
* (this is controlled by the `cleanup` setting).
64
61
* By doing this, tests will run much faster and will be isolated from each other.
97
94
* for more flexibility, e.g.:
98
95
*
99
96
* ```php
100
- * $I->seeInRepository(' User' , [
97
+ * $I->seeInRepository(User::class , [
101
98
* 'name' => 'John',
102
99
* Criteria::create()->where(
103
100
* Criteria::expr()->endsWith('email', '@domain.com')
108
105
* If criteria is just a `->where(...)` construct, you can pass just expression without criteria wrapper:
109
106
*
110
107
* ```php
111
- * $I->seeInRepository(' User' , [
108
+ * $I->seeInRepository(User::class , [
112
109
* 'name' => 'John',
113
110
* Criteria::expr()->endsWith('email', '@domain.com'),
114
111
* ]);
@@ -340,7 +337,7 @@ public function clearEntityManager()
340
337
}
341
338
342
339
/**
343
- * This method is deprecated in favor of `haveInRepository()`. It's functionality is exactly the same.
340
+ * This method is deprecated in favor of `haveInRepository()`. Its functionality is exactly the same.
344
341
*/
345
342
public function persistEntity ($ obj , $ values = [])
346
343
{
@@ -359,7 +356,7 @@ public function persistEntity($obj, $values = [])
359
356
* ``` php
360
357
* <?php
361
358
*
362
- * $I->haveFakeRepository('Entity\ User', array( 'findByUsername' => function($username) { return null; }) );
359
+ * $I->haveFakeRepository(User::class, [ 'findByUsername' => function($username) { return null; }] );
363
360
*
364
361
* ```
365
362
*
@@ -445,50 +442,46 @@ public function haveFakeRepository($classname, $methods = [])
445
442
* If the primary key is composite, an array of values is returned.
446
443
*
447
444
* ```php
448
- * $I->haveInRepository('Entity\ User', array( 'name' => 'davert') );
445
+ * $I->haveInRepository(User::class, [ 'name' => 'davert'] );
449
446
* ```
450
447
*
451
448
* This method also accepts instances as first argument, which is useful when the entity constructor
452
449
* has some arguments:
453
450
*
454
451
* ```php
455
- * $I->haveInRepository(new User($arg), array( 'name' => 'davert') );
452
+ * $I->haveInRepository(new User($arg), [ 'name' => 'davert'] );
456
453
* ```
457
454
*
458
455
* Alternatively, constructor arguments can be passed by name. Given User constructor signature is `__constructor($arg)`, the example above could be rewritten like this:
459
456
*
460
457
* ```php
461
- * $I->haveInRepository('Entity\ User', array( 'arg' => $arg, 'name' => 'davert') );
458
+ * $I->haveInRepository(User::class, [ 'arg' => $arg, 'name' => 'davert'] );
462
459
* ```
463
460
*
464
461
* If the entity has relations, they can be populated too. In case of
465
462
* [OneToMany](https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html#one-to-many-bidirectional)
466
463
* the following format is expected:
467
464
*
468
465
* ```php
469
- * $I->haveInRepository('Entity\ User', array(
466
+ * $I->haveInRepository(User::class, [
470
467
* 'name' => 'davert',
471
- * 'posts' => array(
472
- * array(
473
- * 'title' => 'Post 1',
474
- * ),
475
- * array(
476
- * 'title' => 'Post 2',
477
- * ),
478
- * ),
479
- * ));
468
+ * 'posts' => [
469
+ * ['title' => 'Post 1'],
470
+ * ['title' => 'Post 2'],
471
+ * ],
472
+ * ]);
480
473
* ```
481
474
*
482
475
* For [ManyToOne](https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html#many-to-one-unidirectional)
483
476
* the format is slightly different:
484
477
*
485
478
* ```php
486
- * $I->haveInRepository('Entity\ User', array(
479
+ * $I->haveInRepository(User::class, [
487
480
* 'name' => 'davert',
488
- * 'post' => array(
481
+ * 'post' => [
489
482
* 'title' => 'Post 1',
490
- * ) ,
491
- * ) );
483
+ * ] ,
484
+ * ] );
492
485
* ```
493
486
*
494
487
* This works recursively, so you can create deep structures in a single call.
@@ -838,9 +831,9 @@ private function populateEmbeddables($entityObject, array $data)
838
831
*
839
832
* ``` php
840
833
* <?php
841
- * $I->seeInRepository('AppBundle: User', array( 'name' => 'davert') );
842
- * $I->seeInRepository(' User', array( 'name' => 'davert', 'Company' => array( 'name' => 'Codegyre')) );
843
- * $I->seeInRepository(' Client', array( 'User' => array( 'Company' => array( 'name' => 'Codegyre')) );
834
+ * $I->seeInRepository(User::class, [ 'name' => 'davert'] );
835
+ * $I->seeInRepository(User::class, [ 'name' => 'davert', 'Company' => [ 'name' => 'Codegyre']] );
836
+ * $I->seeInRepository(Client::class, [ 'User' => [ 'Company' => [ 'name' => 'Codegyre']]] );
844
837
* ?>
845
838
* ```
846
839
*
@@ -889,7 +882,7 @@ protected function proceedSeeInRepository($entity, $params = [])
889
882
*
890
883
* ``` php
891
884
* <?php
892
- * $email = $I->grabFromRepository(' User' , 'email', array( 'name' => 'davert') );
885
+ * $email = $I->grabFromRepository(User::class , 'email', [ 'name' => 'davert'] );
893
886
* ?>
894
887
* ```
895
888
*
@@ -920,13 +913,13 @@ public function grabFromRepository($entity, $field, $params = [])
920
913
*
921
914
* ``` php
922
915
* <?php
923
- * $users = $I->grabEntitiesFromRepository('AppBundle: User', array( 'name' => 'davert') );
916
+ * $users = $I->grabEntitiesFromRepository(User::class, [ 'name' => 'davert'] );
924
917
* ?>
925
918
* ```
926
919
*
927
920
* @version 1.1
928
921
* @param $entity
929
- * @param array $params. For `IS NULL`, use `array( 'field'=> null) `
922
+ * @param array $params. For `IS NULL`, use `[ 'field' => null] `
930
923
* @return array
931
924
*/
932
925
public function grabEntitiesFromRepository ($ entity , $ params = [])
@@ -951,13 +944,13 @@ public function grabEntitiesFromRepository($entity, $params = [])
951
944
*
952
945
* ``` php
953
946
* <?php
954
- * $user = $I->grabEntityFromRepository(' User', array( 'id' => '1234') );
947
+ * $user = $I->grabEntityFromRepository(User::class, [ 'id' => '1234'] );
955
948
* ?>
956
949
* ```
957
950
*
958
951
* @version 1.1
959
952
* @param $entity
960
- * @param array $params. For `IS NULL`, use `array( 'field'=> null) `
953
+ * @param array $params. For `IS NULL`, use `[ 'field' => null] `
961
954
* @return object
962
955
*/
963
956
public function grabEntityFromRepository ($ entity , $ params = [])
0 commit comments