/** * Set up test environment. */ public function setUp() { parent::setUp(); $this->pool = new Pool($this->connection); $this->position_context_structure = new PositionContextStructure(); if (!class_exists($this->head_type_class_name, false) && !class_exists($this->tail_type_class_name, false)) { $this->position_context_structure->build(null, $this->connection); } if ($this->connection->tableExists('position_context_head_entries')) { $this->connection->dropTable('position_context_head_entries'); } if ($this->connection->tableExists('position_context_tail_entries')) { $this->connection->dropTable('position_context_tail_entries'); } $type_table_builder = new TypeTableBuilder($this->position_context_structure); $type_table_builder->setConnection($this->connection); $type_table_builder->buildType($this->position_context_structure->getType('position_context_head_entries')); $type_table_builder->buildType($this->position_context_structure->getType('position_context_tail_entries')); $this->assertTrue($this->connection->tableExists('position_context_head_entries')); $this->assertTrue($this->connection->tableExists('position_context_tail_entries')); $this->pool->registerType($this->head_type_class_name); $this->pool->registerType($this->tail_type_class_name); $this->assertTrue($this->pool->isTypeRegistered($this->head_type_class_name)); $this->assertTrue($this->pool->isTypeRegistered($this->tail_type_class_name)); }
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); }
/** * Set up test environment. */ public function setUp() { parent::setUp(); $this->pool = new Pool($this->connection); $this->json_serialization_structure = new JsonSerializationStructure(); if (!class_exists($this->type_class_name, false)) { $this->json_serialization_structure->build(null, $this->connection); } if ($this->connection->tableExists('key_values')) { $this->connection->dropTable('key_values'); } $type_table_builder = new TypeTableBuilder($this->json_serialization_structure); $type_table_builder->setConnection($this->connection); $type_table_builder->buildType($this->json_serialization_structure->getType('key_values')); $this->assertTrue($this->connection->tableExists('key_values')); $this->pool->registerType($this->type_class_name); $this->assertTrue($this->pool->isTypeRegistered($this->type_class_name)); }
/** * {@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); }