14
14
use AppBundle \Entity \Comment ;
15
15
use AppBundle \Entity \Post ;
16
16
use AppBundle \Entity \User ;
17
- use Doctrine \Common \DataFixtures \FixtureInterface ;
17
+ use Doctrine \Common \DataFixtures \AbstractFixture ;
18
18
use Doctrine \Common \Persistence \ObjectManager ;
19
19
use Symfony \Component \DependencyInjection \ContainerAwareInterface ;
20
20
use Symfony \Component \DependencyInjection \ContainerAwareTrait ;
32
32
* @author Ryan Weaver <[email protected] >
33
33
* @author Javier Eguiluz <[email protected] >
34
34
*/
35
- class LoadFixtures implements FixtureInterface, ContainerAwareInterface
35
+ class LoadFixtures extends AbstractFixture implements ContainerAwareInterface
36
36
{
37
37
use ContainerAwareTrait;
38
38
@@ -55,6 +55,7 @@ private function loadUsers(ObjectManager $manager)
55
55
$ encodedPassword = $ passwordEncoder ->encodePassword ($ johnUser , 'kitten ' );
56
56
$ johnUser ->setPassword ($ encodedPassword );
57
57
$ manager ->persist ($ johnUser );
58
+ $ this ->addReference ('john-user ' , $ johnUser );
58
59
59
60
$ annaAdmin = new User ();
60
61
$ annaAdmin ->setUsername ('anna_admin ' );
@@ -63,6 +64,7 @@ private function loadUsers(ObjectManager $manager)
63
64
$ encodedPassword = $ passwordEncoder ->encodePassword ($ annaAdmin , 'kitten ' );
64
65
$ annaAdmin ->setPassword ($ encodedPassword );
65
66
$ manager ->persist ($ annaAdmin );
67
+ $ this ->addReference ('anna-admin ' , $ annaAdmin );
66
68
67
69
$ manager ->flush ();
68
70
}
@@ -76,13 +78,13 @@ private function loadPosts(ObjectManager $manager)
76
78
$ post ->setSummary ($ this ->getRandomPostSummary ());
77
79
$ post ->setSlug ($ this ->container ->get ('slugger ' )->slugify ($ post ->getTitle ()));
78
80
$ post ->setContent ($ this ->getPostContent ());
79
- $ post->
setAuthorEmail ( ' [email protected] ' );
81
+ $ post ->setAuthor ( $ this -> getReference ( ' anna-admin ' ) );
80
82
$ post ->setPublishedAt (new \DateTime ('now - ' .$ i .'days ' ));
81
83
82
84
foreach (range (1 , 5 ) as $ j ) {
83
85
$ comment = new Comment ();
84
86
85
- $ comment->
setAuthorEmail ( ' [email protected] ' );
87
+ $ comment ->setAuthor ( $ this -> getReference ( ' john-user ' ) );
86
88
$ comment ->setPublishedAt (new \DateTime ('now + ' .($ i + $ j ).'seconds ' ));
87
89
$ comment ->setContent ($ this ->getRandomCommentContent ());
88
90
$ comment ->setPost ($ post );
0 commit comments