Esempio n. 1
0
 /**
  * @inheritdoc
  */
 public function postPersist($entity)
 {
     $form = $this->getForm();
     if ($form->offsetExists(static::FIELD_AMOUNT)) {
         $amount = intval($form->get(static::FIELD_AMOUNT)->getData());
         $this->jamService->duplicate($entity, $amount - 1);
     }
 }
Esempio n. 2
0
 /**
  * @dataProvider duplicateProvider
  */
 public function testDuplicate($count, $expectedCount)
 {
     $jam = $this->getMock('\\Levi9\\SonataBundle\\Entity\\Jam');
     $cloneService = $this->getMock('\\Levi9\\SonataBundle\\Service\\CloneService');
     $cloneService->expects($this->exactly($expectedCount))->method('cloneObject')->with($jam);
     $em = $this->getMockBuilder('\\Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $em->expects($this->exactly($expectedCount))->method('persist');
     $em->expects($this->once())->method('flush');
     $jamService = new JamService($em, $cloneService);
     $jamService->duplicate($jam, $count);
 }
Esempio n. 3
0
 /**
  * @dataProvider duplicateProvider
  */
 public function testDuplicate($count, $expectedCount)
 {
     //todo: actually, this test is not testing, whether Jam was cloned or not.
     //To test clone method: create "clone" factory. It will have only one method with "clone" operator.
     // inject that service into Jam service. Expect, that clone method was called N times.
     $jam = $this->getMock('\\Levi9\\SonataBundle\\Entity\\Jam');
     $em = $this->getMockBuilder('\\Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $em->expects($this->exactly($expectedCount))->method('persist')->withConsecutive(array($jam), array($jam), array($jam));
     $em->expects($this->once())->method('flush');
     $jamService = new JamService($em);
     $jamService->duplicate($jam, $count);
 }