Skip to content

Commit 00d24fa

Browse files
committed
Making some minor bugfixes to the testing/database cookbook. Added different code examples
1 parent 2823a40 commit 00d24fa

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

cookbook/testing/database.rst

+34-14
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,16 @@ easy to pass a mock object within a test::
5959
->method('getBonus')
6060
->will($this->returnValue(1100));
6161
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
6363
$employeeRepository = $this->getMockBuilder('\Doctrine\ORM\EntityRepository')
6464
->disableOriginalConstructor()
6565
->getMock();
6666
$employeeRepository->expects($this->once())
67-
->method('__call')
67+
->method('find')
6868
->will($this->returnValue($employee));
6969
7070
// 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')
7272
->disableOriginalConstructor()
7373
->getMock();
7474
$entityManager->expects($this->once())
@@ -83,14 +83,6 @@ easy to pass a mock object within a test::
8383
We are building our mocks from the inside out, first creating the employee which
8484
gets returned by the ``Repository`` which itself gets returned by the ``EntityManager``.
8585
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``.
9486

9587
Changing database settings for functional tests
9688
-----------------------------------------------
@@ -100,15 +92,43 @@ Most of the time you want to use a dedicated database connection to make sure
10092
not to overwrite data you entered when developing the application and also
10193
to be able to clear the database before every test.
10294

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:
10497

98+
.. code-block:: yaml
99+
100+
# app/config/config_test.yml
105101
doctrine:
102+
# ...
106103
dbal:
107104
host: localhost
108105
dbname: testdb
109106
user: testdb
110107
password: testdb
111108
112-
Make sure that your database runs on localhost and has the defined database and
113-
user credentials set up.
109+
.. code-block:: xml
114110
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

Comments
 (0)