Skip to content

Commit 92639d6

Browse files
committed
This commit removes getDatabasePlatformName from the API. These changes will need to be made downstream in the driver packages.
Signed-off-by: Joey Smith <[email protected]>
1 parent 5840ead commit 92639d6

File tree

7 files changed

+7
-73
lines changed

7 files changed

+7
-73
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ parameters:
66
count: 1
77
path: src/Sql/AbstractSql.php
88

9-
-
10-
message: '#^Cannot call method getAttribute\(\) on resource\.$#'
11-
identifier: method.nonObject
12-
count: 1
13-
path: test/unit/Adapter/Driver/Pdo/TestAsset/TestPdo.php
14-
159
-
1610
message: '#^Parameter \#1 \$attribute \(string\) of method PhpDbTest\\Adapter\\Driver\\TestAsset\\PdoMock\:\:getAttribute\(\) should be compatible with parameter \$attribute \(int\) of method PDO\:\:getAttribute\(\)$#'
1711
identifier: method.childParameterType

src/Adapter/Driver/DriverInterface.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ interface DriverInterface
1010
{
1111
public const PARAMETERIZATION_POSITIONAL = 'positional';
1212
public const PARAMETERIZATION_NAMED = 'named';
13-
public const NAME_FORMAT_CAMELCASE = 'camelCase';
14-
public const NAME_FORMAT_NATURAL = 'natural';
15-
16-
/** Get database platform name */
17-
public function getDatabasePlatformName(string $nameFormat = DriverInterface::NAME_FORMAT_CAMELCASE): string;
1813

1914
/**
2015
* Check environment

src/Adapter/Driver/Pdo/AbstractPdo.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Override;
88
use PDO;
99
use PDOStatement;
10+
use PhpDb\Adapter\Driver\AbstractConnection;
1011
use PhpDb\Adapter\Driver\PdoConnectionInterface;
1112
use PhpDb\Adapter\Driver\PdoDriverAwareInterface;
1213
use PhpDb\Adapter\Driver\PdoDriverInterface;
@@ -26,7 +27,7 @@
2627

2728
abstract class AbstractPdo implements PdoDriverInterface, ProfilerAwareInterface
2829
{
29-
protected (PdoConnectionInterface&PdoDriverAwareInterface)|PDO $connection;
30+
protected (PdoConnectionInterface&AbstractConnection&PdoDriverAwareInterface)|PDO $connection;
3031

3132
protected StatementInterface&PdoDriverAwareInterface $statementPrototype;
3233

test/unit/Adapter/Container/AdapterInterfaceDelegatorTest.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,6 @@ public function testDelegatorWithServiceManagerAndCustomAdapterName(): void
213213

214214
public function testDelegatorWithPluginManager(): void
215215
{
216-
$this->markTestSkipped(
217-
'Test requires factory-based plugin manager configuration to pass options to constructor'
218-
);
219-
220-
/** @phpstan-ignore deadCode.unreachable */
221216
$databaseAdapter = new Adapter(
222217
$this->createMock(DriverInterface::class),
223218
$this->createMock(PlatformInterface::class),
@@ -241,7 +236,6 @@ public function testDelegatorWithPluginManager(): void
241236
],
242237
];
243238

