Esempio n. 1
0
 public function testProcessEventListenerCascadeOneToMany()
 {
     /** @var UploadHandler $uploadHandler */
     $uploadHandler = self::$kernel->getContainer()->get('kyoushu_common.upload.handler');
     $webDir = $uploadHandler->getWebDir();
     $sourcePath = sprintf('%s/../Resources/upload/test.txt', __DIR__);
     $this->assertFileExists($sourcePath);
     $parent = new UploadParentEntity();
     $childOne = new UploadChildEntity();
     $childOne->setFile(new File($sourcePath));
     $childTwo = new UploadChildEntity();
     $childTwo->setFile(new File($sourcePath));
     $parent->addOneToManyChild($childOne);
     $parent->addOneToManyChild($childTwo);
     $manager = $this->getEntityManager();
     $manager->persist($parent);
     $manager->flush();
     $this->assertCount(2, $parent->getOneToManyChildren());
     foreach ($parent->getOneToManyChildren() as $child) {
         $path = sprintf('%s/%s', $webDir, $child->getRelPath());
         $this->assertFileExists($path);
         $fetchedChild = $this->getEntityManager()->getRepository('Kyoushu\\CommonBundle\\Tests\\Entity\\UploadChildEntity')->find($child->getId());
         $this->assertNotNull($fetchedChild);
         $path = sprintf('%s/%s', $webDir, $fetchedChild->getRelPath());
         $this->assertFileExists($path);
     }
 }
 /**
  * @param UploadChildEntity $child
  * @return $this
  */
 public function addOneToManyChild(UploadChildEntity $child)
 {
     $child->setManyToOneParent($this);
     $this->oneToManyChildren->add($child);
     return $this;
 }