/** * @param EmailCampaign $emailCampaign * @param Campaign $campaign * @param bool $expected * @dataProvider staticCampaignProvider */ public function testIsApplicableOnEmailCampaign($emailCampaign, $campaign, $expected) { $this->entityRepository->expects($this->any())->method('findOneBy')->will($this->returnValue($campaign)); $this->managerRegistry->expects($this->any())->method('getManager')->will($this->returnValue($this->entityManager)); $this->entityManager->expects($this->any())->method('getRepository')->will($this->returnValue($this->entityRepository)); $this->assertEquals($expected, $this->placeholderFilter->isApplicableOnEmailCampaign($emailCampaign)); }
/** * @param null|StaticSegment $staticSegment * @param bool $expected * @dataProvider staticSegmentDataProvider */ public function testIsApplicableOnMarketingList($staticSegment, $expected) { $this->entityRepository->expects($this->once())->method('findOneBy')->will($this->returnValue($staticSegment)); $this->managerRegistry->expects($this->once())->method('getManager')->will($this->returnValue($this->entityManager)); $this->entityManager->expects($this->once())->method('getRepository')->will($this->returnValue($this->entityRepository)); $entity = new MarketingList(); $this->assertEquals($expected, $this->placeholderFilter->isApplicableOnMarketingList($entity)); }
public function testSuccessChange() { $this->registry->expects($this->once())->method('getManager')->will($this->returnValue($this->em)); $this->registry->expects($this->once())->method('getRepository')->with('JMSJobQueueBundle:Job')->will($this->returnValue($this->repo)); $this->repo->expects($this->once())->method('findOneBy')->with(['command' => LifetimeAverageAggregateCommand::COMMAND_NAME, 'state' => Job::STATE_PENDING])->will($this->returnValue($scheduled = false)); $this->em->expects($this->once())->method('persist'); $this->em->expects($this->once())->method('flush'); $this->listener->onConfigUpdate(new ConfigUpdateEvent(['oro_locale.timezone' => ['old' => 1, 'new' => 2]])); }
/** * {@inheritdoc} */ public function setUp() { $this->entityRepository = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->setMethods(['find'])->getMock(); $this->entityRepository->expects($this->once())->method('find')->willReturn(null); $this->entityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->setMethods(['getRepository'])->getMock(); $this->entityManager->expects($this->once())->method('getRepository')->willReturn($this->entityRepository); $this->elasticsearchRepository = $this->getMockBuilder('ONGR\\ElasticsearchBundle\\ORM\\Repository')->disableOriginalConstructor()->getMock(); $this->syncStorage = $this->getMockBuilder('ONGR\\ConnectionsBundle\\Sync\\SyncStorage\\SyncStorage')->disableOriginalConstructor()->setMethods(['getChunk'])->getMock(); }
public function testGetChannelFromContext() { $testID = 1; $integration = new Integration(); $integration->setTransport($this->getMockForAbstractClass('Oro\\Bundle\\IntegrationBundle\\Entity\\Transport')); $context = $this->getMock('Oro\\Bundle\\ImportExportBundle\\Context\\ContextInterface'); $context->expects($this->once())->method('getOption')->with('channel')->will($this->returnValue($testID)); $this->repo->expects($this->once())->method('getOrLoadById')->with($testID)->will($this->returnValue($integration)); $result = $this->contextMediator->getChannel($context); $this->assertEquals($integration, $result); }
public function testGetSegmentTypeChoices() { $this->repository = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock(); $this->em->expects($this->any())->method('getRepository')->with('OroSegmentBundle:SegmentType')->will($this->returnValue($this->repository)); $type = new SegmentType('test'); $type->setLabel('testLabel'); $types = [$type]; $this->repository->expects($this->once())->method('findAll')->will($this->returnValue($types)); $result = $this->manager->getSegmentTypeChoices(); $this->assertInternalType('array', $result); $this->assertCount(1, $result); $this->assertSame(['test' => 'testLabel'], $result); }
/** * @return EntityRepository */ public function getEntityRepository() { if (!$this->entityRepository) { $this->entityRepository = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock(); $this->entityRepository->expects($this->any())->method('createQueryBuilder')->with('e')->will($this->returnValue($this->getQueryBuilder())); } return $this->entityRepository; }
public function testGetAllRoutes() { $this->objectRepositoryMock->expects($this->once())->method('findBy')->with(array(), null, 42)->will($this->returnValue(array($this->routeMock))); $routeProvider = new RouteProvider($this->managerRegistryMock, $this->candidatesMock, 'Route'); $routeProvider->setManagerName('default'); $routeProvider->setRouteCollectionLimit(42); $routes = $routeProvider->getRoutesByNames(null); $this->assertCount(1, $routes); }
protected function setSearchExpects() { $this->entityRepository->expects($this->once())->method('createQueryBuilder')->will($this->returnValue($this->queryBuilder)); $this->queryBuilder->expects($this->once())->method('where')->will($this->returnSelf()); $this->queryBuilder->expects($this->exactly(2))->method('andWhere')->will($this->returnSelf()); $this->queryBuilder->expects($this->exactly(3))->method('setParameter')->will($this->returnSelf()); $this->queryBuilder->expects($this->exactly(2))->method('addOrderBy')->will($this->returnSelf()); $this->queryBuilder->expects($this->any())->method('expr')->will($this->returnValue($this->expr)); $this->aclHelper->expects($this->once())->method('apply')->will($this->returnValue($this->queryBuilder)); }
public function testExecuteWrongNameSpecified() { $this->expectContainerGetManagerRegistryAndProcessHandler(); $id = 1; $this->input->expects($this->exactly(2))->method('getOption')->willReturnMap([['id', $id], ['name', 'wrong_name']]); $processTrigger = $this->createProcessTrigger($id); $this->repo->expects($this->once())->method('find')->with($id)->willReturn($processTrigger); $this->processHandler->expects($this->never())->method($this->anything()); $this->command->execute($this->input, $this->output); $this->assertAttributeEquals(['Trigger not found in process definition "wrong_name"'], 'messages', $this->output); }
/** * Test case to cover the showResignedAction with filter value as post * * @covers Skyrocket\LoginBundle\Controller\DefaultController::showResignedAction */ public function testShowResignedWithFilterAction() { $dummyResultArray = $this->getResignedDummyFilterArray(); $this->mockController->expects($this->once())->method('getRequest')->will($this->returnValue($this->mockRequest)); $this->mockRequest->expects($this->any())->method('getMethod')->will($this->returnValue('POST')); $this->mockRequest->expects($this->at(1))->method('get')->with($this->equalTo('fromDate'))->will($this->returnValue('08/04/2015')); $this->mockRequest->expects($this->at(2))->method('get')->with($this->equalTo('toDate'))->will($this->returnValue('08/06/2015')); $this->mockController->expects($this->once())->method('getDoctrine')->will($this->returnValue($this->mockRegistry)); $this->mockRegistry->expects($this->once())->method('getManager')->will($this->returnValue($this->mockEntityManager)); $this->mockEntityManager->expects($this->once())->method('getRepository')->with($this->equalTo('SkyrocketLoginBundle:Employee'))->will($this->returnValue($this->mockRepository)); $this->mockRepository->expects($this->once())->method('getFilteredEmployeesResigned')->with($this->equalTo(1), $this->equalTo('2015-08-04 00:00:00'), $this->equalTo('2015-08-06 00:00:00'))->will($this->returnValue($dummyResultArray)); $this->mockController->showResignedAction(); }
/** * @param null $name * @param array $data * @param string $dataName */ public function __construct($name = null, array $data = array(), $dataName = '') { parent::__construct($name, $data, $dataName); $this->billingAddressType = new AddressType(AddressType::TYPE_BILLING); $this->shippingAddressType = new AddressType(AddressType::TYPE_SHIPPING); $this->em = $this->createEntityManagerMock(); $this->addressRepository = $this->createRepositoryMock([$this->billingAddressType, $this->shippingAddressType]); $this->addressRepository->expects($this->any())->method('findBy')->will($this->returnCallback(function ($params) { $result = []; foreach ($params['name'] as $name) { switch ($name) { case AddressType::TYPE_BILLING: $result[] = $this->billingAddressType; break; case AddressType::TYPE_SHIPPING: $result[] = $this->shippingAddressType; break; } } return $result; })); }
public function testFindById() { $accountId = 1; $search = 'test'; $foundElement = $this->getResultStub($accountId, $search); $expectedResultData = [['id' => $accountId, 'email' => $search]]; $queryString = sprintf('%s%s%d', $search, self::DELIMITER, $accountId); $this->entityRepository->expects($this->once())->method('findOneBy')->will($this->returnValue($foundElement)); $searchResult = $this->searchHandler->search($queryString, 1, 10, true); $this->assertInternalType('array', $searchResult); $this->assertArrayHasKey('more', $searchResult); $this->assertArrayHasKey('results', $searchResult); $this->assertEquals($expectedResultData, $searchResult['results']); }
/** * @param string $search * @param int $page * @param int $perPage * @param array $foundElements * @param array $resultData * @param array $expectedIds * @return \PHPUnit_Framework_MockObject_MockObject */ protected function assertSearchCall($search, $page, $perPage, array $foundElements, array $resultData, array $expectedIds) { $searchResult = $this->getMockBuilder('Oro\\Bundle\\SearchBundle\\Query\\Result')->disableOriginalConstructor()->getMock(); $searchResult->expects($this->once())->method('getElements')->will($this->returnValue($foundElements)); $this->indexer->expects($this->once())->method('simpleSearch')->with($search, $page - 1, $perPage + 1, 'alias')->will($this->returnValue($searchResult)); $queryBuilder = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock(); $query = $this->getMockBuilder('Doctrine\\ORM\\AbstractQuery')->disableOriginalConstructor()->setMethods(['getResult'])->getMockForAbstractClass(); $query->expects($this->once())->method('getResult')->will($this->returnValue($resultData)); $expr = $this->getMockBuilder('Doctrine\\ORM\\Query\\Expr')->disableOriginalConstructor()->getMock(); $expr->expects($this->once())->method('in')->with('e.id', $expectedIds)->will($this->returnSelf()); $queryBuilder->expects($this->once())->method('expr')->will($this->returnValue($expr)); $queryBuilder->expects($this->once())->method('where')->with($expr)->will($this->returnSelf()); $this->aclHelper->expects($this->once())->method('apply')->with($queryBuilder, 'VIEW')->will($this->returnValue($query)); $this->entityRepository->expects($this->any())->method('createQueryBuilder')->will($this->returnValue($queryBuilder)); return $searchResult; }
/** * {@inheritdoc} */ protected function setUp() { $this->objectManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $this->doctrineHelper = $this->getMockBuilder('Oro\\Bundle\\EntityBundle\\ORM\\DoctrineHelper')->disableOriginalConstructor()->getMock(); $this->eventDispatcher = $this->getMockBuilder('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface')->disableOriginalConstructor()->getMock(); $this->skuIncrementor = $this->getMockBuilder('OroB2B\\Bundle\\ProductBundle\\Duplicator\\SkuIncrementorInterface')->disableOriginalConstructor()->getMock(); $this->attachmentManager = $this->getMockBuilder('Oro\\Bundle\\AttachmentBundle\\Manager\\AttachmentManager')->disableOriginalConstructor()->getMock(); $this->attachmentProvider = $this->getMockBuilder('Oro\\Bundle\\AttachmentBundle\\Provider\\AttachmentProvider')->disableOriginalConstructor()->getMock(); $this->productStatusRepository = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock(); $this->productStatusDisabled = $this->getMockBuilder('Oro\\Bundle\\EntityExtendBundle\\Entity\\AbstractEnumValue')->disableOriginalConstructor()->getMockForAbstractClass(); $this->connection = $this->getMockBuilder('Doctrine\\DBAL\\Connection')->disableOriginalConstructor()->getMock(); $this->doctrineHelper->expects($this->once())->method('getEntityRepository')->with(ExtendHelper::buildEnumValueClassName('prod_status'))->will($this->returnValue($this->productStatusRepository)); $this->doctrineHelper->expects($this->any())->method('getEntityManager')->with($this->anything())->will($this->returnValue($this->objectManager)); $this->objectManager->expects($this->any())->method('getConnection')->will($this->returnValue($this->connection)); $this->productStatusRepository->expects($this->once())->method('find')->with(Product::STATUS_DISABLED)->will($this->returnValue($this->productStatusDisabled)); $this->duplicator = new ProductDuplicator($this->doctrineHelper, $this->eventDispatcher, $this->attachmentManager, $this->attachmentProvider); $this->duplicator->setSkuIncrementor($this->skuIncrementor); }
/** * @covers Kunstmaan\PagePartBundle\EventListener\CloneListener::postDeepCloneAndSave */ public function testClonePageTemplate() { $entity = $this->getMock(HasPageTemplateInterface::class); /** @var HasPageTemplateInterface|\PHPUnit_Framework_MockObject_MockObject $clone */ $clone = clone $entity; $entity->expects($this->any())->method('getId')->will($this->returnValue(1)); $clone->expects($this->any())->method('getId')->will($this->returnValue(2)); $this->repo->expects($this->once())->method('copyPageParts')->with($this->em, $entity, $clone, 'main'); $configuration = new PageTemplateConfiguration(); $configuration->setId(1); $configuration->setPageId(1); $this->templateService->expects($this->once())->method('findOrCreateFor')->with($this->identicalTo($entity))->will($this->returnValue($configuration)); $newConfiguration = clone $configuration; $newConfiguration->setId(null); $newConfiguration->setPageId($clone->getId()); $this->em->expects($this->once())->method('persist')->with($newConfiguration); $event = new DeepCloneAndSaveEvent($entity, $clone); $this->object->postDeepCloneAndSave($event); }
/** * @test */ public function updateBranchWithAllValues() { $this->fileMock = new UploadedFileStub(self::DUMMY_LOGO_PATH, self::DUMMY_LOGO_NAME); $uploadedFile = $this->fileMock->move(self::DUMMY_LOGO_PATH, self::DUMMY_LOGO_NAME); $this->branchRepository->expects($this->once())->method('get')->will($this->returnValue($this->branch)); $this->branch->expects($this->exactly(2))->method('getLogo')->will($this->returnValue($this->logo)); $this->branchLogoHandler->expects($this->once())->method('remove')->with($this->equalTo($this->logo)); $this->branchLogoHandler->expects($this->once())->method('upload')->with($this->equalTo($this->fileMock))->will($this->returnValue($uploadedFile)); $name = 'DUMMY_NAME_UPDT'; $description = 'DUMMY_DESC_UPDT'; $assigneeId = 1; $assignee = new User($assigneeId, User::TYPE_ORO); $defaultAssignee = new OroUser(); $tags = array('autocomplete' => array(), 'all' => array(), 'owner' => array()); $this->branch->expects($this->once())->method('update')->with($this->equalTo($name), $this->equalTo($description), $this->equalTo($defaultAssignee), $this->equalTo(new Logo($uploadedFile->getFilename(), $uploadedFile->getFilename()))); $this->branch->expects($this->once())->method('setTags')->with($this->equalTo($tags)); $this->registry->expects($this->exactly(2))->method('getManager')->will($this->returnValue($this->entityManager)); $this->entityManager->expects($this->once())->method('persist')->with($this->branch); $this->entityManager->expects($this->once())->method('flush'); $this->tagManager->expects($this->once())->method('saveTagging')->with($this->equalTo($this->branch)); $this->authorizationService->expects($this->once())->method('isActionPermitted')->with($this->equalTo('EDIT'), $this->equalTo('Entity:DiamanteDeskBundle:Branch'))->will($this->returnValue(true)); $this->registry->expects($this->once())->method('getRepository')->with($this->equalTo('OroUserBundle:User'))->will($this->returnValue($this->userRepo)); $this->userRepo->expects($this->once())->method('find')->with($this->equalTo($assigneeId))->will($this->returnValue($defaultAssignee)); $command = new BranchCommand(); $command->name = $name; $command->description = $description; $command->defaultAssignee = $assigneeId; $command->logoFile = $this->fileMock; $command->tags = $tags; $this->branchServiceImpl->updateBranch($command); }