Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 13 additions & 37 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -222,63 +222,39 @@ parameters:
count: 1
path: test/integration/AdapterPlatformTest.php

-
message: '#^Callable PhpDb\\Mysql\\Container\\DriverInterfaceFactory invoked with 1 parameter, 2\-3 required\.$#'
identifier: arguments.count
count: 1
path: test/integration/Container/DriverInterfaceFactoryTest.php

-
message: '#^Parameter \#1 \$container of callable PhpDb\\Mysql\\Container\\DriverInterfaceFactory expects Laminas\\ServiceManager\\ServiceManager, Psr\\Container\\ContainerInterface given\.$#'
identifier: argument.type
count: 1
count: 2
path: test/integration/Container/DriverInterfaceFactoryTest.php

-
message: '#^Callable PhpDb\\Mysql\\Container\\MetadataInterfaceFactory invoked with 1 parameter, 2\-3 required\.$#'
identifier: arguments.count
count: 1
path: test/integration/Container/MetadataInterfaceFactoryTest.php

-
message: '#^Callable PhpDb\\Mysql\\Container\\PdoConnectionInterfaceFactory invoked with 1 parameter, 2\-3 required\.$#'
identifier: arguments.count
count: 1
path: test/integration/Container/PdoConnectionInterfaceFactoryTest.php

-
message: '#^Callable PhpDb\\Mysql\\Container\\PdoDriverInterfaceFactory invoked with 1 parameter, 2\-3 required\.$#'
identifier: arguments.count
count: 1
path: test/integration/Container/PdoDriverInterfaceFactoryTest.php

-
message: '#^Parameter \#1 \$container of callable PhpDb\\Mysql\\Container\\PdoDriverInterfaceFactory expects Laminas\\ServiceManager\\ServiceManager, Psr\\Container\\ContainerInterface given\.$#'
identifier: argument.type
count: 1
path: test/integration/Container/PdoDriverInterfaceFactoryTest.php

-
message: '#^Callable PhpDb\\Mysql\\Container\\PdoStatementFactory invoked with 1 parameter, 2\-3 required\.$#'
identifier: arguments.count
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertIsInt\(\) with int will always evaluate to true\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 1
path: test/integration/Container/PdoStatementFactoryTest.php
path: test/integration/Pdo/ConnectionTest.php

-
message: '#^Callable PhpDb\\Mysql\\Container\\PlatformInterfaceFactory invoked with 1 parameter, 2\-3 required\.$#'
identifier: arguments.count
message: '#^Unreachable statement \- code above always terminates\.$#'
identifier: deadCode.unreachable
count: 1
path: test/integration/Container/PlatformInterfaceFactoryTest.php
path: test/integration/Pdo/QueryTest.php

-
message: '#^Callable PhpDb\\Mysql\\Container\\StatementInterfaceFactory invoked with 1 parameter, 2\-3 required\.$#'
identifier: arguments.count
message: '#^Unreachable statement \- code above always terminates\.$#'
identifier: deadCode.unreachable
count: 1
path: test/integration/Container/StatementInterfaceFactoryTest.php
path: test/integration/Pdo/TableGatewayTest.php

-
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertIsInt\(\) with int will always evaluate to true\.$#'
identifier: staticMethod.alreadyNarrowedType
message: '#^Unreachable statement \- code above always terminates\.$#'
identifier: deadCode.unreachable
count: 1
path: test/integration/Pdo/ConnectionTest.php
path: test/integration/TableGatewayTest.php

7 changes: 4 additions & 3 deletions src/Container/PdoConnectionInterfaceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ public function __invoke(
string $requestedName,
?array $options = null
): PdoConnectionInterface&Connection {
if (! is_array($options['connection']) || $options['connection'] === []) {
$conn = $options['connection'] ?? [];
if (! is_array($conn) || $conn === []) {
throw new InvalidConnectionParametersException(
'Connection configuration must be an array of parameters passed via $options["connection"]',
$options['connection']
$conn
);
}

return new Connection($options['connection']);
return new Connection($conn);
}
}
25 changes: 18 additions & 7 deletions test/integration/Container/ConnectionInterfaceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace PhpDbIntegrationTest\Mysql\Container;

