/**
  * Test extraction service to insert updates to SyncStorage.
  *
  * @throws \Doctrine\DBAL\DBALException
  */
 public function testExtract()
 {
     $container = $this->getServiceContainer();
     /** @var \ONGR\ConnectionsBundle\Sync\Extractor\DoctrineExtractor $extractor */
     $extractor = $container->get('ongr_connections.sync.extractor.doctrine_extractor');
     // Populate database with schema and data.
     $this->importData('ExtractorTest/sample_db.sql');
     // Get storage mock.
     /** @var SyncStorageInterface|\PHPUnit_Framework_MockObject_MockObject $dummySyncStorage */
     $dummySyncStorage = $this->getMock('\\ONGR\\ConnectionsBundle\\Sync\\SyncStorage\\SyncStorageInterface');
     $dummySyncStorage->expects($this->exactly(7))->method('save')->withConsecutive([ActionTypes::UPDATE, 'product', 'art0', $this->isInstanceOf('\\DateTime')], [ActionTypes::UPDATE, 'product', 'art1', $this->isInstanceOf('\\DateTime')], [ActionTypes::UPDATE, 'category', 'cat0', $this->isInstanceOf('\\DateTime')], [ActionTypes::UPDATE, 'product', 'art0', $this->isInstanceOf('\\DateTime')], [ActionTypes::UPDATE, 'product', 'art1', $this->isInstanceOf('\\DateTime')], [ActionTypes::UPDATE, 'product', 'art0', $this->isInstanceOf('\\DateTime')], [ActionTypes::UPDATE, 'product', 'art1', $this->isInstanceOf('\\DateTime')]);
     $extractor->setStorageFacility($dummySyncStorage);
     // Execute.
     // Should not make any save calls because Category CREATE action is turned off.
     $item = new CreateDiffItem();
     $item->setCategory('oxcategories');
     $item->setItem(['OXID' => 'cat0', 'OXTITLE' => 'Category']);
     $item->setTimestamp(new \DateTime());
     $extractor->extract($item);
     // Should save 2 products but not category.
     $item = new UpdateDiffItem();
     $item->setCategory('oxcategories');
     $item->setItem(['OXID' => 'cat0', 'OXTITLE' => 'Category']);
     $item->setOldItem(['OXID' => 'cat0', 'OXTITLE' => 'Category']);
     $item->setTimestamp(new \DateTime());
     $extractor->extract($item);
     // Should make 5 save calls.
     $item->setItem(['OXID' => 'cat0', 'OXTITLE' => 'CategoryNew']);
     $extractor->extract($item);
 }
 /**
  * Test if extract is able to add data to the storage for item create action.
  */
 public function testExtractForCreateItem()
 {
     $category = 'product';
     $id = 123;
     $timestamp = new DateTime('-1 hour 20 minutes');
     $createDiffItem = new CreateDiffItem();
     $createDiffItem->setCategory($category);
     $createDiffItem->setItemId($id);
     $createDiffItem->setTimestamp($timestamp);
     $this->extractor->extract($createDiffItem);
     foreach ($this->shopIds as $shopId) {
         $actual = (object) $this->getConnection()->fetchAssoc('SELECT * FROM ' . $this->storageManager->getTableName($shopId) . ' WHERE
                 `type` = :operationType
                 AND `document_type` = :documentType
                 AND `document_id` = :documentId
                 AND `status` = :status', ['operationType' => ActionTypes::CREATE, 'documentType' => $category, 'documentId' => $id, 'status' => 0]);
         $this->assertTrue(!empty($actual->id));
         $this->assertEquals(ActionTypes::CREATE, $actual->type);
         $this->assertEquals($category, $actual->document_type);
         $this->assertEquals($id, $actual->document_id);
         $this->assertEquals($timestamp, new DateTime($actual->timestamp));
     }
 }
 /**
  * Test invalid argument.
  */
 public function testInvalidArgument()
 {
     $diffItem = new CreateDiffItem();
     $diffItem->setCategory('some-category');
     $diffItem->setTimestamp(new \DateTime());
     $this->storage->expects($this->never())->method('save');
     $this->setExpectedException('InvalidArgumentException', 'No valid item ID provided.');
     $this->service->extract($diffItem);
 }