From fe3f3f815c60e7160915a0b8497086e2f6573fe4 Mon Sep 17 00:00:00 2001 From: Jan Skrasek Date: Sun, 10 Jan 2016 20:29:55 +0100 Subject: [PATCH] platform: added IPlatform::getName() --- src/Platforms/CachedPlatform.php | 6 ++++++ src/Platforms/IPlatform.php | 7 +++++++ src/Platforms/MySqlPlatform.php | 6 ++++++ src/Platforms/PostgreSqlPlatform.php | 6 ++++++ tests/cases/integration/platform.mysql.phpt | 6 ++++++ tests/cases/integration/platform.pgsql.phpt | 6 ++++++ tests/cases/unit/CachedPlatformTest.phpt | 7 +++++++ 7 files changed, 44 insertions(+) diff --git a/src/Platforms/CachedPlatform.php b/src/Platforms/CachedPlatform.php index 811de9ba..5b47218a 100644 --- a/src/Platforms/CachedPlatform.php +++ b/src/Platforms/CachedPlatform.php @@ -30,6 +30,12 @@ public function __construct(Connection $connection, IStorage $storage) } + public function getName() + { + return $this->platform->getName(); + } + + public function getTables() { return $this->cache->load('tables', function () { diff --git a/src/Platforms/IPlatform.php b/src/Platforms/IPlatform.php index 397fd722..020036bd 100644 --- a/src/Platforms/IPlatform.php +++ b/src/Platforms/IPlatform.php @@ -11,6 +11,13 @@ interface IPlatform { + /** + * Returns platform name. + * @return string + */ + public function getName(); + + /** * Returns list of tables names indexed by table name. * @return array diff --git a/src/Platforms/MySqlPlatform.php b/src/Platforms/MySqlPlatform.php index d86bd27f..f4b6dd37 100644 --- a/src/Platforms/MySqlPlatform.php +++ b/src/Platforms/MySqlPlatform.php @@ -23,6 +23,12 @@ public function __construct(Connection $connection) } + public function getName() + { + return 'mysql'; + } + + public function getTables() { $tables = []; diff --git a/src/Platforms/PostgreSqlPlatform.php b/src/Platforms/PostgreSqlPlatform.php index 9958a992..03ec3f90 100644 --- a/src/Platforms/PostgreSqlPlatform.php +++ b/src/Platforms/PostgreSqlPlatform.php @@ -23,6 +23,12 @@ public function __construct(Connection $connection) } + public function getName() + { + return 'postgresql'; + } + + public function getTables() { $result = $this->connection->query(" diff --git a/tests/cases/integration/platform.mysql.phpt b/tests/cases/integration/platform.mysql.phpt index cc8c2a4f..33f12a3b 100644 --- a/tests/cases/integration/platform.mysql.phpt +++ b/tests/cases/integration/platform.mysql.phpt @@ -137,6 +137,12 @@ class PlatformMysqlTest extends IntegrationTestCase { Assert::null($this->connection->getPlatform()->getPrimarySequenceName('books')); } + + + public function testName() + { + Assert::same('mysql', $this->connection->getPlatform()->getName()); + } } diff --git a/tests/cases/integration/platform.pgsql.phpt b/tests/cases/integration/platform.pgsql.phpt index e87b32ed..fcdf2fc6 100644 --- a/tests/cases/integration/platform.pgsql.phpt +++ b/tests/cases/integration/platform.pgsql.phpt @@ -145,6 +145,12 @@ class PlatformPostgreTest extends IntegrationTestCase { Assert::same('books_id_seq', $this->connection->getPlatform()->getPrimarySequenceName('books')); } + + + public function testName() + { + Assert::same('postgresql', $this->connection->getPlatform()->getName()); + } } diff --git a/tests/cases/unit/CachedPlatformTest.phpt b/tests/cases/unit/CachedPlatformTest.phpt index 89e3b4ea..20d00809 100644 --- a/tests/cases/unit/CachedPlatformTest.phpt +++ b/tests/cases/unit/CachedPlatformTest.phpt @@ -164,6 +164,13 @@ class CachedPlatformTest extends TestCase $cols = $this->platform->getPrimarySequenceName('foo'); Assert::same($expectedPs, $cols); } + + + public function testName() + { + $this->platformMock->shouldReceive('getName')->once()->andReturn('foo'); + Assert::same('foo', $this->platform->getName()); + } }