|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tempest\Database\Tests; |
| 4 | + |
| 5 | +use Generator; |
| 6 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 7 | +use PHPUnit\Framework\TestCase; |
| 8 | +use Tempest\Core\Insight; |
| 9 | +use Tempest\Database\Config\DatabaseConfig; |
| 10 | +use Tempest\Database\Config\MysqlConfig; |
| 11 | +use Tempest\Database\Config\PostgresConfig; |
| 12 | +use Tempest\Database\Config\SQLiteConfig; |
| 13 | +use Tempest\Database\Database; |
| 14 | +use Tempest\Database\DatabaseInsightsProvider; |
| 15 | + |
| 16 | +final class DatabaseInsightsProviderTest extends TestCase |
| 17 | +{ |
| 18 | + #[DataProvider('provide_database_drivers')] |
| 19 | + public function test_get_insights(DatabaseConfig $config, string $version, array $expected): void |
| 20 | + { |
| 21 | + $database = $this->createMock(Database::class); |
| 22 | + $database |
| 23 | + ->expects($this->once()) |
| 24 | + ->method('fetchFirst') |
| 25 | + ->withAnyParameters() |
| 26 | + ->willReturn(['version' => $version]); |
| 27 | + |
| 28 | + $databaseInsightsProvider = new DatabaseInsightsProvider( |
| 29 | + databaseConfig: $config, |
| 30 | + database: $database, |
| 31 | + ); |
| 32 | + |
| 33 | + $this->assertEquals($expected, $databaseInsightsProvider->getInsights()); |
| 34 | + } |
| 35 | + |
| 36 | + public static function provide_database_drivers(): Generator |
| 37 | + { |
| 38 | + yield 'sqlite' => [ |
| 39 | + new SQLiteConfig(), |
| 40 | + '3.45.2', |
| 41 | + ['Engine' => 'SQLite', 'Version' => new Insight('3.45.2')], |
| 42 | + ]; |
| 43 | + yield 'mysql (simple)' => [ |
| 44 | + new MysqlConfig(), |
| 45 | + '8.0.42', |
| 46 | + ['Engine' => 'MySQL', 'Version' => new Insight('8.0.42')], |
| 47 | + ]; |
| 48 | + yield 'mysql (distribution specific)' => [ |
| 49 | + new MysqlConfig(), |
| 50 | + '8.0.42-0ubuntu0.22.04.1', |
| 51 | + ['Engine' => 'MySQL', 'Version' => new Insight('8.0.42')], |
| 52 | + ]; |
| 53 | + yield 'postgresql' => [ |
| 54 | + new PostgresConfig(), |
| 55 | + 'PostgreSQL 15.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 11.3.0, 64-bit', |
| 56 | + ['Engine' => 'PostgreSQL', 'Version' => new Insight('15.3')], |
| 57 | + ]; |
| 58 | + } |
| 59 | +} |
0 commit comments