3 declare(strict_types
=1);
5 namespace PhpMyAdmin\Tests
;
8 use PhpMyAdmin\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
;
25 use PHPUnit\Framework\Attributes\PreserveGlobalState
;
26 use PHPUnit\Framework\Attributes\RunInSeparateProcess
;
27 use PHPUnit\Framework\MockObject\MockObject
;
29 use function json_encode
;
31 #[CoversClass(StorageEngine::class)]
32 class StorageEngineTest
extends AbstractTestCase
34 protected DatabaseInterface
$dbi;
36 protected DbiDummy
$dummyDbi;
38 /** @var StorageEngine&MockObject */
39 protected StorageEngine
$object;
42 * Sets up the fixture, for example, opens a network connection.
43 * This method is called before a test is executed.
45 protected function setUp(): void
49 $this->dummyDbi
= $this->createDbiDummy();
50 $this->dbi
= $this->createDatabaseInterface($this->dummyDbi
);
51 DatabaseInterface
::$instance = $this->dbi
;
52 $this->object = $this->getMockForAbstractClass(
59 * Tears down the fixture, for example, closes a network connection.
60 * This method is called after a test is executed.
62 protected function tearDown(): void
69 #[PreserveGlobalState(false)]
70 #[RunInSeparateProcess]
71 public function testGetStorageEngines(): void
75 'dummy' => ['Engine' => 'dummy', 'Support' => 'YES', 'Comment' => 'dummy comment'],
76 'dummy2' => ['Engine' => 'dummy2', 'Support' => 'NO', 'Comment' => 'dummy2 comment'],
78 'Engine' => 'FEDERATED',
80 'Comment' => 'Federated MySQL storage engine',
82 'Pbxt' => ['Engine' => 'Pbxt', 'Support' => 'NO', 'Comment' => 'Pbxt storage engine'],
84 $this->object->getStorageEngines(),
88 public function testGetArray(): void
90 $actual = $this->object->getArray();
93 ['dummy' => ['name' => 'dummy', 'comment' => 'dummy comment', 'is_default' => false]],
99 * Test for StorageEngine::getEngine
101 * @param string $expectedClass Class that should be selected
102 * @param string $engineName Engine name
103 * @psalm-param class-string $expectedClass
105 #[DataProvider('providerGetEngine')]
106 public function testGetEngine(string $expectedClass, string $engineName): void
108 $actual = StorageEngine
::getEngine($engineName);
109 $this->assertInstanceOf($expectedClass, $actual);
113 * Provider for testGetEngine
117 public static function providerGetEngine(): array
120 [StorageEngine
::class, 'unknown engine'],
122 [Berkeleydb
::class, 'Berkeleydb'],
123 [Binlog
::class, 'Binlog'],
124 [Innobase
::class, 'Innobase'],
125 [Innodb
::class, 'Innodb'],
126 [Memory
::class, 'Memory'],
127 [Merge
::class, 'Merge'],
128 [MrgMyisam
::class, 'Mrg_Myisam'],
129 [Myisam
::class, 'Myisam'],
130 [Ndbcluster
::class, 'Ndbcluster'],
131 [Pbxt
::class, 'Pbxt'],
132 [PerformanceSchema
::class, 'Performance_Schema'],
139 public function testIsValid(): void
142 $this->object->isValid('PBMS'),
145 $this->object->isValid('dummy'),
148 $this->object->isValid('dummy2'),
151 $this->object->isValid('invalid'),
158 public function testGetPage(): void
162 $this->object->getPage('Foo'),
167 * Test for getInfoPages
169 public function testGetInfoPages(): void
173 $this->object->getInfoPages(),
178 * Test for getVariablesLikePattern
180 public function testGetVariablesLikePattern(): void
184 $this->object->getVariablesLikePattern(),
189 * Test for getMysqlHelpPage
191 public function testGetMysqlHelpPage(): void
194 'dummy-storage-engine',
195 $this->object->getMysqlHelpPage(),
200 * Test for getVariables
202 public function testGetVariables(): void
206 $this->object->getVariables(),
211 * Test for getSupportInformationMessage
213 public function testGetSupportInformationMessage(): void
216 'dummy is available on this MySQL server.',
217 $this->object->getSupportInformationMessage(),
220 $this->object->support
= 1;
222 'dummy has been disabled for this MySQL server.',
223 $this->object->getSupportInformationMessage(),
226 $this->object->support
= 2;
228 'dummy is available on this MySQL server.',
229 $this->object->getSupportInformationMessage(),
232 $this->object->support
= 3;
234 'dummy is the default storage engine on this MySQL server.',
235 $this->object->getSupportInformationMessage(),
240 * Test for getComment
242 public function testGetComment(): void
246 $this->object->getComment(),
253 public function testGetTitle(): void
257 $this->object->getTitle(),
262 * Test for resolveTypeSize
264 public function testResolveTypeSize(): void
268 $this->object->resolveTypeSize(12),
272 public function testHasMroongaEngine(): void
274 $this->dummyDbi
->addResult('SELECT mroonga_command(\'object_list\');', [
276 (string) json_encode([]), // Fake result
279 $this->assertTrue(StorageEngine
::hasMroongaEngine());
280 $this->assertTrue(StorageEngine
::hasMroongaEngine()); // Does not call any query
282 Cache
::remove('storage-engine.mroonga.has.mroonga_command'); // Cache clear
284 $this->dummyDbi
->addResult('SELECT mroonga_command(\'object_list\');', false);
285 $this->assertFalse(StorageEngine
::hasMroongaEngine());
287 $this->dummyDbi
->assertAllQueriesConsumed();
290 public function testGetMroongaLengths(): void
292 $this->dummyDbi
->addResult('SELECT mroonga_command(\'object_list\');', [
295 (string) json_encode([
298 'name' => 'WGS84GeoPoint',
301 'type' => ['id' => 32, 'name' => 'type'],
302 'flags' => ['value' => 24, 'names' => 'KEY_GEO_POINT'],
306 'mroonga_operations' => ['type' => ['id' => 51, 'name' => 'table:no_key']],
307 'mroonga_operations.type' => ['type' => ['id' => 65, 'name' => 'column:var_size']],
308 'mroonga_operations.table' => ['type' => ['id' => 65, 'name' => 'column:var_size']],
309 'mroonga_operations.record' => ['type' => ['id' => 64, 'name' => 'column:fix_size']],
310 'idx_correo' => ['type' => ['id' => 49, 'name' => 'table:pat_key']],
311 'idx_correo.id' => ['type' => ['id' => 64, 'name' => 'column:fix_size']],
312 'idx_correo.search' => ['type' => ['id' => 65, 'name' => 'column:var_size']],
313 'idx_correo#idx_correo_search' => ['type' => ['id' => 49, 'name' => 'table:pat_key']],
314 'idx_correo#idx_correo_search.index' => ['type' => ['id' => 72, 'name' => 'column:index']],
318 $this->dummyDbi
->addResult('SELECT mroonga_command(\'object_inspect idx_correo\');', [
321 (string) json_encode([
323 'name' => 'idx_correo',
324 'type' => ['id' => 49, 'name' => 'table:pat_key'],
326 'type' => ['id' => 8, 'name' => 'Int32', 'type' => ['id' => 32,'name' => 'type'], 'size' => 4],
328 'max_total_size' => 4294967294,
330 'value' => ['type' => null],
332 'disk_usage' => 4243456,
336 $this->dummyDbi
->addResult('SELECT mroonga_command(\'object_inspect idx_correo.id\');', [
339 (string) json_encode([
344 'name' => 'idx_correo',
345 'type' => ['id' => 49, 'name' => 'table:pat_key'],
350 'type' => ['id' => 32, 'name' => 'type'],
354 'max_total_size' => 4294967294,
356 'value' => ['type' => null],
358 'disk_usage' => 4243456,
360 'full_name' => 'idx_correo.id',
361 'type' => ['name' => 'scalar', 'raw' => ['id' => 64, 'name' => 'column:fix_size']],
363 'type' => ['id' => 8, 'name' => 'Int32', 'type' => ['id' => 32,'name' => 'type'], 'size' => 4],
366 'disk_usage' => 4096,
370 $this->dummyDbi
->addResult('SELECT mroonga_command(\'object_inspect idx_correo.search\');', [
373 (string) json_encode([
378 'name' => 'idx_correo',
379 'type' => ['id' => 49, 'name' => 'table:pat_key'],
384 'type' => ['id' => 32, 'name' => 'type'],
388 'max_total_size' => 4294967294,
390 'value' => ['type' => null],
392 'disk_usage' => 4243456,
394 'full_name' => 'idx_correo.search',
395 'type' => ['name' => 'scalar', 'raw' => ['id' => 65, 'name' => 'column:var_size']],
399 'name' => 'LongText',
400 'type' => ['id' => 32, 'name' => 'type'],
401 'size' => 2147483648,
405 'disk_usage' => 274432,
409 $this->dummyDbi
->addResult('SELECT mroonga_command(\'object_inspect idx_correo#idx_correo_search\');', [
412 (string) json_encode([
414 'name' => 'idx_correo#idx_correo_search',
415 'type' => ['id' => 49, 'name' => 'table:pat_key'],
419 'name' => 'ShortText',
420 'type' => ['id' => 32, 'name' => 'type'],
424 'max_total_size' => 4294967294,
426 'value' => ['type' => null],
428 'disk_usage' => 12878,
432 $this->dummyDbi
->addResult('SELECT mroonga_command(\'object_inspect idx_correo#idx_correo_search.index\');', [
435 (string) json_encode([
440 'name' => 'idx_correo#idx_correo_search',
441 'type' => ['id' => 49, 'name' => 'table:pat_key'],
445 'name' => 'ShortText',
446 'type' => ['id' => 32, 'name' => 'type'],
450 'max_total_size' => 4294967294,
452 'value' => ['type' => null],
454 'disk_usage' => 4243456,
456 'full_name' => 'idx_correo#idx_correo_search.index',
457 'type' => ['name' => 'index', 'raw' => ['id' => 72, 'name' => 'column:index']],
461 'name' => 'idx_correo',
462 'type' => ['id' => 49, 'name' => 'table:pat_key'],
470 'max_section_id' => 0,
471 'n_garbage_segments' => 0,
472 'max_array_segment_id' => 0,
473 'n_array_segments' => 0,
474 'max_buffer_segment_id' => 0,
475 'n_buffer_segments' => 0,
476 'max_in_use_physical_segment_id' => 0,
477 'n_unmanaged_segments' => 0,
478 'total_chunk_size' => 0,
479 'max_in_use_chunk_id' => 0,
480 'n_garbage_chunks' => [
505 'name' => 'idx_correo',
506 'type' => ['id' => 49, 'name' => 'table:pat_key'],
511 'type' => ['id' => 32, 'name' => 'type'],
515 'max_total_size' => 4294967294,
517 'value' => ['type' => null],
519 'disk_usage' => 4243456,
521 'full_name' => 'idx_correo.search',
524 'disk_usage' => 565248,
529 $this->dummyDbi
->addSelectDb('my_db');
530 $lengths = StorageEngine
::getMroongaLengths('my_db', 'idx_correo');
531 $this->dummyDbi
->assertAllSelectsConsumed();
532 $this->assertSame([4521984, 578126], $lengths);
534 $this->dummyDbi
->assertAllQueriesConsumed();