3 declare(strict_types
=1);
5 namespace PhpMyAdmin\Tests
;
7 use PhpMyAdmin\Dbal\DatabaseInterface
;
8 use PhpMyAdmin\TypeClass
;
10 use PHPUnit\Framework\Attributes\CoversClass
;
11 use PHPUnit\Framework\Attributes\DataProvider
;
12 use PHPUnit\Framework\MockObject\Stub
;
14 #[CoversClass(Types::class)]
15 class TypesByDatabaseVersionTest
extends AbstractTestCase
17 private DatabaseInterface
&Stub
$dbiStub;
19 protected Types
$object;
22 * Sets up the fixture, for example, opens a network connection.
23 * This method is called before a test is executed.
25 protected function setUp(): void
29 $this->dbiStub
= self
::createStub(DatabaseInterface
::class);
33 * Tears down the fixture, for example, closes a network connection.
34 * This method is called after a test is executed.
36 protected function tearDown(): void
40 unset($this->dbiStub
);
45 * @param string $database Database
46 * @param int $dbVersion Database Version
47 * @param TypeClass $class The class to get function list.
48 * @param array $includes Expected elements should contain in result
49 * @param array $excludes Expected elements should not contain in result
50 * @phpstan-param array<string> $includes
51 * @phpstan-param array<string> $excludes
53 #[DataProvider('providerFortTestGetFunctionsClass')]
54 public function testGetFunctionsClass(
61 $this->createObject($database, $dbVersion);
63 $result = $this->object->getFunctionsClass($class);
65 foreach ($includes as $value) {
66 self
::assertContains($value, $result);
69 if ($excludes === []) {
73 foreach ($excludes as $value) {
74 self
::assertNotContains($value, $result);
79 * Data provider for testing function lists
81 * @psalm-return array<string, array{string, int, TypeClass, array<string>, array<string>}>
83 public static function providerFortTestGetFunctionsClass(): array
86 'mysql 5.1.0 - CHAR - not support INET6 Converter' => [
95 'mysql 8.0.30 - CHAR - support INET6 Converter' => [
104 'mariadb 5.1.0 - CHAR - not support INET6 Converter' => [
113 'mariadb 10.0.12 - CHAR - support INET6 Converter' => [
122 'mariadb 10.9.3 - CHAR - support INET6 Converter and UUID' => [
127 [ 'INET6_NTOA', 'UUID' ],
131 'mysql 5.1.0 - NUMBER - not support INET6 Converter' => [
140 'mysql 8.0.30 - NUMBER - support INET6 Converter' => [
149 'mariadb 5.1.0 - NUMBER - not support INET6 Converter' => [
158 'mariadb 10.0.12 - NUMBER - support INET6 Converter' => [
167 'mariadb 10.9.3 - NUMBER - support INET6 Converter and UUID' => [
172 [ 'INET6_ATON', 'UUID_SHORT' ],
176 'mysql 5.1.0 - SPATIAL - not support ST_Geometry' => [
203 'ST_GeomCollFromText',
210 'ST_GeomCollFromWKB',
219 'mysql 8.0.30 - SPATIAL - support ST_Geometry' => [
227 'ST_GeomCollFromText',
234 'ST_GeomCollFromWKB',
266 * Test for getAllFunctions
268 * @param string $database Database
269 * @param int $dbVersion Database Version
270 * @param array $includes Expected elements should contain in result
271 * @param array $excludes Expected elements should not contain in result
272 * @phpstan-param array<string> $includes
273 * @phpstan-param array<string> $excludes
275 #[DataProvider('providerFortTestGetAllFunctions')]
276 public function testGetAllFunctions(string $database, int $dbVersion, array $includes, array $excludes): void
278 $this->createObject($database, $dbVersion);
280 $result = $this->object->getAllFunctions();
282 foreach ($includes as $value) {
283 self
::assertContains($value, $result);
286 if ($excludes === []) {
290 foreach ($excludes as $value) {
291 self
::assertNotContains($value, $result);
296 * Data provider for testing get all functions
298 * @psalm-return array<string, array{string, int, array<string>, array<string>}>
300 public static function providerFortTestGetAllFunctions(): array
303 'mysql 5.1.0 - not support INET6_ATON, ST_Geometry' => [
329 'ST_GeomCollFromText',
336 'ST_GeomCollFromWKB',
345 'mysql 8.0.30 - support INET6_ATON and ST_Geometry' => [
353 'ST_GeomCollFromText',
360 'ST_GeomCollFromWKB',
389 'mariadb 5.1.0 - not support INET6_ATON and ST_Geometry' => [
417 'ST_GeomCollFromText',
424 'ST_GeomCollFromWKB',
433 'mariadb 10.6.0 - support INET6_ATON and ST_Geometry' => [
441 'ST_GeomCollFromText',
448 'ST_GeomCollFromWKB',
477 'mariadb 10.9.3 - support INET6_ATON, ST_Geometry and UUID' => [
485 'ST_GeomCollFromText',
492 'ST_GeomCollFromWKB',
525 * Test for getColumns
527 * @param string $database Database
528 * @param int $dbVersion Database Version
529 * @param array $expected Expected Result
530 * @phpstan-param array<int|string, array<int, string>|string> $expected
532 #[DataProvider('providerFortTestGetColumns')]
533 public function testGetColumns(string $database, int $dbVersion, array $expected): void
535 $this->createObject($database, $dbVersion);
537 self
::assertSame($expected, $this->object->getColumns());
541 * Data provider for testing test columns
543 * @psalm-return array<string, array{string, int, array<int|string, array<int, string>|string>}>
545 public static function providerFortTestGetColumns(): array
548 'mysql 5.1.0 - not support INET6, JSON and UUID' => [
572 'Date and time' => ['DATE', 'DATETIME', 'TIMESTAMP', 'TIME', 'YEAR'],
601 'GEOMETRYCOLLECTION',
605 'mysql 8.0.30 - support JSON but not support INET6 and UUID' => [
629 'Date and time' => ['DATE', 'DATETIME', 'TIMESTAMP', 'TIME', 'YEAR'],
658 'GEOMETRYCOLLECTION',
663 'mariadb 5.1.0 - not support INET6, JSON and UUID' => [
687 'Date and time' => ['DATE', 'DATETIME', 'TIMESTAMP', 'TIME', 'YEAR'],
716 'GEOMETRYCOLLECTION',
720 'mariadb 10.2.8 - support JSON but not support INET6 and UUID' => [
744 'Date and time' => ['DATE', 'DATETIME', 'TIMESTAMP', 'TIME', 'YEAR'],
773 'GEOMETRYCOLLECTION',
775 'JSON' => [ 'JSON' ],
778 'mariadb 10.5.0 - support JSON and INET6 but not support UUID' => [
802 'Date and time' => ['DATE', 'DATETIME', 'TIMESTAMP', 'TIME', 'YEAR'],
833 'GEOMETRYCOLLECTION',
835 'JSON' => [ 'JSON' ],
838 'mariadb 10.9.3 - support INET6, JSON and UUID' => [
863 'Date and time' => ['DATE', 'DATETIME', 'TIMESTAMP', 'TIME', 'YEAR'],
894 'GEOMETRYCOLLECTION',
896 'JSON' => [ 'JSON' ],
897 'UUID' => [ 'UUID' ],
904 * @param string $database Database
905 * @param int $version Database Version
907 private function createObject(string $database, int $version): void
909 $this->dbiStub
->method('isMariaDB')->willReturn($database === 'mariadb');
910 $this->dbiStub
->method('getVersion')->willReturn($version);
911 $this->object = new Types($this->dbiStub
);