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 testUserLesson()
 {
     $user = $this->buildUser();
     $course = new Course();
     $course->setName('PHP');
     $course->setDescription('Curso de PHP');
     $course->setValue(100);
     $course->setTeacher($user);
     $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);
     $user->setLessonCollection($lessonCollection);
     $this->getEntityManager()->persist($user);
     $this->getEntityManager()->flush();
     $savedUser = $this->getEntityManager()->find(get_class($user), 1);
     $this->assertEquals(2, count($savedUser->getLessonCollection()));
     $savedLessons = $savedUser->getLessonCollection();
     $this->assertEquals(1, $savedLessons[0]->getId());
 }