/**
  * Check if command works. Suppose all operations happened in the same second.
  */
 public function testExecuteWithoutTimeDifference()
 {
     // Set last sync date, to now.
     $this->setLastSync(new DateTime('now'), BinlogParser::START_TYPE_DATE);
     $this->importData('ExtractorTest/sample_db_nodelay.sql');
     $commandTester = $this->executeCommand(static::$kernel);
     foreach ($this->shopIds as $shopId) {
         $expectedData = [['type' => ActionTypes::UPDATE, 'document_type' => 'category', 'document_id' => 'cat0', 'status' => '0', 'shop_id' => $shopId], ['type' => ActionTypes::UPDATE, 'document_type' => 'product', 'document_id' => 'art0', 'status' => '0', 'shop_id' => $shopId], ['type' => ActionTypes::CREATE, 'document_type' => 'product', 'document_id' => 'art0', 'status' => '0', 'shop_id' => $shopId], ['type' => ActionTypes::CREATE, 'document_type' => 'product', 'document_id' => 'art2', 'status' => '0', 'shop_id' => $shopId], ['type' => ActionTypes::UPDATE, 'document_type' => 'product', 'document_id' => 'art2', 'status' => '0', 'shop_id' => $shopId], ['type' => ActionTypes::DELETE, 'document_type' => 'product', 'document_id' => 'art1', 'status' => '0', 'shop_id' => $shopId]];
         // Ensure that there is no time difference between records (even though there might be).
         $this->managerMysql->getConnection()->executeQuery("update {$this->managerMysql->getTableName($shopId)} set timestamp=NOW()");
         $storageData = $this->getSyncData(count($expectedData), 0, $shopId);
         $this->assertEquals($expectedData, $storageData);
     }
     $output = $commandTester->getDisplay();
     $this->assertContains('Job finished', $output);
 }
 /**
  * Test possible SQL injection.
  */
 public function testInvalidTableName()
 {
     $tableName = ';SQL injection here';
     $this->setExpectedException('\\InvalidArgumentException', "Invalid table name specified: \"{$tableName}\"");
     $service = new MysqlStorageManager($this->getConnection(), $tableName);
     $service->setContainer($this->getServiceContainer());
     $service->getTableName();
 }
 /**
  * Test if extract is able to add data to the storage for item delete action.
  */
 public function testExtractForDeleteItem()
 {
     $category = 'product';
     $id = 123;
     $timestamp = new DateTime('-1 hour 20 minutes');
     $deleteDiffItem = new DeleteDiffItem();
     $deleteDiffItem->setCategory($category);
     $deleteDiffItem->setItemId($id);
     $deleteDiffItem->setTimestamp($timestamp);
     $this->extractor->extract($deleteDiffItem);
     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::DELETE, 'documentType' => $category, 'documentId' => $id, 'status' => 0]);
         $this->assertTrue(!empty($actual->id));
         $this->assertEquals(ActionTypes::DELETE, $actual->type);
         $this->assertEquals($category, $actual->document_type);
         $this->assertEquals($id, $actual->document_id);
         $this->assertEquals($timestamp, new DateTime($actual->timestamp));
     }
 }
 /**
  * Test possible SQL injection in shop id.
  */
 public function testInvalidShopId()
 {
     $id = '\';inject';
     $this->setExpectedException('InvalidArgumentException', "Shop id \"{$id}\" is invalid.");
     $this->service->getTableName($id);
 }