getEntityManager(); $publicationRepo = self::getContainer()->get(CStudentPublicationRepository::class); $correctionRepo = self::getContainer()->get(CStudentPublicationCorrectionRepository::class); $course = $this->createCourse('new'); $teacher = $this->createUser('teacher'); $publication = (new CStudentPublication()) ->setTitle('publi') ->setDescription('desc') ->setParent($course) ->setFiletype('folder') ->setWeight(100) ->setCreator($teacher) ; $em->persist($publication); $file = $this->getUploadedFile(); $correction = (new CStudentPublicationCorrection()) ->setParent($publication) ->setCreator($teacher) ->setTitle($file->getClientOriginalName()) ; $correctionRepo->create($correction); $correctionRepo->addFile($correction, $file); $correctionRepo->update($correction); $em->flush(); $documentRepo = self::getContainer()->get(CDocumentRepository::class); $admin = $this->getUser('admin'); $document = (new CDocument()) ->setFiletype('file') ->setTitle('title 123') ->setTemplate(false) ->setReadonly(false) ->setParent($course) ->setCreator($admin) ->addCourseLink($course) ; $documentRepo->create($document); $document = (new CStudentPublicationRelDocument()) ->setPublication($publication) ->setDocument($document) ; $em->persist($document); $em->flush(); $em->clear(); /** @var CStudentPublication $publication */ $publication = $publicationRepo->find($publication->getIid()); $this->assertNotNull($publication->getCorrection()); $this->assertSame(1, $publicationRepo->count([])); $this->assertSame(1, $correctionRepo->count([])); $em->remove($publication); $em->flush(); // Fixme the correction should be cascade-deleted with the publication // $this->assertSame(0, $correctionRepo->count([])); $this->assertSame(0, $publicationRepo->count([])); } }