/**
  * Tests that a source is scheduled for processing if it's unlinked.
  */
 public function testScheduleSourceProcessOnSourceUnlinked()
 {
     $this->listener->expects($this->once())->method('isSourceModified')->will($this->returnValue(false));
     $this->sourceProcessor->expects($this->once())->method('isLinked')->will($this->returnValue(false));
     $this->eventDispatcher->expects($this->once())->method('dispatch')->with($this->equalTo(IoEvents::SOURCE_PROCESS));
     $this->listener->onFlush($this->getOnFlushEventArgs(new SourceMock(12345)));
     $this->listener->postFlush(new PostFlushEventArgs($this->entityManager));
 }
 /**
  * @param OnFlushEventArgs $args
  */
 public function onFlush(OnFlushEventArgs $args)
 {
     $uow = $args->getEntityManager()->getUnitOfWork();
     $entities = array_merge($uow->getScheduledEntityInsertions(), $uow->getScheduledEntityUpdates());
     // remember sources that are to be updated
     foreach ($entities as $entity) {
         if (!$entity instanceof SourceInterface) {
             continue;
         }
         $modified = $this->isSourceModified($entity, $uow);
         // update modification date when it's modified
         if ($modified) {
             $this->setSourceModificationDate($entity, $uow);
         }
         if ($modified || !$this->sourceProcessor->isLinked($entity)) {
             $this->sources[] = $entity;
         }
     }
 }
 public function testProcess()
 {
     $this->processor1->expects($this->any())->method('supports')->will($this->returnValue(true));
     $this->processor1->expects($this->any())->method('isLinked')->will($this->returnValue(true));
     $this->processor1->expects($this->once())->method('process');
     $this->processor2->expects($this->any())->method('supports')->will($this->returnValue(true));
     $this->processor2->expects($this->any())->method('isLinked')->will($this->returnValue(true));
     $this->processor2->expects($this->once())->method('process');
     $this->delegate->process(new SourceMock(123));
 }
 public function testProcessException()
 {
     $executor = new SourceProcessExecutor($this->manager, $this->processor, new NullLogger());
     $source = new SourceMock(12345);
     $this->manager->expects($this->once())->method('findById')->will($this->returnValue($source));
     $this->processor->expects($this->once())->method('isLinked')->will($this->returnValue(false));
     $this->processor->expects($this->once())->method('process')->will($this->throwException(new SourceProcessException('Foobar')));
     $this->assertFalse($executor->execute($this->getPayload($executor, $source)));
     $messages = $source->getMessages();
     $this->assertInternalType('array', $messages);
     $this->assertArrayHasKey('process', $messages);
     $this->assertArrayHasKey(LogLevel::ERROR, $messages['process']);
     $this->assertContains('Foobar', $messages['process'][LogLevel::ERROR]);
 }