/** * Test if table is updated properly. */ public function testUpdateTable() { $schemaManager = $this->getConnection()->getSchemaManager(); $tableManager = new TableManager($this->getConnection(), 'jobs_test', ['shop1', 'shop2', 'shop3']); $this->importData('TableManagerTest/tableOutdated.sql'); $tableManager->updateTable(); $updatedTable = $schemaManager->listTableDetails('jobs_test'); $schemaManager->dropTable('jobs_test'); $this->importData('TableManagerTest/tableMultiple.sql'); $this->compareTable($schemaManager->listTableDetails('jobs_test'), $updatedTable); }
/** * Returns table name for specified shop. * * @param int|null $shopId If null will use active shop. * * @throws InvalidArgumentException * * @return string */ public function getTableName($shopId = null) { $tableName = parent::getTableName(); if ($shopId === null) { $shopId = $this->getActiveShopId(); } if (!$this->isShopValid($shopId)) { throw new InvalidArgumentException("Shop id \"{$shopId}\" is invalid."); } $tableName .= '_' . $shopId; try { SqlValidator::validateTableName($tableName); } catch (InvalidArgumentException $e) { throw new InvalidArgumentException("Shop id \"{$shopId}\" is invalid.", 0, $e); } return $tableName; }
/** * Test for createTable() in case of multi shop (expected multiple `status` fields). */ public function testCreateTableMultiShop() { $connection = $this->getConnection(); /** @var AbstractSchemaManager|MockObject $schemaManager */ $schemaManager = $connection->getSchemaManager(); $schemaManager->expects($this->once())->method('createTable')->with($this->callback(function ($table) { /** @var Table $table */ $fieldNames = []; foreach ($table->getColumns() as $column) { $fieldNames[] = $column->getName(); } // Test if expected fields are set. $this->assertContains('status_alpha', $fieldNames); $this->assertContains('status_beta', $fieldNames); return true; })); $service = new TableManager($connection, 'test_table_name', ['alpha', 'beta']); $this->assertTrue($service->createTable()); }