public function testCreateTable() { $type_table_build = new TypeTableBuilder($this->structure); $type_table_build->setConnection($this->connection); $stats_snapshots_type = $this->structure->getType('stats_snapshots'); $this->assertInstanceOf(TypeInterface::class, $stats_snapshots_type); $create_table_statement = $type_table_build->prepareCreateTableStatement($stats_snapshots_type); $this->assertContains("`plan_name` VARCHAR(191) AS (`stats`->>'\$.plan_name') STORED", $create_table_statement); $this->assertContains("`number_of_active_users` INT AS (`stats`->>'\$.users.num_active') STORED", $create_table_statement); $this->assertContains("`is_used_on_day` TINYINT(1) UNSIGNED AS (`stats`->>'\$.is_used_on_day') VIRTUAL", $create_table_statement); $this->assertContains('INDEX `plan_name` (`plan_name`)', $create_table_statement); $this->assertNotContains('INDEX `number_of_active_users` (`number_of_active_users`)', $create_table_statement); $this->assertNotContains('INDEX `number_of_active_users` (`number_of_active_users`)', $create_table_statement); }
public function testCreateTable() { $type_table_build = new TypeTableBuilder($this->structure); $type_table_build->setConnection($this->connection); $stats_snapshots_type = $this->structure->getType('stats_snapshots'); $this->assertInstanceOf(TypeInterface::class, $stats_snapshots_type); $create_table_statement = $type_table_build->prepareCreateTableStatement($stats_snapshots_type); $this->assertContains("`plan_name` VARCHAR(191) AS (IF(`stats`->>'\$.plan_name' IS NULL, NULL, `stats`->>'\$.plan_name')) STORED", $create_table_statement); $this->assertContains("`number_of_active_users` INT AS (IF(`stats`->>'\$.users.num_active' IS NULL, NULL, CAST(`stats`->>'\$.users.num_active' AS SIGNED INTEGER))) STORED", $create_table_statement); $this->assertContains("`is_used_on_day` TINYINT(1) UNSIGNED AS (IF(`stats`->>'\$.is_used_on_day' IS NULL, NULL, IF(`stats`->>'\$.is_used_on_day' = 'true' OR (`stats`->>'\$.is_used_on_day' REGEXP '^-?[0-9]+\$' AND CAST(`stats`->>'\$.is_used_on_day' AS SIGNED) != 0), 1, 0))) VIRTUAL", $create_table_statement); $this->assertContains('INDEX `plan_name` (`plan_name`)', $create_table_statement); $this->assertNotContains('INDEX `number_of_active_users` (`number_of_active_users`)', $create_table_statement); $this->assertNotContains('INDEX `number_of_active_users` (`number_of_active_users`)', $create_table_statement); }
/** * {@inheritdoc} */ public function setUp() { parent::setUp(); $this->structure = new JsonFieldStructure(); if (!class_exists("{$this->namespace}\\StatsSnapshot", false)) { $this->structure->build(); } $this->stats_snapshot_class_name = "{$this->namespace}\\StatsSnapshot"; $this->stats_snapshot_base_class_reflection = new ReflectionClass("{$this->namespace}\\Base\\StatsSnapshot"); $this->stats_snapshot_class_reflection = new ReflectionClass($this->stats_snapshot_class_name); $type_table_build = new TypeTableBuilder($this->structure); $type_table_build->setConnection($this->connection); $stats_snapshots_type = $this->structure->getType('stats_snapshots'); $this->assertInstanceOf(TypeInterface::class, $stats_snapshots_type); $create_table_statement = $type_table_build->prepareCreateTableStatement($stats_snapshots_type); $this->connection->execute($create_table_statement); $this->pool = new Pool($this->connection); $this->pool->registerType($this->stats_snapshot_class_name); }