use PhpDb\Adapter\AdapterInterface;
use PhpDb\Adapter\Driver\ConnectionInterface;
use PhpDb\Adapter\Exception\InvalidConnectionParametersException;
use PhpDb\Mysql\Connection;
use PhpDb\Mysql\Container\ConnectionInterfaceFactory;
use PHPUnit\Framework\Attributes;
Expand All @@ -21,16 +23,25 @@ final class ConnectionInterfaceFactoryTest extends TestCase

public function testInvokeReturnsMysqliConnection(): void
{
$this->getAdapter([
'db' => [
'driver' => 'Mysqli',
],
]);

$factory = new ConnectionInterfaceFactory();
$connection = $factory($this->container, Connection::class);
$connection = $factory(
$this->container,
Connection::class,
$this->config[AdapterInterface::class]
);

self::assertInstanceOf(ConnectionInterface::class, $connection);
self::assertInstanceOf(Connection::class, $connection);
}

public function testInvokeThrowsExceptionWithoutConnectionConfig(): void
{
$this->expectException(InvalidConnectionParametersException::class);

$factory = new ConnectionInterfaceFactory();
$factory(
$this->container,
Connection::class
);
}
}
25 changes: 19 additions & 6 deletions test/integration/Container/DriverInterfaceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

namespace PhpDbIntegrationTest\Mysql\Container;

use PhpDb\Adapter\AdapterInterface;
use PhpDb\Adapter\Driver\DriverInterface;
use PhpDb\Exception\ContainerException;
use PhpDb\Mysql\Connection;
use PhpDb\Mysql\Container\DriverInterfaceFactory;
use PhpDb\Mysql\Driver;
use PHPUnit\Framework\Attributes;
Expand All @@ -21,14 +24,24 @@ final class DriverInterfaceFactoryTest extends TestCase

public function testFactoryReturnsMysqliDriver(): void
{
$this->getAdapter([
'db' => [
'driver' => 'Mysqli',
],
]);
$factory = new DriverInterfaceFactory();
$driver = $factory($this->container);
$driver = $factory(
$this->container,
DriverInterface::class,
$this->config[AdapterInterface::class]
);
self::assertInstanceOf(DriverInterface::class, $driver);
$this->assertInstanceOf(Driver::class, $driver);
}

