8fc1dc1f1c
- Seed a HivePress-shaped dataset three ways (native meta, entity tables, hot table) with flat tables built by TMDO's own schema code - Refuse any database not named *_bench before the bootstrap connects; bootstrap now honours a pre-defined ABSPATH for the wp-admin stub - Full scale seeds 9.5M postmeta rows in 7m25s; 0 value mismatches Verify: TMDO_TEST_DB_NAME=wp_wpdo_bench php tests/bench/seed.php --vendors=100000 --listings=1000000; unit 600 OK, integration 416 OK PR: PR-004
85 lines
2.9 KiB
PHP
85 lines
2.9 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
require_once dirname( __DIR__ ) . '/bench/class-tmdo-bench-seeder.php';
|
|
|
|
/**
|
|
* Unit test: TMDO_Bench_Seeder guards and deterministic generators.
|
|
*
|
|
* The seeder drops and rebuilds tables, so the database-name guard is the
|
|
* only thing standing between it and a production database.
|
|
*/
|
|
class BenchSeederTest extends TestCase {
|
|
|
|
/**
|
|
* @dataProvider rejected_db_names
|
|
*/
|
|
public function test_rejects_non_bench_databases( string $name ): void {
|
|
$this->expectException( InvalidArgumentException::class );
|
|
TMDO_Bench_Seeder::assert_bench_db( $name );
|
|
}
|
|
|
|
public static function rejected_db_names(): array {
|
|
return array(
|
|
'production site' => array( 'wp_2meet_pro_dev21' ),
|
|
'integration db' => array( 'wp_wpdo_test' ),
|
|
'bench not suffix' => array( 'wp_bench_prod' ),
|
|
'empty' => array( '' ),
|
|
'injection' => array( 'x_bench`; DROP DATABASE y; -- _bench' ),
|
|
);
|
|
}
|
|
|
|
public function test_accepts_bench_database(): void {
|
|
TMDO_Bench_Seeder::assert_bench_db( 'wp_wpdo_bench' );
|
|
$this->addToAssertionCount( 1 );
|
|
}
|
|
|
|
public function test_count_bounds(): void {
|
|
TMDO_Bench_Seeder::assert_count( 'listings', TMDO_Bench_Seeder::MAX_ROWS );
|
|
$this->addToAssertionCount( 1 );
|
|
|
|
foreach ( array( 0, -5, TMDO_Bench_Seeder::MAX_ROWS + 1 ) as $bad ) {
|
|
try {
|
|
TMDO_Bench_Seeder::assert_count( 'listings', $bad );
|
|
$this->fail( "Accepted out-of-range count {$bad}" );
|
|
} catch ( InvalidArgumentException $e ) {
|
|
$this->addToAssertionCount( 1 );
|
|
}
|
|
}
|
|
}
|
|
|
|
public function test_generators_are_deterministic_per_seed(): void {
|
|
$a = new TMDO_Bench_Seeder( null, 'wp_itest_', 100, 1000, 42 );
|
|
$b = new TMDO_Bench_Seeder( null, 'wp_itest_', 100, 1000, 42 );
|
|
$c = new TMDO_Bench_Seeder( null, 'wp_itest_', 100, 1000, 7 );
|
|
|
|
$this->assertSame( $a->listing_meta( 123, 5 ), $b->listing_meta( 123, 5 ) );
|
|
$this->assertSame( $a->vendor_meta( 9 ), $b->vendor_meta( 9 ) );
|
|
$this->assertNotSame( $a->listing_meta( 123, 5 ), $c->listing_meta( 123, 5 ) );
|
|
}
|
|
|
|
public function test_listing_distribution_matches_spec(): void {
|
|
$seeder = new TMDO_Bench_Seeder( null, 'wp_itest_', 1000, 10000 );
|
|
$statuses = array();
|
|
$featured = 0;
|
|
|
|
for ( $i = 1; $i <= 10000; $i++ ) {
|
|
$vendor = $seeder->listing_vendor( $i );
|
|
$this->assertGreaterThanOrEqual( 1, $vendor );
|
|
$this->assertLessThanOrEqual( 1000, $vendor );
|
|
|
|
$meta = $seeder->listing_meta( $i, $vendor );
|
|
$statuses[ $meta['hp_status'] ] = ( $statuses[ $meta['hp_status'] ] ?? 0 ) + 1;
|
|
$featured += $meta['hp_featured'];
|
|
$this->assertSame( (bool) $meta['hp_featured'], isset( $meta['hp_featured_time'] ) );
|
|
}
|
|
|
|
ksort( $statuses );
|
|
$this->assertSame( array( 'draft', 'pending', 'private', 'publish' ), array_keys( $statuses ) );
|
|
$this->assertEqualsWithDelta( 9000, $statuses['publish'], 300 );
|
|
$this->assertEqualsWithDelta( 500, $featured, 100 );
|
|
}
|
|
}
|