public function testSaveWithFlush() { $entity = $this->subject->create(); $this->objectManager->expects($this->once())->method('persist')->with($entity); $this->objectManager->expects($this->never())->method('flush'); $this->subject->save($entity, false); }
public function testDelete() { $entity = $this->subject->create(); $this->objectManager->expects($this->once())->method('remove')->with($entity); $this->objectManager->expects($this->once())->method('flush'); $this->subject->delete($entity); }
protected function prepareServices() { $this->form->expects($this->once())->method('setData')->with($this->entity); $this->form->expects($this->once())->method('submit')->with($this->request); $this->request->setMethod('POST'); $this->form->expects($this->once())->method('isValid')->willReturn(true); $this->manager->expects($this->at(0))->method('persist')->with($this->isType('object')); $repository = $this->getMockBuilder('OroB2B\\Bundle\\PricingBundle\\Entity\\Repository\\PriceListRepository')->disableOriginalConstructor()->getMock(); $repository->expects($this->any())->method('setPriceListToAccount')->will($this->returnCallback(function (Account $account, PriceList $priceList = null) { $this->entity->removeAccount($account); if ($priceList) { $this->entity->addAccount($account); } })); $repository->expects($this->any())->method('setPriceListToAccountGroup')->will($this->returnCallback(function (AccountGroup $accountGroup, PriceList $priceList = null) { $this->entity->removeAccountGroup($accountGroup); if ($priceList) { $this->entity->addAccountGroup($accountGroup); } })); $repository->expects($this->any())->method('setPriceListToWebsite')->will($this->returnCallback(function (Website $website, PriceList $priceList = null) { $this->entity->removeWebsite($website); if ($priceList) { $this->entity->addWebsite($website); } })); $this->manager->expects($this->any())->method('getRepository')->with($this->isType('string'))->willReturn($repository); $this->manager->expects($this->exactly(2))->method('flush'); }
public function testOnDuplicateAfterSourceProductWithoutPrices() { $this->productPriceRepository->expects($this->once())->method('getPricesByProduct')->with($this->sourceProduct)->will($this->returnValue([])); $this->objectManager->expects($this->never())->method('persist'); $event = new ProductDuplicateAfterEvent($this->product, $this->sourceProduct); $this->listener->onDuplicateAfter($event); }
public function testProcessValidData() { $appendedUser = new User(); $appendedUser->setId(1); $removedUser = new User(); $removedUser->setId(2); $removedUser->addBusinessUnit($this->entity); $this->form->expects($this->once())->method('setData')->with($this->entity); $this->form->expects($this->once())->method('submit')->with($this->request); $this->request->setMethod('POST'); $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true)); $appendForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock(); $appendForm->expects($this->once())->method('getData')->will($this->returnValue(array($appendedUser))); $this->form->expects($this->at(3))->method('get')->with('appendUsers')->will($this->returnValue($appendForm)); $removeForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock(); $removeForm->expects($this->once())->method('getData')->will($this->returnValue(array($removedUser))); $this->form->expects($this->at(4))->method('get')->with('removeUsers')->will($this->returnValue($removeForm)); $this->manager->expects($this->at(0))->method('persist')->with($appendedUser); $this->manager->expects($this->at(1))->method('persist')->with($removedUser); $this->manager->expects($this->at(2))->method('persist')->with($this->entity); $this->manager->expects($this->once())->method('flush'); $this->assertTrue($this->handler->process($this->entity)); $businessUnits = $appendedUser->getBusinessUnits()->toArray(); $this->assertCount(1, $businessUnits); $this->assertEquals($this->entity, current($businessUnits)); $this->assertCount(0, $removedUser->getBusinessUnits()->toArray()); }
/** * Test get loaded settings */ public function testGetLoaded() { $loadedSettings = $this->loadedSettings; $repository = $this->getMockBuilder('Oro\\Bundle\\ConfigBundle\\Entity\\Repository\\ConfigRepository')->disableOriginalConstructor()->getMock(); $repository->expects($this->at(0))->method('loadSettings')->with('user', 0)->will($this->returnValue($loadedSettings)); $repository->expects($this->at(1))->method('loadSettings')->with('app', 0)->will($this->returnValue($loadedSettings)); $this->om->expects($this->exactly(2))->method('getRepository')->will($this->returnValue($repository)); $this->object->get('oro_user.level'); }
public function testGetNextValueWithNotExistingSequenceReturnsNextValue() { $sequenceName = 'ABC'; $this->repository->expects($this->once())->method('findOneBy')->with(array('name' => $sequenceName))->willReturn(null); $this->objectManager->expects($this->any())->method('persist'); $this->objectManager->expects($this->any())->method('flush'); $result = $this->subject->getNextValue($sequenceName); $this->assertEquals(1, $result); }
public function testRemove() { /** @var NotificationInterface $notification */ $notification = $this->getMock(NotificationInterface::class); $this->objectManager->expects($this->at(0))->method('remove')->with($notification); $this->objectManager->expects($this->at(0))->method('flush'); $result = $this->mapper->remove($notification); $this->assertTrue($result); }
public function testProcessValidData() { $this->request->setMethod('POST'); $this->form->expects($this->once())->method('setData')->with($this->entity); $this->form->expects($this->once())->method('submit')->with($this->request); $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true)); $this->manager->expects($this->once())->method('persist')->with($this->entity); $this->manager->expects($this->once())->method('flush'); $this->assertTrue($this->handler->process($this->entity)); }
/** * Tests the method when the address being saved is already persisted. */ public function testSavingAlreadyPersistedAddress() { $originalAddress = $this->getAddress('42', 'New address'); $clonedAddress = $this->getAddress(null, 'New address'); $this->addressObjectManagerMock->expects($this->once())->method('persist')->with($clonedAddress); $this->addressObjectManagerMock->expects($this->once())->method('flush')->with($clonedAddress); $this->addressEventDispatcher->expects($this->once())->method('dispatchAddressOnCloneEvent'); $savedAddress = $this->addressManager->saveAddress($originalAddress); $this->assertEquals($savedAddress, $clonedAddress, 'The saved address should be a new one'); }
protected function setUp() { $class = Layout::class; $this->repo = $this->getMockBuilder(ObjectRepository::class)->getMock(); $this->om = $this->getMockBuilder(ObjectManager::class)->getMock(); $this->om->expects($this->once())->method('getRepository')->with($class)->will($this->returnValue($this->repo)); /* @var ManagerRegistry|\PHPUnit_Framework_MockObject_MockObject $registry */ $registry = $this->getMockBuilder(ManagerRegistry::class)->getMock(); $registry->expects($this->once())->method('getManagerForClass')->with($class)->will($this->returnValue($this->om)); $this->loader = new EntityLayoutLoader($registry, $class); }
public function setUp() { $this->routeMock = $this->buildMock('Symfony\\Cmf\\Bundle\\RoutingBundle\\Doctrine\\Orm\\Route'); $this->route2Mock = $this->buildMock('Symfony\\Cmf\\Bundle\\RoutingBundle\\Doctrine\\Orm\\Route'); $this->objectManagerMock = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager'); $this->managerRegistryMock = $this->getMock('Doctrine\\Common\\Persistence\\ManagerRegistry'); $this->objectRepositoryMock = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->setMethods(array('findByStaticPrefix', 'findOneBy', 'findBy'))->disableOriginalConstructor()->getMock(); $this->candidatesMock = $this->getMock('Symfony\\Cmf\\Component\\Routing\\Candidates\\CandidatesInterface'); $this->candidatesMock->expects($this->any())->method('isCandidate')->will($this->returnValue(true)); $this->managerRegistryMock->expects($this->any())->method('getManager')->will($this->returnValue($this->objectManagerMock)); $this->objectManagerMock->expects($this->any())->method('getRepository')->with('Route')->will($this->returnValue($this->objectRepositoryMock)); }
public function testProcessValidPost() { $offerData = ['offer', 'data']; $quote = new Quote(); $order = new Order(); $this->request->setMethod('POST'); $this->form->expects($this->once())->method('submit')->with($this->request); $this->form->expects($this->once())->method('isValid')->willReturn(true); $this->form->expects($this->once())->method('getData')->willReturn($offerData); $this->converter->expects($this->once())->method('convert')->with($quote, $this->accountUser, $offerData)->willReturn($order); $this->manager->expects($this->once())->method('persist')->with($order); $this->manager->expects($this->once())->method('flush'); $this->assertEquals($order, $this->handler->process($quote)); }
protected function setUp() { $this->factory = $this->getMock('Symfony\\Component\\Form\\ChoiceList\\Factory\\ChoiceListFactoryInterface'); $this->om = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager'); $this->repository = $this->getMock('Doctrine\\Common\\Persistence\\ObjectRepository'); $this->class = 'stdClass'; $this->idReader = $this->getMockBuilder('Symfony\\Bridge\\Doctrine\\Form\\ChoiceList\\IdReader')->disableOriginalConstructor()->getMock(); $this->objectLoader = $this->getMock('Symfony\\Bridge\\Doctrine\\Form\\ChoiceList\\EntityLoaderInterface'); $this->obj1 = (object) array('name' => 'A'); $this->obj2 = (object) array('name' => 'B'); $this->obj3 = (object) array('name' => 'C'); $this->om->expects($this->any())->method('getRepository')->with($this->class)->willReturn($this->repository); $this->om->expects($this->any())->method('getClassMetadata')->with($this->class)->willReturn(new ClassMetadata($this->class)); }
protected function setUp() { $this->objectRepository = $this->getMockForClass('Oro\\Bundle\\EmailBundle\\Entity\\Repository\\EmailTemplateRepository'); $this->objectManager = $this->getMockForClass('Doctrine\\Common\\Persistence\\ObjectManager'); $this->objectManager->expects($this->any())->method('getRepository')->with('OroEmailBundle:EmailTemplate')->willReturn($this->objectRepository); $this->managerRegistry = $this->getMock('Doctrine\\Common\\Persistence\\ManagerRegistry'); $this->managerRegistry->expects($this->any())->method('getManagerForClass')->with('OroEmailBundle:EmailTemplate')->willReturn($this->objectManager); $this->configManager = $this->getMockForClass('Oro\\Bundle\\ConfigBundle\\Config\\ConfigManager'); $this->configManager->expects($this->any())->method('get')->willReturnMap([['oro_notification.email_notification_sender_email', false, false, self::FROM_EMAIL], ['oro_notification.email_notification_sender_name', false, false, self::FROM_NAME]]); $this->renderer = $this->getMockForClass('Oro\\Bundle\\EmailBundle\\Provider\\EmailRenderer'); $this->emailHolderHelper = $this->getMockForClass('Oro\\Bundle\\EmailBundle\\Tools\\EmailHolderHelper'); $this->mailer = $this->getMockForClass('\\Swift_Mailer'); $this->mailProcessor = new BaseProcessor($this->managerRegistry, $this->configManager, $this->renderer, $this->emailHolderHelper, $this->mailer); $this->emailTemplate = $this->getMock('Oro\\Bundle\\EmailBundle\\Model\\EmailTemplateInterface'); }
public function testSetOrderMail() { $order = new TicketsOrder(); $ticketsOrderRepository = $this->getMockBuilder(TicketsOrderRepository::class)->disableOriginalConstructor()->setMethods(array('findOneBy'))->getMock(); $ticketsOrderRepository->expects($this->at(0))->method('findOneBy')->will($this->returnValue(null)); $ticketsOrderRepository->expects($this->at(1))->method('findOneBy')->will($this->returnValue($order)); $this->entityManager->expects($this->any())->method('getRepository')->will($this->returnValue($ticketsOrderRepository)); try { $this->paymentOrderInformation->setOrderMail(1, 'AAAAA', '*****@*****.**'); $this->fail('a null order must throw an exception'); } catch (HttpException $e) { $this->assertEquals('400', $e->getStatusCode()); } $this->paymentOrderInformation->setOrderMail(1, 'AAAAA', '*****@*****.**'); $this->assertEquals('*****@*****.**', $order->getMail()); }
/** * @dataProvider getAccountDataProvider * * @param string $method * @param string $class * @param string $param */ public function testGetAccount($method, $class, $param) { $entity = $this->getEntity($class, 42); $this->request->expects($this->once())->method('get')->with(OrderType::NAME)->willReturn([$param => $entity->getId()]); $this->objectManager->expects($this->once())->method('find')->with($class, $entity->getId())->willReturn($entity); $this->assertSame($entity, $this->handler->{$method}()); }
/** * @expectedException \Abc\Bundle\ResourceLockBundle\Exception\LockException * @expectedExceptionMessage Lock with provided name can not be set */ public function testLockThrowsServerException() { $lockName = 'ABC'; $ex = $this->getMock(DriverException::class); $this->objectManager->expects($this->once())->method('persist')->willThrowException(new ServerException('ServerException', $ex)); $this->subject->lock($lockName); }
public function testProcessValidData() { $appendedContact = new Contact(); $appendedContact->setId(1); $removedContact = new Contact(); $removedContact->setId(2); $this->entity->addContact($removedContact); $this->request->setMethod('POST'); $this->form->expects($this->once())->method('setData')->with($this->entity); $this->form->expects($this->once())->method('submit')->with($this->request); $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true)); $this->form->expects($this->once())->method('has')->with('contacts')->will($this->returnValue(true)); $contactsForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock(); $appendForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock(); $appendForm->expects($this->once())->method('getData')->will($this->returnValue(array($appendedContact))); $contactsForm->expects($this->at(0))->method('get')->with('added')->will($this->returnValue($appendForm)); $removeForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock(); $removeForm->expects($this->once())->method('getData')->will($this->returnValue(array($removedContact))); $contactsForm->expects($this->at(1))->method('get')->with('removed')->will($this->returnValue($removeForm)); $this->form->expects($this->exactly(1))->method('get')->with('contacts')->will($this->returnValue($contactsForm)); $this->manager->expects($this->once())->method('persist')->with($this->entity); $this->manager->expects($this->once())->method('flush'); $this->assertTrue($this->handler->process($this->entity)); $actualContacts = $this->entity->getContacts()->toArray(); $this->assertCount(1, $actualContacts); $this->assertEquals($appendedContact, current($actualContacts)); }
protected function setUp() { $repo = $this->getMockBuilder('Oro\\Bundle\\ConfigBundle\\Entity\\Repository\\ConfigRepository')->disableOriginalConstructor()->getMock(); $repo->expects($this->any())->method('loadSettings'); $this->om = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager'); $this->om->expects($this->any())->method('getRepository')->will($this->returnValue($repo)); $this->object = new UserScopeManager($this->om); $this->security = $this->getMock('Symfony\\Component\\Security\\Core\\SecurityContextInterface'); $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface'); $this->security->expects($this->any())->method('getToken')->will($this->returnValue($token)); $token->expects($this->any())->method('getUser')->will($this->returnValue($this->getUser())); $this->container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); $this->container->expects($this->any())->method('get')->will($this->returnValueMap([['security.context', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->security]])); $this->object = new UserScopeManager($this->om); $this->object->setContainer($this->container); }
protected function setUp() { $this->contextAccessor = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Model\\ContextAccessor')->disableOriginalConstructor()->getMock(); $this->emailProcessor = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Mailer\\Processor')->disableOriginalConstructor()->getMock(); $this->entityNameResolver = $this->getMockBuilder('Oro\\Bundle\\EntityBundle\\Provider\\EntityNameResolver')->disableOriginalConstructor()->getMock(); $this->dispatcher = $this->getMockBuilder('Symfony\\Component\\EventDispatcher\\EventDispatcher')->disableOriginalConstructor()->getMock(); $this->renderer = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Provider\\EmailRenderer')->disableOriginalConstructor()->getMock(); $this->validator = $this->getMock('Symfony\\Component\\Validator\\Validator\\ValidatorInterface'); $this->objectManager = $this->getMockBuilder('Doctrine\\Common\\Persistence\\ObjectManager')->disableOriginalConstructor()->getMock(); $this->objectRepository = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Entity\\Repository\\EmailTemplateRepository')->disableOriginalConstructor()->getMock(); $logger = $this->getMock('Psr\\Log\\LoggerInterface'); $this->objectManager->expects($this->any())->method('getRepository')->willReturn($this->objectRepository); $this->emailTemplate = $this->getMock('Oro\\Bundle\\EmailBundle\\Model\\EmailTemplateInterface'); $this->action = new SendEmailTemplate($this->contextAccessor, $this->emailProcessor, new EmailAddressHelper(), $this->entityNameResolver, $this->renderer, $this->objectManager, $this->validator); $this->action->setLogger($logger); $this->action->setDispatcher($this->dispatcher); }
/** * Test add postalCode in zone * * @dataProvider dataAddAnyInZone */ public function testAddPostalCodeInZone($exists, $persist, $flush) { $this->objectManager->expects($persist)->method('persist')->with($this->isInstanceOf('Elcodi\\Component\\Geo\\Entity\\Interfaces\\ZonePostalCodeMemberInterface')); $this->objectManager->expects($flush)->method('flush')->with($this->isInstanceOf('Elcodi\\Component\\Geo\\Entity\\Interfaces\\ZonePostalCodeMemberInterface')); $this->zoneMatcher->expects($this->any())->method('isPostalCodeContainedInZone')->will($this->returnValue($exists)); $postalCode = $this->getMock('Elcodi\\Component\\Geo\\Entity\\Interfaces\\PostalCodeInterface'); $zone = $this->getMock('Elcodi\\Component\\Geo\\Entity\\Interfaces\\ZoneInterface'); $this->zoneManager->addPostalCodeToZone($zone, $postalCode); }
/** * @param FormEvent $event * @param array $prices */ protected function assertPriceAdd(FormEvent $event, array $prices) { /** @var FormInterface|\PHPUnit_Framework_MockObject_MockObject $mainForm */ $mainForm = $event->getForm(); $mainForm->expects($this->once())->method('isValid')->willReturn(true); /** @var FormInterface|\PHPUnit_Framework_MockObject_MockObject $pricesForm */ $pricesForm = $mainForm->get('prices'); $pricesForm->expects($this->once())->method('getData')->will($this->returnValue($prices)); $this->priceManager->expects($this->exactly(count($prices)))->method('persist'); }
public function testAssertNullValueNotUsedAsIdentifierForOneToOneWithNonOptionalMethodSignature() { $entity = new Asset\OneToOneEntityNotNullable(); $entity->setToOne(new Asset\SimpleEntity()); $this->configureObjectManagerForOneToOneEntityNotNullable(); $this->objectManager->expects($this->never())->method('find'); $data = array('toOne' => null); $object = $this->hydratorByValue->hydrate($data, $entity); $this->assertInstanceOf('DoctrineModuleTest\\Stdlib\\Hydrator\\Asset\\SimpleEntity', $object->getToOne(false)); }
protected function setUp() { $repo = $this->getMockBuilder('Oro\\Bundle\\ConfigBundle\\Entity\\Repository\\ConfigRepository')->disableOriginalConstructor()->getMock(); $repo->expects($this->any())->method('loadSettings'); $this->om = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager'); $this->om->expects($this->any())->method('getRepository')->will($this->returnValue($repo)); $this->object = new UserScopeManager($this->om); $this->security = $this->getMock('Symfony\\Component\\Security\\Core\\SecurityContextInterface'); $this->group1 = $this->getMock('Oro\\Bundle\\UserBundle\\Entity\\Group'); $this->group2 = $this->getMock('Oro\\Bundle\\UserBundle\\Entity\\Group'); $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface'); $user = new User(); $this->security->expects($this->any())->method('getToken')->will($this->returnValue($token)); $this->group1->expects($this->any())->method('getId')->will($this->returnValue(2)); $this->group2->expects($this->any())->method('getId')->will($this->returnValue(3)); $token->expects($this->any())->method('getUser')->will($this->returnValue($user)); $user->setId(1)->addGroup($this->group1)->addGroup($this->group2); $this->object = new UserScopeManager($this->om); }
public function testProcessValidData() { $subtotal = new Subtotal(); $amount = 42; $subtotal->setType(Subtotal::TYPE_SUBTOTAL); $subtotal->setAmount($amount); $subtotals = new ArrayCollection([$subtotal]); $this->subtotalsProvider->expects($this->any())->method('getSubtotals')->willReturn($subtotals); $this->request->setMethod('POST'); $this->form->expects($this->once())->method('submit')->with($this->request); $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true)); $this->manager->expects($this->once())->method('persist')->with($this->entity); $this->manager->expects($this->once())->method('flush'); $this->assertTrue($this->handler->process($this->entity)); $propertyAccessor = PropertyAccess::createPropertyAccessor(); foreach ($subtotals as $subtotal) { $this->assertEquals($amount, $propertyAccessor->getValue($this->entity, $subtotal->getType())); } }
/** * {@inheritdoc} */ protected function setUp() { $classMetadata = $this->getMockForAbstractClass('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata'); $classMetadata->expects($this->once())->method('getName')->will($this->returnValue($this->fullClassName)); $this->objectRepository = $this->getMockForAbstractClass('Doctrine\\Common\\Persistence\\ObjectRepository'); $this->objectManager = $this->getMockForAbstractClass('Doctrine\\Common\\Persistence\\ObjectManager'); $this->objectManager->expects($this->once())->method('getClassMetadata')->with($this->shortClassName)->will($this->returnValue($classMetadata)); $this->objectManager->expects($this->once())->method('getRepository')->with($this->fullClassName)->will($this->returnValue($this->objectRepository)); $this->uut = $this->getMockForAbstractClass('Fightmaster\\Model\\Manager\\DoctrineManager', array($this->objectManager, $this->shortClassName)); }
/** * @expectedException \RuntimeException * @expectedExceptionMessage Expected Symfony\Component\Security\Core\Role\RoleInterface, \stdClass given */ public function testNotSupportedRole() { $user = new User(); $this->metadata->expects($this->once())->method('getAssociationTargetClass')->willReturn('\\stdClass'); $this->om->expects($this->never())->method('persist')->with($this->equalTo($user)); $this->om->expects($this->never())->method('flush'); $repository = $this->getMockBuilder('Oro\\Bundle\\UserBundle\\Entity\\Repository\\UserApiRepository')->disableOriginalConstructor()->getMock(); $this->om->expects($this->any())->method('getRepository')->will($this->returnValue($repository)); $this->userManager->updateUser($user); }
public function testFormWithNullData() { $entity = new Entity(1); $className = get_class($entity); $this->entityMgr->expects($this->never())->method('getReference'); $form = $this->factory->createBuilder()->add('auto', AutocompleterType::class, array('class' => $className))->getForm(); $form->submit(array()); $data = $form['auto']->getData(); $this->assertNull($data); }
public function testResolveTask() { $listId = 1; $taskId = 1; $task = new Task(); $this->taskRepository->expects($this->once())->method('getTask')->with($listId, $taskId)->willReturn($task); $this->em->expects($this->once())->method('flush'); $task = $this->todoService->resolveTask($listId, $taskId); $this->assertEquals(Task::STATUS_DONE, $task->getStatus()); }