public function testInvokeThrowsExceptionWithoutConnectionConfig(): void
{
$this->expectException(ContainerException::class);

$factory = new DriverInterfaceFactory();
$factory(
$this->container,
Connection::class
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class MetadataInterfaceFactoryTest extends TestCase
public function testFactoryReturnsMysqlMetadata(): void
{
$factory = new MetadataInterfaceFactory();
$metadata = $factory($this->container);
$metadata = $factory($this->container, MetadataInterface::class);
self::assertInstanceOf(MetadataInterface::class, $metadata);
self::assertInstanceOf(Source::class, $metadata);
}
Expand Down
19 changes: 18 additions & 1 deletion test/integration/Container/PdoConnectionInterfaceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

namespace PhpDbIntegrationTest\Mysql\Container;

use PhpDb\Adapter\AdapterInterface;
use PhpDb\Adapter\Driver\ConnectionInterface;
use PhpDb\Adapter\Driver\PdoConnectionInterface;
use PhpDb\Adapter\Exception\InvalidConnectionParametersException;
use PhpDb\Mysql\Container\PdoConnectionInterfaceFactory;
use PhpDb\Mysql\Pdo\Connection;
use PHPUnit\Framework\Attributes\CoversClass;
Expand All @@ -24,9 +26,24 @@ final class PdoConnectionInterfaceFactoryTest extends TestCase
public function testInvokeReturnsPdoConnection(): void
{
$factory = new PdoConnectionInterfaceFactory();
$instance = $factory($this->container);
$instance = $factory(
$this->container,
PdoConnectionInterface::class,
$this->config[AdapterInterface::class]
);
self::assertInstanceOf(ConnectionInterface::class, $instance);
self::assertInstanceOf(PdoConnectionInterface::class, $instance);
self::assertInstanceOf(Connection::class, $instance);
}

public function testInvokeThrowsExceptionWithoutConnectionConfig(): void
{
$this->expectException(InvalidConnectionParametersException::class);

$factory = new PdoConnectionInterfaceFactory();
$factory(
$this->container,
PdoConnectionInterface::class
);
}
}
7 changes: 6 additions & 1 deletion test/integration/Container/PdoDriverInterfaceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace PhpDbIntegrationTest\Mysql\Container;

use PhpDb\Adapter\AdapterInterface;
use PhpDb\Adapter\Driver\PdoDriverInterface;
use PhpDb\Mysql\Container\PdoDriverInterfaceFactory;
use PhpDb\Mysql\Pdo\Driver;
Expand All @@ -23,7 +24,11 @@ final class PdoDriverInterfaceFactoryTest extends TestCase
public function testInvokeReturnsPdoDriver(): void
{
$factory = new PdoDriverInterfaceFactory();
$instance = $factory($this->container);
$instance = $factory(
$this->container,
PdoDriverInterface::class,
$this->config[AdapterInterface::class]
);

self::assertInstanceOf(PdoDriverInterface::class, $instance);
self::assertInstanceOf(Driver::class, $instance);
Expand Down
7 changes: 6 additions & 1 deletion test/integration/Container/PdoStatementFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace PhpDbIntegrationTest\Mysql\Container;

use PhpDb\Adapter\AdapterInterface;
use PhpDb\Adapter\Driver\Pdo\Statement;
use PhpDb\Adapter\Driver\StatementInterface;
use PhpDb\Mysql\Container\PdoStatementFactory;
Expand All @@ -23,7 +24,11 @@ final class PdoStatementFactoryTest extends TestCase
public function testInvokeReturnsPdoStatement(): void
{
$factory = new PdoStatementFactory();
$statement = $factory($this->container);
$statement = $factory(
$this->container,
StatementInterface::class,
$this->config[AdapterInterface::class]
);
self::assertInstanceOf(StatementInterface::class, $statement);
self::assertInstanceOf(Statement::class, $statement);
}
Expand Down
13 changes: 12 additions & 1 deletion test/integration/Container/PlatformInterfaceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

namespace PhpDbIntegrationTest\Mysql\Container;

use PhpDb\Adapter\AdapterInterface;
use PhpDb\Adapter\Platform\PlatformInterface;
use PhpDb\Mysql\AdapterPlatform;
use PhpDb\Mysql\Container\PlatformInterfaceFactory;
use PhpDb\Mysql\Pdo\Driver as PdoDriver;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\Attributes\Group;
Expand All @@ -22,8 +24,17 @@ final class PlatformInterfaceFactoryTest extends TestCase

public function testInvokeReturnsPlatformInterfaceWhenDbDriverIsPdo(): void
{
$adapter = $this->getAdapter(['driver' => PdoDriver::class]);

$this->config[AdapterInterface::class]['driver'] = $adapter->getDriver();

$factory = new PlatformInterfaceFactory();
$instance = $factory($this->container);
$instance = $factory(
$this->container,
PlatformInterface::class,
$this->config[AdapterInterface::class]
);

self::assertInstanceOf(PlatformInterface::class, $instance);
self::assertInstanceOf(AdapterPlatform::class, $instance);
}
Expand Down
7 changes: 6 additions & 1 deletion test/integration/Container/StatementInterfaceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace PhpDbIntegrationTest\Mysql\Container;

use PhpDb\Adapter\AdapterInterface;
use PhpDb\Adapter\Driver\StatementInterface;
use PhpDb\Mysql\Container\StatementInterfaceFactory;
use PhpDb\Mysql\Statement;
Expand Down Expand Up @@ -31,7 +32,11 @@ public function testInvokeReturnsMysqliStatement(): void
]);

$factory = new StatementInterfaceFactory();
$statement = $factory($this->container);
$statement = $factory(
$this->container,
StatementInterface::class,
$this->config[AdapterInterface::class]
);

self::assertInstanceOf(StatementInterface::class, $statement);
self::assertInstanceOf(Statement::class, $statement);
Expand Down
Loading