/** * @param ObjectProphecy $entity * @param string $method * @param ObjectProphecy $form * @param array $parameters * @param ObjectProphecy $submittedEntity */ protected function prophesizeProcessFormOk(ObjectProphecy $entity, $method, ObjectProphecy $form, array $parameters, ObjectProphecy $submittedEntity) { $this->prophesizeProcessFormFirstPart($this->formTypeName, $entity, $method, $form, $parameters); $form->isValid()->willReturn(true)->shouldBeCalledTimes(1); $form->getData()->willReturn($submittedEntity->reveal())->shouldBeCalledTimes(1); $this->fertilizerObjectManager->batchPersistAndFlush(array($submittedEntity->reveal()))->shouldBeCalledTimes(1); }
/** * @param EntityInterface $entity * @param array $parameters * @param string $method * * @return mixed * @throws InvalidFormException */ public function processForm(EntityInterface $entity, array $parameters, $method = "PUT") { $form = $this->formFactory->create($this->formTypeAlias, $entity, array('method' => $method)); $form->submit($parameters, 'PATCH' !== $method); if ($form->isValid()) { $submittedEntity = $form->getData(); $this->fertilizerObjectManager->batchPersistAndFlush(array($submittedEntity)); return $submittedEntity; } throw new InvalidFormException('Invalid submitted data', $form); }
/** * @dataProvider getTestBatchPersistAndFlushData * @param int $batchLimit * @param array $entityList * @param array $entitiesToFlushList */ public function testBatchPersistAndFlush($batchLimit, array $entityList, array $entitiesToFlushList) { $className = 'AppBundle\\Entity\\EntityInterface'; /** @var DoctrineObjectManager|ObjectProphecy $manager */ $manager = $this->prophesize('Doctrine\\Common\\Persistence\\ObjectManager'); $this->repository->getClassName()->willReturn($className)->shouldBeCalledTimes(1); $this->managerRegistry->getManagerForClass($className)->willReturn($manager->reveal())->shouldBeCalledTimes(1); foreach ($entityList as $entity) { $manager->persist($entity)->shouldBeCalledTimes(1); } foreach ($entitiesToFlushList as $entitiesToFlush) { $manager->flush($entitiesToFlush)->shouldBeCalledTimes(1); } $this->manager->batchPersistAndFlush($entityList, $batchLimit); }