3 declare(strict_types
=1);
5 namespace PhpMyAdmin\Tests
;
8 use PhpMyAdmin\Dbal\DatabaseInterface
;
9 use PhpMyAdmin\Engines\Bdb
;
10 use PhpMyAdmin\Engines\Berkeleydb
;
11 use PhpMyAdmin\Engines\Binlog
;
12 use PhpMyAdmin\Engines\Innobase
;
13 use PhpMyAdmin\Engines\Innodb
;
14 use PhpMyAdmin\Engines\Memory
;
15 use PhpMyAdmin\Engines\Merge
;
16 use PhpMyAdmin\Engines\MrgMyisam
;
17 use PhpMyAdmin\Engines\Myisam
;
18 use PhpMyAdmin\Engines\Ndbcluster
;
19 use PhpMyAdmin\Engines\Pbxt
;
20 use PhpMyAdmin\Engines\PerformanceSchema
;
21 use PhpMyAdmin\StorageEngine
;
22 use PhpMyAdmin\Tests\Stubs\DbiDummy
;
23 use PHPUnit\Framework\Attributes\CoversClass
;
24 use PHPUnit\Framework\Attributes\DataProvider
;
26 use function json_encode
;
28 #[CoversClass(StorageEngine::class)]
29 class StorageEngineTest
extends AbstractTestCase
31 protected DatabaseInterface
$dbi;
33 protected DbiDummy
$dummyDbi;
35 protected StorageEngine
$object;
38 * Sets up the fixture, for example, opens a network connection.
39 * This method is called before a test is executed.
41 protected function setUp(): void
45 $this->dummyDbi
= $this->createDbiDummy();
46 $this->dbi
= $this->createDatabaseInterface($this->dummyDbi
);
47 DatabaseInterface
::$instance = $this->dbi
;
48 $this->object = new StorageEngine('dummy');
52 * Tears down the fixture, for example, closes a network connection.
53 * This method is called after a test is executed.
55 protected function tearDown(): void
62 public function testGetStorageEngines(): void
66 'dummy' => ['Engine' => 'dummy', 'Support' => 'YES', 'Comment' => 'dummy comment'],
67 'dummy2' => ['Engine' => 'dummy2', 'Support' => 'NO', 'Comment' => 'dummy2 comment'],
69 'Engine' => 'FEDERATED',
71 'Comment' => 'Federated MySQL storage engine',
73 'Pbxt' => ['Engine' => 'Pbxt', 'Support' => 'NO', 'Comment' => 'Pbxt storage engine'],
75 StorageEngine
::getStorageEngines(),
79 public function testGetArray(): void
81 $actual = StorageEngine
::getArray();
84 ['dummy' => ['name' => 'dummy', 'comment' => 'dummy comment', 'is_default' => false]],
90 * Test for StorageEngine::getEngine
92 * @param string $expectedClass Class that should be selected
93 * @param string $engineName Engine name
94 * @psalm-param class-string $expectedClass
96 #[DataProvider('providerGetEngine')]
97 public function testGetEngine(string $expectedClass, string $engineName): void
99 $actual = StorageEngine
::getEngine($engineName);
100 self
::assertInstanceOf($expectedClass, $actual);
104 * Provider for testGetEngine
108 public static function providerGetEngine(): array
111 [StorageEngine
::class, 'unknown engine'],
113 [Berkeleydb
::class, 'Berkeleydb'],
114 [Binlog
::class, 'Binlog'],
115 [Innobase
::class, 'Innobase'],
116 [Innodb
::class, 'Innodb'],
117 [Memory
::class, 'Memory'],
118 [Merge
::class, 'Merge'],
119 [MrgMyisam
::class, 'Mrg_Myisam'],
120 [Myisam
::class, 'Myisam'],
121 [Ndbcluster
::class, 'Ndbcluster'],
122 [Pbxt
::class, 'Pbxt'],
123 [PerformanceSchema
::class, 'Performance_Schema'],
130 public function testIsValid(): void
133 StorageEngine
::isValid('PBMS'),
136 StorageEngine
::isValid('dummy'),
139 StorageEngine
::isValid('dummy2'),
142 StorageEngine
::isValid('invalid'),
149 public function testGetPage(): void
153 $this->object->getPage('Foo'),
158 * Test for getInfoPages
160 public function testGetInfoPages(): void
164 $this->object->getInfoPages(),
169 * Test for getVariablesLikePattern
171 public function testGetVariablesLikePattern(): void
175 $this->object->getVariablesLikePattern(),
180 * Test for getMysqlHelpPage
182 public function testGetMysqlHelpPage(): void
185 'dummy-storage-engine',
186 $this->object->getMysqlHelpPage(),
191 * Test for getVariables
193 public function testGetVariables(): void
197 $this->object->getVariables(),
202 * Test for getSupportInformationMessage
204 public function testGetSupportInformationMessage(): void
207 'dummy is available on this MySQL server.',
208 $this->object->getSupportInformationMessage(),
211 $this->object->support
= 1;
213 'dummy has been disabled for this MySQL server.',
214 $this->object->getSupportInformationMessage(),
217 $this->object->support
= 2;
219 'dummy is available on this MySQL server.',
220 $this->object->getSupportInformationMessage(),
223 $this->object->support
= 3;
225 'dummy is the default storage engine on this MySQL server.',
226 $this->object->getSupportInformationMessage(),
231 * Test for getComment
233 public function testGetComment(): void
237 $this->object->getComment(),
244 public function testGetTitle(): void
248 $this->object->getTitle(),
253 * Test for resolveTypeSize
255 public function testResolveTypeSize(): void
259 $this->object->resolveTypeSize(12),
263 public function testHasMroongaEngine(): void
265 $this->dummyDbi
->addResult('SELECT mroonga_command(\'object_list\');', [
267 (string) json_encode([]), // Fake result
270 self
::assertTrue(StorageEngine
::hasMroongaEngine());
271 self
::assertTrue(StorageEngine
::hasMroongaEngine()); // Does not call any query
273 Cache
::remove('storage-engine.mroonga.has.mroonga_command'); // Cache clear
275 $this->dummyDbi
->addResult('SELECT mroonga_command(\'object_list\');', false);
276 self
::assertFalse(StorageEngine
::hasMroongaEngine());
278 $this->dummyDbi
->assertAllQueriesConsumed();
281 public function testGetMroongaLengths(): void
283 $this->dummyDbi
->addResult('SELECT mroonga_command(\'object_list\');', [
286 (string) json_encode([
289 'name' => 'WGS84GeoPoint',
292 'type' => ['id' => 32, 'name' => 'type'],
293 'flags' => ['value' => 24, 'names' => 'KEY_GEO_POINT'],
297 'mroonga_operations' => ['type' => ['id' => 51, 'name' => 'table:no_key']],
298 'mroonga_operations.type' => ['type' => ['id' => 65, 'name' => 'column:var_size']],
299 'mroonga_operations.table' => ['type' => ['id' => 65, 'name' => 'column:var_size']],
300 'mroonga_operations.record' => ['type' => ['id' => 64, 'name' => 'column:fix_size']],
301 'idx_correo' => ['type' => ['id' => 49, 'name' => 'table:pat_key']],
302 'idx_correo.id' => ['type' => ['id' => 64, 'name' => 'column:fix_size']],
303 'idx_correo.search' => ['type' => ['id' => 65, 'name' => 'column:var_size']],
304 'idx_correo#idx_correo_search' => ['type' => ['id' => 49, 'name' => 'table:pat_key']],
305 'idx_correo#idx_correo_search.index' => ['type' => ['id' => 72, 'name' => 'column:index']],
309 $this->dummyDbi
->addResult('SELECT mroonga_command(\'object_inspect idx_correo\');', [
312 (string) json_encode([
314 'name' => 'idx_correo',
315 'type' => ['id' => 49, 'name' => 'table:pat_key'],
317 'type' => ['id' => 8, 'name' => 'Int32', 'type' => ['id' => 32,'name' => 'type'], 'size' => 4],
319 'max_total_size' => 4294967294,
321 'value' => ['type' => null],
323 'disk_usage' => 4243456,
327 $this->dummyDbi
->addResult('SELECT mroonga_command(\'object_inspect idx_correo.id\');', [
330 (string) json_encode([
335 'name' => 'idx_correo',
336 'type' => ['id' => 49, 'name' => 'table:pat_key'],
341 'type' => ['id' => 32, 'name' => 'type'],
345 'max_total_size' => 4294967294,
347 'value' => ['type' => null],
349 'disk_usage' => 4243456,
351 'full_name' => 'idx_correo.id',
352 'type' => ['name' => 'scalar', 'raw' => ['id' => 64, 'name' => 'column:fix_size']],
354 'type' => ['id' => 8, 'name' => 'Int32', 'type' => ['id' => 32,'name' => 'type'], 'size' => 4],
357 'disk_usage' => 4096,
361 $this->dummyDbi
->addResult('SELECT mroonga_command(\'object_inspect idx_correo.search\');', [
364 (string) json_encode([
369 'name' => 'idx_correo',
370 'type' => ['id' => 49, 'name' => 'table:pat_key'],
375 'type' => ['id' => 32, 'name' => 'type'],
379 'max_total_size' => 4294967294,
381 'value' => ['type' => null],
383 'disk_usage' => 4243456,
385 'full_name' => 'idx_correo.search',
386 'type' => ['name' => 'scalar', 'raw' => ['id' => 65, 'name' => 'column:var_size']],
390 'name' => 'LongText',
391 'type' => ['id' => 32, 'name' => 'type'],
392 'size' => 2147483648,
396 'disk_usage' => 274432,
400 $this->dummyDbi
->addResult('SELECT mroonga_command(\'object_inspect idx_correo#idx_correo_search\');', [
403 (string) json_encode([
405 'name' => 'idx_correo#idx_correo_search',
406 'type' => ['id' => 49, 'name' => 'table:pat_key'],
410 'name' => 'ShortText',
411 'type' => ['id' => 32, 'name' => 'type'],
415 'max_total_size' => 4294967294,
417 'value' => ['type' => null],
419 'disk_usage' => 12878,
423 $this->dummyDbi
->addResult('SELECT mroonga_command(\'object_inspect idx_correo#idx_correo_search.index\');', [
426 (string) json_encode([
431 'name' => 'idx_correo#idx_correo_search',
432 'type' => ['id' => 49, 'name' => 'table:pat_key'],
436 'name' => 'ShortText',
437 'type' => ['id' => 32, 'name' => 'type'],
441 'max_total_size' => 4294967294,
443 'value' => ['type' => null],
445 'disk_usage' => 4243456,
447 'full_name' => 'idx_correo#idx_correo_search.index',
448 'type' => ['name' => 'index', 'raw' => ['id' => 72, 'name' => 'column:index']],
452 'name' => 'idx_correo',
453 'type' => ['id' => 49, 'name' => 'table:pat_key'],
461 'max_section_id' => 0,
462 'n_garbage_segments' => 0,
463 'max_array_segment_id' => 0,
464 'n_array_segments' => 0,
465 'max_buffer_segment_id' => 0,
466 'n_buffer_segments' => 0,
467 'max_in_use_physical_segment_id' => 0,
468 'n_unmanaged_segments' => 0,
469 'total_chunk_size' => 0,
470 'max_in_use_chunk_id' => 0,
471 'n_garbage_chunks' => [
496 'name' => 'idx_correo',
497 'type' => ['id' => 49, 'name' => 'table:pat_key'],
502 'type' => ['id' => 32, 'name' => 'type'],
506 'max_total_size' => 4294967294,
508 'value' => ['type' => null],
510 'disk_usage' => 4243456,
512 'full_name' => 'idx_correo.search',
515 'disk_usage' => 565248,
520 $this->dummyDbi
->addSelectDb('my_db');
521 $lengths = StorageEngine
::getMroongaLengths('my_db', 'idx_correo');
522 $this->dummyDbi
->assertAllSelectsConsumed();
523 self
::assertSame([4521984, 578126], $lengths);
525 $this->dummyDbi
->assertAllQueriesConsumed();