public function testResetHangedOrigins() { $now = new \DateTime('now', new \DateTimeZone('UTC')); $border = clone $now; $border->sub(new \DateInterval('P1D')); $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', ':failure')->will($this->returnValue($qb)); $qb->expects($this->at($index++))->method('where')->with('o.syncCode = :inProcess AND o.syncCodeUpdatedAt <= :border')->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('failure', AbstractEmailSynchronizer::SYNC_CODE_FAILURE)->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('getQuery')->will($this->returnValue($q)); $q->expects($this->once())->method('execute'); $this->em->expects($this->once())->method('getRepository')->with(TestEmailSynchronizer::EMAIL_ORIGIN_ENTITY)->will($this->returnValue($repo)); $this->sync->setCurrentUtcDateTime($now); $this->sync->callResetHangedOrigins(); }