@@ -59,16 +59,16 @@ easy to pass a mock object within a test::
59
59
->method('getBonus')
60
60
->will($this->returnValue(1100));
61
61
62
- // Now, mock tthe repository so it returns the mock of the employee
62
+ // Now, mock the repository so it returns the mock of the employee
63
63
$employeeRepository = $this->getMockBuilder('\Doctrine\ORM\EntityRepository')
64
64
->disableOriginalConstructor()
65
65
->getMock();
66
66
$employeeRepository->expects($this->once())
67
- ->method('__call ')
67
+ ->method('find ')
68
68
->will($this->returnValue($employee));
69
69
70
70
// Last, mock the EntityManager to return the mock of the repository
71
- $entityManager = $this->getMockBuilder('\Doctrine\ORM\EntityManager ')
71
+ $entityManager = $this->getMockBuilder('\Doctrine\Common\Persistence\ObjectManager ')
72
72
->disableOriginalConstructor()
73
73
->getMock();
74
74
$entityManager->expects($this->once())
@@ -83,14 +83,6 @@ easy to pass a mock object within a test::
83
83
We are building our mocks from the inside out, first creating the employee which
84
84
gets returned by the ``Repository `` which itself gets returned by the ``EntityManager ``.
85
85
This way, no real class is involved in testing.
86
-
87
- .. note ::
88
-
89
- As a ``Repository `` doesn't have a ``find() `` method but uses the magic method
90
- ``__call ``, you cannot define a mock method on ``find() `` but must instead use
91
- ``__call ``. It's possible to implement the ``find() `` method in your ``Repository ``
92
- and use it when mocking. In this case, make sure to mock your ``Repository ``
93
- class instead of the generic ``EntityRepository ``.
94
86
95
87
Changing database settings for functional tests
96
88
-----------------------------------------------
@@ -100,15 +92,43 @@ Most of the time you want to use a dedicated database connection to make sure
100
92
not to overwrite data you entered when developing the application and also
101
93
to be able to clear the database before every test.
102
94
103
- To do this, you can specify the database configuration inside your ``app/config/config_test.yml ``::
95
+ To do this, you can specify a database configuration which overwrites the default
96
+ configuration:
104
97
98
+ .. code-block :: yaml
99
+
100
+ # app/config/config_test.yml
105
101
doctrine :
102
+ # ...
106
103
dbal :
107
104
host : localhost
108
105
dbname : testdb
109
106
user : testdb
110
107
password : testdb
111
108
112
- Make sure that your database runs on localhost and has the defined database and
113
- user credentials set up.
109
+ .. code-block :: xml
114
110
111
+ <!-- app/config/config_test.xml -->
112
+ <doctrine : config >
113
+ <doctrine : dbal
114
+ host =" localhost"
115
+ dbname =" testdb"
116
+ user =" testdb"
117
+ password =" testdb"
118
+ >
119
+ </doctrine : config >
120
+
121
+ .. code-block :: php
122
+
123
+ // app/config/config_test.php
124
+ $configuration->loadFromExtension('doctrine', array(
125
+ 'dbal' => array(
126
+ 'host' => 'localhost',
127
+ 'dbname' => 'testdb',
128
+ 'user' => 'testdb',
129
+ 'password' => 'testdb',
130
+ ),
131
+ ));
132
+
133
+ Make sure that your database runs on localhost and has the defined database and
134
+ user credentials set up.
0 commit comments