244-
/** @var AbstractPluginManager $pluginManager */
245239
$pluginManager = new class ($container, $pluginManagerConfig) extends AbstractPluginManager {
246240
public function validate(mixed $instance): void
247241
{
@@ -254,7 +248,7 @@ public function validate(mixed $instance): void
254248
];
255249

256250
/** @var ConcreteAdapterAwareObject $result */
257-
$result = $pluginManager->get(
251+
$result = $pluginManager->build(
258252
ConcreteAdapterAwareObject::class,
259253
$options
260254
);

test/unit/Adapter/Driver/Pdo/ConnectionTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ protected function setUp(): void
4040
*/
4141
public function testResource(): void
4242
{
43-
$this->markTestSkipped('Test requires concrete driver implementation with DSN building logic');
44-
/** @phpstan-ignore deadCode.unreachable */
45-
$this->expectException(InvalidConnectionParametersException::class);
46-
$this->connection->getResource();
43+
$resource = $this->connection->getResource();
44+
self::assertNotNull($resource);
4745
}
4846

4947
/**
@@ -65,7 +63,7 @@ public function testGetDsn(): void
6563
#[Group('2622')]
6664
public function testArrayOfConnectionParametersCreatesCorrectDsn(): void
6765
{
68-
$this->markTestSkipped('Test requires concrete MySQL driver implementation with DSN building logic');
66+
$this->markTestSkipped('This test will pass with current sqlite::memory: prefix, but shouldn\'t.');
6967
/** @phpstan-ignore deadCode.unreachable */
7068
$this->connection->setConnectionParameters([
7169
'driver' => 'pdo_mysql',
@@ -80,7 +78,7 @@ public function testArrayOfConnectionParametersCreatesCorrectDsn(): void
8078
}
8179
$responseString = $this->connection->getDsn();
8280

83-
self::assertStringStartsWith('mysql:', $responseString);
81+
self::assertStringStartsWith('sqlite::memory:', $responseString);
8482
self::assertStringContainsString('charset=utf8', $responseString);
8583
self::assertStringContainsString('dbname=foo', $responseString);
8684
self::assertStringContainsString('port=3306', $responseString);

test/unit/Adapter/Driver/Pdo/PdoTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use PHPUnit\Framework\Attributes\DataProvider;
1515
use PHPUnit\Framework\TestCase;
1616

17-
#[CoversMethod(AbstractPdo::class, 'getDatabasePlatformName')]
1817
#[CoversMethod(AbstractPdo::class, 'getResultPrototype')]
1918
final class PdoTest extends TestCase
2019
{
@@ -30,14 +29,6 @@ protected function setUp(): void
3029
$this->pdo = new TestPdo([]);
3130
}
3231

33-
public function testGetDatabasePlatformName(): void
34-
{
35-
// Test platform name for SqlServer
36-
$this->pdo->getConnection()->setConnectionParameters(['pdodriver' => 'sqlsrv']);
37-
self::assertEquals('SqlServer', $this->pdo->getDatabasePlatformName());
38-
self::assertEquals('SQLServer', $this->pdo->getDatabasePlatformName(DriverInterface::NAME_FORMAT_NATURAL));
39-
}
40-
4132
/** @psalm-return array<array-key, array{0: int|string, 1: null|string, 2: string}> */
4233
public static function getParamsAndType(): array
4334
{

test/unit/Adapter/Driver/Pdo/TestAsset/TestPdo.php

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
use PhpDb\Adapter\Driver\Pdo\Result;
1414
use PhpDb\Adapter\Driver\Pdo\Statement;
1515

16-
use function ucfirst;
17-
1816
/**
1917
* Test asset for AbstractPdo - provides a concrete implementation for testing
2018
*/
@@ -61,41 +59,4 @@ public function createResult($resource): Result
6159
$result->initialize($resource, $this->connection->getLastGeneratedValue());
6260
return $result;
6361
}
64-
65-
/**
66-
* Get database platform name
67-
*/
68-
#[Override]
69-
public function getDatabasePlatformName(string $nameFormat = self::NAME_FORMAT_CAMELCASE): string
70-
{
71-
$pdoDriver = null;
72-
if ($this->connection instanceof TestConnection) {
73-
$pdoDriver = $this->connection->getConnectionParameters()['pdodriver'] ?? null;
74-
}
75-
76-
if ($pdoDriver === null && $this->connection->isConnected()) {
77-
$pdoDriver = $this->connection->getResource()->getAttribute(PDO::ATTR_DRIVER_NAME);
78-
}
79-
80-
// todo: None of this belongs here
81-
return match ($nameFormat) {
82-
self::NAME_FORMAT_CAMELCASE => match ($pdoDriver) {
83-
'sqlsrv', 'dblib', 'mssql' => 'SqlServer',
84-
'mysql' => 'MySql',
85-
'oci' => 'Oracle',
86-
'pgsql' => 'PostgreSql',
87-
'sqlite' => 'Sqlite',
88-
default => 'Sql92',
89-
},
90-
self::NAME_FORMAT_NATURAL => match ($pdoDriver) {
91-
'sqlsrv', 'dblib', 'mssql' => 'SQLServer',
92-
'mysql' => 'MySQL',
93-
'oci' => 'Oracle',
94-
'pgsql' => 'PostgreSQL',
95-
'sqlite' => 'SQLite',
96-
default => 'SQL92',
97-
},
98-
default => $pdoDriver !== null ? ucfirst($pdoDriver) : 'SQL92',
99-
};
100-
}
10162
}

0 commit comments

Comments
 (0)