public function testUserLesson()
 {
     $userA = $this->buildUser('UserA');
     $course = new Course();
     $course->setName('PHP');
     $course->setDescription('Curso de PHP');
     $course->setValue(100);
     $course->setTeacher($userA);
     $lessonA = new Lesson();
     $lessonA->setName('Arrays');
     $lessonA->setDescription('Aula sobre Arrays');
     $lessonA->setCourse($course);
     $lessonB = new Lesson();
     $lessonB->setName('Datas');
     $lessonB->setDescription('Aula sobre Datas');
     $lessonB->setCourse($course);
     $lessonCollection = new ArrayCollection();
     $lessonCollection->add($lessonA);
     $lessonCollection->add($lessonB);
     $userA->setLessonCollection($lessonCollection);
     $enrollment = new Enrollment();
     $enrollment->setUser($userA);
     $enrollment->setCourse($course);
     $progressA = new Progress();
     $progressA->setPercent(100);
     $progressA->setUser($userA);
     $progressA->setLesson($lessonA);
     $progressA->setCreated(\DateTime::createFromFormat('Y-m-d H:i:s', date('Y-m-d H:i:s')));
     $progressB = new Progress();
     $progressB->setPercent(90);
     $progressB->setUser($userA);
     $progressB->setLesson($lessonB);
     $progressB->setCreated(\DateTime::createFromFormat('Y-m-d H:i:s', date('Y-m-d H:i:s')));
     $this->getEntityManager()->persist($userA);
     $this->getEntityManager()->persist($enrollment);
     $this->getEntityManager()->persist($progressA);
     $this->getEntityManager()->persist($progressB);
     $this->getEntityManager()->flush();
     $query = $this->em->createQuery('SELECT p FROM DoctrineNapratica\\Model\\Progress p JOIN p.lesson l JOIN l.course c WHERE p.percent = 100');
     $result = $query->getResult();
     $this->assertEquals(1, count($result));
     $this->assertEquals($userA->getId(), $result[0]->getUser()->getId());
     $this->assertEquals($lessonA->getId(), $result[0]->getLesson()->getId());
 }
 public function testUserEnrollment()
 {
     $user = $this->buildUser();
     $courseA = $this->buildCourse('PHP');
     $courseB = $this->buildCourse('Doctrine');
     $enrollmentA = new Enrollment();
     $enrollmentA->setUser($user);
     $enrollmentA->setCourse($courseA);
     $enrollmentB = new Enrollment();
     $enrollmentB->setUser($user);
     $enrollmentB->setCourse($courseB);
     $enrollmentCollection = new ArrayCollection();
     $enrollmentCollection->add($enrollmentA);
     $enrollmentCollection->add($enrollmentB);
     $user->setEnrollmentCollection($enrollmentCollection);
     $this->getEntityManager()->persist($user);
     $this->getEntityManager()->flush();
     $savedUser = $this->getEntityManager()->find(get_class($user), 1);
     $this->assertEquals(2, count($savedUser->getEnrollmentCollection()));
 }