query( 'CREATE TABLE `' . self::POSTS . "` ( ID BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, post_type VARCHAR(20) NOT NULL DEFAULT 'post', PRIMARY KEY (ID) ) ENGINE=InnoDB" ); $wpdb->query( 'CREATE TABLE `' . self::POSTMETA . '` ( meta_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, post_id BIGINT UNSIGNED NOT NULL DEFAULT 0, meta_key VARCHAR(255) DEFAULT NULL, meta_value LONGTEXT, PRIMARY KEY (meta_id) ) ENGINE=InnoDB' ); $wpdb->query( 'CREATE TABLE `' . self::FLAT . '` ( id BIGINT NOT NULL AUTO_INCREMENT, post_id BIGINT NOT NULL, bs_price DECIMAL(18,6) DEFAULT NULL, PRIMARY KEY (id), UNIQUE KEY uk_entity (post_id) ) ENGINE=InnoDB' ); $wpdb->insert( self::POSTS, array( 'ID' => 1, 'post_type' => 'hp_listing' ) ); $wpdb->insert( self::POSTS, array( 'ID' => 2, 'post_type' => 'post' ) ); $wpdb->insert( self::POSTMETA, array( 'post_id' => 1, 'meta_key' => 'bs_price', 'meta_value' => '10' ) ); $wpdb->insert( self::POSTMETA, array( 'post_id' => 2, 'meta_key' => 'bs_price', 'meta_value' => '20' ) ); $wpdb->insert( self::FLAT, array( 'post_id' => 1, 'bs_price' => 10 ) ); $wpdb->insert( self::POSTS, array( 'ID' => 3, 'post_type' => 'hp_listing' ) ); $wpdb->insert( self::FLAT, array( 'post_id' => 3 ) ); $GLOBALS['_wp_options'] = array( 'wpdo_bridge_modes' => array( 'post' => 'dual_write' ) ); $GLOBALS['_wp_cli_items'] = array(); $GLOBALS['_wp_cli_output'] = array(); TMDO_Mode_Manager::reset_cache(); WPDO_Entity_Registry::init(); WPDO_Entity_Registry::register_adapter( 'post', new WPDO_Adapter_Post() ); WPDO_Entity_Registry::register_group( 'post', 'bs_grp', array( array( 'key' => 'bs_price', 'type' => 'decimal' ) ), array( 'post_types' => array( 'hp_listing' ) ) ); } protected function tearDown(): void { self::drop(); WPDO_Entity_Registry::init(); TMDO_Mode_Manager::reset_cache(); } private static function drop(): void { global $wpdb; foreach ( array( self::POSTS, self::POSTMETA, self::FLAT ) as $table ) { $wpdb->query( "DROP TABLE IF EXISTS `{$table}`" ); } } public function test_counts_only_flat_rows_that_hold_a_value_and_posts_of_the_groups_types(): void { ( new TMDO_CLI_V2() )->bridge_status( array(), array() ); $row = array_values( array_filter( $GLOBALS['_wp_cli_items'], static fn( $r ) => 'bs_grp' === $r['group'] ) )[0]; $this->assertSame( 1, $row['flat_rows'] ); $this->assertSame( 1, $row['eav_ids'] ); $this->assertSame( '100%', $row['progress_%'] ); } }