bootFaker(); $this->bootDatabase(); $this->getFaker()->unique(); } public function testFindByNameWillReturnCompany(): void { $c1 = new Company( 1, new ArrayCollection(), $this->getFaker()->company(), $this->getFaker()->text(50), $this->getFaker()->text(100) ); $this->getEntityManager()->persist($c1); $this->getEntityManager()->persist(new Company( 2, new ArrayCollection(), $this->getFaker()->company(), $this->getFaker()->text(50), $this->getFaker()->text(100) )); $this->getEntityManager()->flush(); /** * @var CompanyRepository $repository */ $repository = parent::getContainer()->get(CompanyRepository::class); $this->assertNotNull($repository->findByName($c1->name)); $this->assertNull($repository->findByName($this->getFaker()->text())); } public function testDeleteOrphanRecordsWillDeleteCompaniesWithoutUsers(): void { $c1 = new Company( 1, new ArrayCollection(), $this->getFaker()->company(), $this->getFaker()->text(50), $this->getFaker()->text(100) ); $user = $this->createUser(1); $this->getEntityManager()->persist($c1); $this->getEntityManager()->persist($user->address); $this->getEntityManager()->persist($user->company); $this->getEntityManager()->persist($user); $this->getEntityManager()->flush(); /** * @var CompanyRepository $repository */ $repository = $this->getContainer()->get(CompanyRepository::class); $repository->deleteOrphanRecords(); $result = $repository->findAll(); $this->assertCount(1, $result); $this->assertSame($user->company, $result[0]); } }