File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
tests/AppBundle/Controller Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -85,11 +85,18 @@ public function testNewComment()
85
85
86
86
$ this ->assertSame (Response::HTTP_FOUND , $ client ->getResponse ()->getStatusCode ());
87
87
88
+ // in order to improve performance, Doctrine doesn't make database calls to
89
+ // get the objects already present in memory. This means that this test will fail
90
+ // because new comments are added at the end of the list of comments and the
91
+ // "@ORM\OrderBy()" defined in the Post entity won't be respected. The solution
92
+ // is to call the clear() method on the Entity Manager, which removes the in-memory
93
+ // changes and forces loading objects from the database again.
88
94
$ client ->getContainer ()->get ('doctrine ' )->getManager ()->clear ();
89
95
90
- $ post = $ client ->getContainer ()->get ('doctrine ' )->getRepository (Post::class)->find (1 );
91
96
// The first one is the most recent comment because of the automatic sorting
92
- // defined in the comments association of the Post entity
97
+ // defined in the comments association of the Post entity. This test can only
98
+ // work when using the clear() method as explained in the above comment.
99
+ $ post = $ client ->getContainer ()->get ('doctrine ' )->getRepository (Post::class)->find (1 );
93
100
$ comment = $ post ->getComments ()->first ();
94
101
95
102
$ this ->assertSame ($ commentsCount + 1 , $ post ->getComments ()->count ());
You can’t perform that action at this time.
0 commit comments