/** * @test */ public function synchronizeHandlesHigherSourceIdInQueueComparisonByCreatingObject() { $idOfSourceObject = 2; $sourceObject = new ObjectDummy(); $this->setUpSourceToReturn(new \ArrayIterator(array($sourceObject))); $idOfDestinationObject = 1; $destinationObject = new ObjectDummy(); $this->setUpDestinationToReturn(new \ArrayIterator(array($destinationObject))); $this->source->expects($this->any(0))->method('idOf')->will($this->returnValue($idOfSourceObject)); $this->destination->expects($this->any())->method('idOf')->will($this->returnValue($idOfDestinationObject)); $this->destination->expects($this->once())->method('delete')->with($destinationObject); $this->synchronizer->synchronize($this->type, function () use($destinationObject) { return Result::changed($destinationObject); }); }
/** * @test */ public function indexHandlesUpdatedObjects() { $idOfNewSourceObject = 1; $newSourceObject = new ObjectDummy(); $this->setUpSourceToReturn(new \ArrayIterator(array($newSourceObject))); $this->source->expects($this->any())->method('idOf')->will($this->returnValue($idOfNewSourceObject)); $this->source->expects($this->once())->method('statusOf')->will($this->returnValue(Adapter\IndexableObjectProvider::STATUS_UPDATE)); $newlyCreatedObject = new \stdClass(); $this->destination->expects($this->once())->method('createObject')->with($idOfNewSourceObject, $this->type)->will($this->returnValue($newlyCreatedObject)); $this->destination->expects($this->once())->method('updated')->with($newlyCreatedObject); // afterObjectProcessed() called for every object $this->destination->expects($this->once())->method('afterObjectProcessed'); $this->destination->expects($this->once())->method('commit'); $this->indexer->index($this->type, function ($src, $dest) { return Result::changed($dest); }); }