Skip to content

Commit 19c442a

Browse files
committed
QA fixes
Signed-off-by: Joey Smith <jsmith@webinertia.net> Signed-off-by: Joey Smith <jsmith@webinertia.net>
1 parent 7ad36e1 commit 19c442a

10 files changed

+116
-220
lines changed

src/ConfigProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
final class ConfigProvider
88
{
9-
public final const NAMED_ADAPTER_KEY = 'adapters';
9+
public const NAMED_ADAPTER_KEY = 'adapters';
1010
public function __invoke(): array
1111
{
1212
return [
@@ -33,7 +33,7 @@ public function getDependencies(): array
3333
{
3434
return [
3535
'abstract_factories' => [
36-
Container\AdapterAbstractServiceFactory::class,
36+
Container\AbstractAdapterInterfaceFactory::class,
3737
],
3838
'aliases' => [
3939
Adapter\AdapterInterface::class => Adapter\Adapter::class,

src/Container/AbstractAdapterInterfaceFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use PhpDb\ConfigProvider;
1616
use PhpDb\Exception\ContainerException;
1717
use PhpDb\ResultSet\ResultSetInterface;
18-
use PSpell\Config;
1918
use Psr\Container\ContainerInterface;
2019

2120
use function is_array;
@@ -52,10 +51,11 @@ public function canCreate(ContainerInterface $container, $requestedName): bool
5251
/**
5352
* Create a DB adapter
5453
*
54+
* @phpstan-param ContainerInterface&ServiceManager $container
5555
* @param string $requestedName
5656
*/
5757
public function __invoke(
58-
ContainerInterface&ServiceManager $container,
58+
ContainerInterface|ServiceManager $container,
5959
$requestedName,
6060
?array $options = null
6161
): AdapterInterface&Adapter {
@@ -72,7 +72,7 @@ public function __invoke(
7272

7373
/** @var DriverInterface|PdoDriverInterface $driver */
7474
$driver = $container->build($driverClass, $this->config[$requestedName]);
75-
/** @var PlatformInterface&Pgsql\AdapterPlatform $platform */
75+
/** @var PlatformInterface $platform */
7676
$platform = $container->build(PlatformInterface::class, ['driver' => $driver]);
7777
/** @var ResultSetInterface|null $resultSet */
7878
$resultSet = $container->has(ResultSetInterface::class)

src/Container/ConnectionInterfaceFactoryFactoryInterface.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/Container/DriverInterfaceFactoryFactoryInterface.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/Container/FactoryFactoryInterface.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/Container/PlatformInterfaceFactoryFactoryInterface.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/Exception/ContainerException.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Psr\Container\ContainerExceptionInterface;
88
use RuntimeException as SplRuntimeException;
99

10+
use function sprintf;
11+
1012
final class ContainerException extends SplRuntimeException implements ContainerExceptionInterface
1113
{
1214
public static function forService(
@@ -17,9 +19,9 @@ public static function forService(
1719
return new self(
1820
sprintf(
1921
'Failed to create service "%s" in factory %s Reason: %s',
20-
$serviceName,
21-
$factoryClass,
22-
$reason
22+
$serviceName,
23+
$factoryClass,
24+
$reason
2325
),
2426
0,
2527
);
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpDbTest\Adapter\Container;
6+
7+
use Laminas\ServiceManager\Exception\ServiceNotFoundException;
8+
use Laminas\ServiceManager\ServiceManager;
9+
use Override;
10+
use PhpDb\Adapter\AdapterInterface;
11+
use PhpDb\Adapter\Driver\PdoDriverInterface;
12+
use PhpDb\Adapter\Platform\PlatformInterface;
13+
use PhpDb\Container\AbstractAdapterInterfaceFactory;
14+
use PhpDbTest\TestAsset\PdoStubDriver;
15+
use PHPUnit\Framework\Attributes\DataProvider;
16+
use PHPUnit\Framework\MockObject\MockObject;
17+
use PHPUnit\Framework\TestCase;
18+
use Psr\Container\ContainerExceptionInterface;
19+
use Psr\Container\ContainerInterface;
20+
use Psr\Container\NotFoundExceptionInterface;
21+
22+
final class AbstractAdapterInterfaceFactoryTest extends TestCase
23+
{
24+
private ContainerInterface|ServiceManager $serviceManager;
25+
26+
#[Override]
27+
protected function setUp(): void
28+
{
29+
/** @var PdoDriverInterface&MockObject $pdoDriverInterfaceMock */
30+
$pdoDriverInterfaceMock = $this->getMockBuilder(PdoDriverInterface::class)->getMock();
31+
/** @var PlatformInterface&MockObject $platformMock */
32+
$platformMock = $this->getMockBuilder(PlatformInterface::class)->getMock();
33+
34+
$config = [
35+
'abstract_factories' => [AbstractAdapterInterfaceFactory::class],
36+
'factories' => [
37+
PdoStubDriver::class => static function (
38+
ContainerInterface $container
39+
) use ($pdoDriverInterfaceMock): PdoDriverInterface {
40+
return $pdoDriverInterfaceMock;
41+
},
42+
PlatformInterface::class => static function (
43+
ContainerInterface $container
44+
) use ($platformMock): PlatformInterface {
45+
return $platformMock;
46+
},
47+
],
48+
];
49+
50+
$this->serviceManager = new ServiceManager($config);
51+
52+
$this->serviceManager->setService('config', [
53+
AdapterInterface::class => [
54+
'adapters' => [
55+
'PhpDb\Adapter\Writer' => [
56+
'driver' => PdoStubDriver::class,
57+
],
58+
'PhpDb\Adapter\Reader' => [
59+
'driver' => PdoStubDriver::class,
60+
],
61+
],
62+
],
63+
]);
64+
}
65+
66+
public static function providerValidService(): array
67+
{
68+
return [
69+
['PhpDb\Adapter\Writer'],
70+
['PhpDb\Adapter\Reader'],
71+
];
72+
}
73+
74+
public static function providerInvalidService(): array
75+
{
76+
return [
77+
['PhpDb\Adapter\Unknown'],
78+
];
79+
}
80+
81+
/**
82+
* @throws ContainerExceptionInterface
83+
* @throws NotFoundExceptionInterface
84+
*/
85+
#[DataProvider('providerValidService')]
86+
public function testValidService(string $service): void
87+
{
88+
$actual = $this->serviceManager->get($service);
89+
self::assertInstanceOf(AdapterInterface::class, $actual);
90+
}
91+
92+
/**
93+
* @throws ContainerExceptionInterface
94+
* @throws NotFoundExceptionInterface
95+
*/
96+
#[DataProvider('providerInvalidService')]
97+
public function testInvalidService(string $service): void
98+
{
99+
$this->expectException(ServiceNotFoundException::class);
100+
$this->serviceManager->get($service);
101+
}
102+
}

test/unit/Adapter/Container/AdapterAbstractServiceFactoryTest.php

Lines changed: 0 additions & 172 deletions
This file was deleted.

0 commit comments

Comments
 (0)