getEntityManager(); $repo = self::getContainer()->get(CExerciseCategoryRepository::class); $course = $this->createCourse('new'); $teacher = $this->createUser('teacher'); $item = (new CExerciseCategory()) ->setName('cat') ->setDescription('des') ->setCourse($course) ->setParent($course) ->setCreator($teacher) ; $this->assertHasNoEntityViolations($item); $em->persist($item); $em->flush(); $this->assertSame('cat', (string) $item); $this->assertSame(1, $repo->count([])); $this->assertCount(1, $repo->getCategories($course->getId())); } }