/** * Test storage creation (when table does not exist). */ public function testCreateStorageTableDoesNotExist() { $shopId = 0; $schemaManager = $this->getMockBuilder('\\Doctrine\\DBAL\\Schema\\AbstractSchemaManager')->disableOriginalConstructor()->setMethods(['_getPortableTableColumnDefinition', 'tablesExist', 'createTable'])->getMock(); $schemaManager->expects($this->any())->method('_getPortableTableColumnDefinition'); $schemaManager->expects($this->once())->method('tablesExist')->with([self::TABLE_NAME . '_' . $shopId])->will($this->returnValue(false)); $table = $this->buildStorageTable(self::TABLE_NAME . '_' . $shopId); $schemaManager->expects($this->once())->method('createTable')->with($table); $this->connection->expects($this->once())->method('getSchemaManager')->will($this->returnValue($schemaManager)); $result = $this->service->createStorage($shopId); $this->assertTrue($result); }
/** * Clear logs before each test. */ public function setUp() { parent::setUp(); $this->getServiceContainer()->get('es.manager')->getConnection()->dropAndCreateIndex(); $this->getConnection()->executeQuery('RESET MASTER'); /** @var MysqlStorageManager $managerMysql */ $this->managerMysql = $this->getServiceContainer()->get('ongr_connections.sync.storage_manager.mysql_storage_manager'); $shops = $this->getServiceContainer()->getParameter('ongr_connections.shops'); foreach ($shops as $shop) { $this->shopIds[] = $shop['shop_id']; $this->managerMysql->createStorage($shop['shop_id']); } }
/** * Setup services for tests. */ protected function setUp() { parent::setUp(); $this->storageManager = new MysqlStorageManager($this->getConnection(), self::TABLE_NAME); $this->storageManager->setContainer($this->getServiceContainer()); $this->syncStorage = new SyncStorage($this->storageManager); $this->extractor = new PassthroughExtractor(); $this->extractor->setContainer($this->getServiceContainer()); $this->extractor->setStorageFacility($this->syncStorage); $shops = $this->getServiceContainer()->getParameter('ongr_connections.shops'); foreach ($shops as $shop) { $this->shopIds[] = $shop['shop_id']; $this->storageManager->createStorage($shop['shop_id']); } }
/** * Check actions deduction. */ public function testMeaninglessModifications() { $processedRecords = [(object) ['operationType' => ActionTypes::CREATE, 'documentType' => 'product', 'documentId' => 401, 'dateTime' => new DateTime('now')], (object) ['operationType' => ActionTypes::CREATE, 'documentType' => 'product', 'documentId' => 402, 'dateTime' => new DateTime('now')], (object) ['operationType' => ActionTypes::CREATE, 'documentType' => 'product', 'documentId' => 403, 'dateTime' => new DateTime('now')], (object) ['operationType' => ActionTypes::UPDATE, 'documentType' => 'product', 'documentId' => 401, 'dateTime' => new DateTime('now')], (object) ['operationType' => ActionTypes::UPDATE, 'documentType' => 'product', 'documentId' => 402, 'dateTime' => new DateTime('now')], (object) ['operationType' => ActionTypes::DELETE, 'documentType' => 'product', 'documentId' => 401, 'dateTime' => new DateTime('now')], (object) ['operationType' => ActionTypes::CREATE, 'documentType' => 'product', 'documentId' => 401, 'dateTime' => new DateTime('now')], (object) ['operationType' => ActionTypes::UPDATE, 'documentType' => 'product', 'documentId' => 402, 'dateTime' => new DateTime('now')]]; $expectedRecords = [['id' => '2', 'type' => 'C', 'document_type' => 'product', 'document_id' => '402', 'status' => '0'], ['id' => '3', 'type' => 'C', 'document_type' => 'product', 'document_id' => '403', 'status' => '0'], ['id' => '5', 'type' => 'U', 'document_type' => 'product', 'document_id' => '402', 'status' => '0'], ['id' => '6', 'type' => 'D', 'document_type' => 'product', 'document_id' => '401', 'status' => '0'], ['id' => '7', 'type' => 'C', 'document_type' => 'product', 'document_id' => '401', 'status' => '0']]; $this->service->createStorage(); $this->addRecords($processedRecords); $actualyRecords = $this->getConnection()->fetchAll('SELECT * FROM `' . self::TABLE_NAME . '_0` WHERE `document_type` = :documentType', ['documentType' => 'product']); $this->compareRecords($expectedRecords, $actualyRecords, true); }