/** * @dataProvider changeOriginSyncStateProvider */ public function testChangeOriginSyncState($syncCode, $hasSynchronizedAt) { $now = new \DateTime('now', new \DateTimeZone('UTC')); $origin = new TestEmailOrigin(123); $q = $this->getMockBuilder('Doctrine\\ORM\\AbstractQuery')->disableOriginalConstructor()->setMethods(array('execute'))->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('update')->will($this->returnValue($qb)); $qb->expects($this->at($index++))->method('set')->with('o.syncCode', ':code')->will($this->returnValue($qb)); $qb->expects($this->at($index++))->method('set')->with('o.syncCodeUpdatedAt', ':updated')->will($this->returnValue($qb)); $qb->expects($this->at($index++))->method('where')->with('o.id = :id')->will($this->returnValue($qb)); $qb->expects($this->at($index++))->method('setParameter')->with('code', $syncCode)->will($this->returnValue($qb)); $qb->expects($this->at($index++))->method('setParameter')->with('updated', $this->equalTo($now))->will($this->returnValue($qb)); $qb->expects($this->at($index++))->method('setParameter')->with('id', $origin->getId())->will($this->returnValue($qb)); if ($hasSynchronizedAt) { $qb->expects($this->at($index++))->method('set')->with('o.synchronizedAt', ':synchronized')->will($this->returnValue($qb)); $qb->expects($this->at($index++))->method('setParameter')->with('synchronized', $now)->will($this->returnValue($qb)); } if ($syncCode === AbstractEmailSynchronizer::SYNC_CODE_IN_PROCESS) { $qb->expects($this->at($index++))->method('andWhere')->with('(o.syncCode IS NULL OR o.syncCode <> :code)')->will($this->returnValue($qb)); } if ($syncCode === AbstractEmailSynchronizer::SYNC_CODE_SUCCESS) { $qb->expects($this->at($index++))->method('set')->with('o.syncCount', 'o.syncCount + 1')->will($this->returnValue($qb)); } $qb->expects($this->at($index++))->method('getQuery')->will($this->returnValue($q)); $q->expects($this->once())->method('execute')->will($this->returnValue(1)); $this->em->expects($this->once())->method('getRepository')->with(TestEmailSynchronizer::EMAIL_ORIGIN_ENTITY)->will($this->returnValue($repo)); $this->sync->setCurrentUtcDateTime($now); $result = $this->sync->callChangeOriginSyncState($origin, $syncCode, $hasSynchronizedAt ? $now : null); $this->assertTrue($result); }