Skip to content

Commit

Permalink
Fix isJsonSupported for MariaDB (#226)
Browse files Browse the repository at this point in the history
* Fix isJsonSupported for MariaDB

* Fix code style

---------

Co-authored-by: jmsche <[email protected]>
Co-authored-by: Damien Harper <[email protected]>
  • Loading branch information
3 people authored Oct 31, 2024
1 parent 0b9929a commit 9e81de0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static function isJsonSupported(Connection $connection): bool
return true;
}

return version_compare(self::getMariaDbMysqlVersionNumber($version), '10.2.7', '<');
return version_compare(self::getMariaDbMysqlVersionNumber($version), '10.2.7', '>=');
}

return true;
Expand Down
45 changes: 45 additions & 0 deletions tests/Provider/Doctrine/Persistence/Helper/PlatformHelperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace DH\Auditor\Tests\Provider\Doctrine\Persistence\Helper;

use DH\Auditor\Provider\Doctrine\Persistence\Helper\PlatformHelper;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\MariaDBPlatform;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Small;
use PHPUnit\Framework\TestCase;

/**
* @internal
*/
#[Small]
final class PlatformHelperTest extends TestCase
{
#[DataProvider('provideMariaDbVersionCases')]
public function testIsJsonSupportedForMariaDb(string $mariaDbVersion, bool $expectedResult): void
{
$connection = $this->createMock(Connection::class);
$connection->method('getDatabasePlatform')
->willReturn(new MariaDBPlatform())
;
$connection->method('getServerVersion')
->willReturn($mariaDbVersion)
;

$this->assertSame($expectedResult, PlatformHelper::isJsonSupported($connection));
}

/**
* @return iterable<string, array<bool|string>>
*/
public static function provideMariaDbVersionCases(): iterable
{
yield '10.2.6' => ['10.2.6', false];

yield '10.2.7' => ['10.2.7', true];

yield '10.11.8-MariaDB-0ubuntu0.24.04.1' => ['10.11.8-MariaDB-0ubuntu0.24.04.1', true];
}
}

0 comments on commit 9e81de0

Please sign in to comment.