public function testIsActive() { $entity = new TestEmailOrigin(); // check that true by default $this->assertTrue($entity->getIsActive()); // check setter $entity->setIsActive(false); $this->assertFalse($entity->getIsActive()); }
public function testPersonalOrigin() { $origin1 = new TestEmailOrigin(1); $origin1->setMailboxName('testName1'); $folder1 = new TestEmailFolder(1); $folder2 = new TestEmailFolder(2); $folder3 = new TestEmailFolder(3); $folder1->setFullName('Folder1'); $folder1->setSyncEnabled(true); $folder2->setFullName('Folder2'); $folder2->setSyncEnabled(true); $folder3->setFullName('Folder - disabled'); $origin1->addFolder($folder1); $origin1->addFolder($folder2); $origin1->addFolder($folder3); $origin2 = new TestEmailOrigin(2); $origin2->setMailboxName('testName2'); $origin2->setActive(false); $folder3 = new TestEmailFolder(3); $folder3->setSyncEnabled(true); $folder3->setFullName('Folder3'); $origin2->addFolder($folder3); $this->doctrine->expects($this->any())->method('getRepository')->will($this->returnValue($this->originRepository)); $this->originRepository->expects($this->once())->method('findBy')->willReturn([$origin1, $origin2]); $this->originRepository->expects($this->once())->method('findAvailableMailboxes')->willReturn([]); $result = $this->originFolderFilterProvider->getListTypeChoices(); $this->assertNotEmpty($result); $this->assertCount(2, $result); $this->assertEquals($origin1->isActive(), $result[$origin1->getMailboxName()]['active']); $this->assertEquals($origin2->isActive(), $result[$origin2->getMailboxName()]['active']); $this->assertCount(2, $result[$origin1->getMailboxName()]['folder']); $this->assertCount(1, $result[$origin2->getMailboxName()]['folder']); $this->assertEquals($folder2->getFullName(), $result[$origin1->getMailboxName()]['folder'][$folder2->getId()]); }
/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testFindOriginToSync() { $maxConcurrentTasks = 2; $minExecPeriodInMin = 1; $now = new \DateTime('now', new \DateTimeZone('UTC')); $border = clone $now; if ($minExecPeriodInMin > 0) { $border->sub(new \DateInterval('PT' . $minExecPeriodInMin . 'M')); } $min = clone $now; $min->sub(new \DateInterval('P1Y')); $q = $this->getMockBuilder('Doctrine\\ORM\\AbstractQuery')->disableOriginalConstructor()->setMethods(array('getResult'))->getMockForAbstractClass(); $qb = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock(); $repo = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock(); $repo->expects($this->once())->method('createQueryBuilder')->with('o')->will($this->returnValue($qb)); $index = 0; $qb->expects($this->at($index++))->method('select')->with('o' . ', CASE WHEN o.syncCode = :inProcess THEN 0 ELSE 1 END AS HIDDEN p1' . ', (COALESCE(o.syncCode, 1000) * 30' . ' + TIMESTAMPDIFF(MINUTE, COALESCE(o.syncCodeUpdatedAt, :min), :now)' . ' / (CASE o.syncCode WHEN :success THEN 100 ELSE 1 END)) AS HIDDEN p2')->will($this->returnValue($qb)); $qb->expects($this->at($index++))->method('where')->with('o.isActive = :isActive AND (o.syncCodeUpdatedAt IS NULL OR o.syncCodeUpdatedAt <= :border)')->will($this->returnValue($qb)); $qb->expects($this->at($index++))->method('orderBy')->with('p1, p2 DESC, o.syncCodeUpdatedAt')->will($this->returnValue($qb)); $qb->expects($this->at($index++))->method('setParameter')->with('inProcess', AbstractEmailSynchronizer::SYNC_CODE_IN_PROCESS)->will($this->returnValue($qb)); $qb->expects($this->at($index++))->method('setParameter')->with('success', AbstractEmailSynchronizer::SYNC_CODE_SUCCESS)->will($this->returnValue($qb)); $qb->expects($this->at($index++))->method('setParameter')->with('isActive', true)->will($this->returnValue($qb)); $qb->expects($this->at($index++))->method('setParameter')->with('now', $this->equalTo($now))->will($this->returnValue($qb)); $qb->expects($this->at($index++))->method('setParameter')->with('min', $this->equalTo($min))->will($this->returnValue($qb)); $qb->expects($this->at($index++))->method('setParameter')->with('border', $this->equalTo($border))->will($this->returnValue($qb)); $qb->expects($this->at($index++))->method('setMaxResults')->with($maxConcurrentTasks + 1)->will($this->returnValue($qb)); $qb->expects($this->at($index++))->method('getQuery')->will($this->returnValue($q)); $origin1 = new TestEmailOrigin(1); $origin1->setSyncCode(AbstractEmailSynchronizer::SYNC_CODE_IN_PROCESS); $origin2 = new TestEmailOrigin(2); $origin2->setSyncCode(AbstractEmailSynchronizer::SYNC_CODE_SUCCESS); $origin3 = new TestEmailOrigin(3); $q->expects($this->once())->method('getResult')->will($this->returnValue(array($origin1, $origin2, $origin3))); $this->em->expects($this->once())->method('getRepository')->with(TestEmailSynchronizer::EMAIL_ORIGIN_ENTITY)->will($this->returnValue($repo)); $this->sync->setCurrentUtcDateTime($now); $result = $this->sync->callFindOriginToSync($maxConcurrentTasks, $minExecPeriodInMin); $this->assertEquals($origin2, $result); }