Skip to content

Commit 6d91edf

Browse files
committed
fix test
Signed-off-by: Joey Smith <jsmith@webinertia.net>
1 parent 58d2595 commit 6d91edf

8 files changed

Lines changed: 20 additions & 71 deletions

phpstan-baseline.neon

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,2 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: '#^Callable PhpDb\\Sqlite\\Container\\PdoStatementFactory invoked with 1 parameter, 2\-3 required\.$#'
5-
identifier: arguments.count
6-
count: 1
7-
path: test/integration/Container/PdoStatementFactoryTest.php
8-
9-
-
10-
message: '#^Callable PhpDb\\Sqlite\\Container\\PdoStatementFactory invoked with 1 parameter, 2\-3 required\.$#'
11-
identifier: arguments.count
12-
count: 3
13-
path: test/unit/Container/PdoStatementFactoryTest.php

src/Container/PdoConnectionFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use PhpDb\Sqlite\Pdo\Connection;
1010
use Psr\Container\ContainerInterface;
1111

12+
use function is_array;
13+
1214
final class PdoConnectionFactory
1315
{
1416
public function __invoke(

test/integration/Container/PdoConnectionFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class PdoConnectionFactoryTest extends TestCase
2424
public function testInvokeReturnsPdoConnection(): void
2525
{
2626
$factory = new PdoConnectionFactory();
27-
$instance = $factory($this->container);
27+
$instance = $factory($this->container, Connection::class, ['connection' => ['dsn' => 'sqlite::memory:']]);
2828
self::assertInstanceOf(ConnectionInterface::class, $instance);
2929
self::assertInstanceOf(PdoConnectionInterface::class, $instance);
3030
self::assertInstanceOf(Connection::class, $instance);

test/integration/Container/PdoStatementFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class PdoStatementFactoryTest extends TestCase
2323
public function testInvokeReturnsPdoStatement(): void
2424
{
2525
$factory = new PdoStatementFactory();
26-
$statement = $factory($this->container);
26+
$statement = $factory($this->container, Statement::class, []);
2727
self::assertInstanceOf(StatementInterface::class, $statement);
2828
self::assertInstanceOf(Statement::class, $statement);
2929
}

test/integration/Container/SqliteMetadataFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ final class SqliteMetadataFactoryTest extends TestCase
2020
public function testFactoryReturnsMysqlMetadata(): void
2121
{
2222
$factory = new MetadataInterfaceFactory();
23-
$metadata = $factory($this->container);
23+
$metadata = $factory($this->container, Metadata\Source::class);
2424
self::assertInstanceOf(MetadataInterface::class, $metadata);
2525
self::assertInstanceOf(Metadata\Source::class, $metadata);
2626
}

test/unit/Container/MetadataInterfaceFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testInvokeReturnsMetadata(): void
3333
->willReturn($adapterMock);
3434

3535
$factory = new MetadataInterfaceFactory();
36-
$metadata = $factory($containerMock);
36+
$metadata = $factory($containerMock, Metadata\Source::class);
3737

3838
self::assertInstanceOf(Metadata\Source::class, $metadata);
3939
}

test/unit/Container/PdoConnectionFactoryTest.php

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpDbTest\Sqlite\Container;
66

7+
use PhpDb\Adapter\Exception\InvalidConnectionParametersException;
78
use PhpDb\Sqlite\Container\PdoConnectionFactory;
89
use PhpDb\Sqlite\Pdo\Connection;
910
use PHPUnit\Framework\Attributes\CoversClass;
@@ -16,47 +17,30 @@ final class PdoConnectionFactoryTest extends TestCase
1617
public function testInvokeReturnsConnection(): void
1718
{
1819
$containerMock = $this->createMock(ContainerInterface::class);
19-
$containerMock->method('get')
20-
->with('config')
21-
->willReturn([
22-
'db' => [
23-
'connection' => [
24-
'dsn' => 'sqlite::memory:',
25-
],
26-
],
27-
]);
2820

2921
$factory = new PdoConnectionFactory();
30-
$connection = $factory($containerMock);
22+
$connection = $factory($containerMock, Connection::class, ['connection' => ['dsn' => 'sqlite::memory:']]);
3123

3224
self::assertInstanceOf(Connection::class, $connection);
3325
}
3426

35-
public function testInvokeWithoutConnectionConfig(): void
27+
public function testInvokeWithoutConnectionConfigThrows(): void
3628
{
3729
$containerMock = $this->createMock(ContainerInterface::class);
38-
$containerMock->method('get')
39-
->with('config')
40-
->willReturn([
41-
'db' => [],
42-
]);
4330

44-
$factory = new PdoConnectionFactory();
45-
$connection = $factory($containerMock);
31+
$this->expectException(InvalidConnectionParametersException::class);
4632

47-
self::assertInstanceOf(Connection::class, $connection);
33+
$factory = new PdoConnectionFactory();
34+
$factory($containerMock, Connection::class, []);
4835
}
4936

50-
public function testInvokeWithoutDbConfig(): void
37+
public function testInvokeWithNullOptionsThrows(): void
5138
{
5239
$containerMock = $this->createMock(ContainerInterface::class);
53-
$containerMock->method('get')
54-
->with('config')
55-
->willReturn([]);
5640

57-
$factory = new PdoConnectionFactory();
58-
$connection = $factory($containerMock);
41+
$this->expectException(InvalidConnectionParametersException::class);
5942

60-
self::assertInstanceOf(Connection::class, $connection);
43+
$factory = new PdoConnectionFactory();
44+
$factory($containerMock, Connection::class, null);
6145
}
6246
}

test/unit/Container/PdoStatementFactoryTest.php

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace PhpDbTest\Sqlite\Container;
66

7-
use PhpDb\Adapter\AdapterInterface;
87
use PhpDb\Adapter\Driver\Pdo\Statement;
98
use PhpDb\Sqlite\Container\PdoStatementFactory;
109
use PHPUnit\Framework\Attributes\CoversClass;
@@ -14,47 +13,22 @@
1413
#[CoversClass(PdoStatementFactory::class)]
1514
final class PdoStatementFactoryTest extends TestCase
1615
{
17-
public function testInvokeReturnsStatement(): void
16+
public function testInvokeReturnsStatementWithOptions(): void
1817
{
1918
$containerMock = $this->createMock(ContainerInterface::class);
20-
$containerMock->method('get')
21-
->with('config')
22-
->willReturn([
23-
AdapterInterface::class => [
24-
'options' => [],
25-
],
26-
]);
2719

2820
$factory = new PdoStatementFactory();
29-
$statement = $factory($containerMock);
21+
$statement = $factory($containerMock, Statement::class, ['key' => 'value']);
3022

3123
self::assertInstanceOf(Statement::class, $statement);
3224
}
3325

34-
public function testInvokeWithoutOptionsConfig(): void
26+
public function testInvokeReturnsStatementWithEmptyOptions(): void
3527
{
3628
$containerMock = $this->createMock(ContainerInterface::class);
37-
$containerMock->method('get')
38-
->with('config')
39-
->willReturn([
40-
AdapterInterface::class => [],
41-
]);
4229

4330
$factory = new PdoStatementFactory();
44-
$statement = $factory($containerMock);
45-
46-
self::assertInstanceOf(Statement::class, $statement);
47-
}
48-
49-
public function testInvokeWithoutDbConfig(): void
50-
{
51-
$containerMock = $this->createMock(ContainerInterface::class);
52-
$containerMock->method('get')
53-
->with('config')
54-
->willReturn([]);
55-
56-
$factory = new PdoStatementFactory();
57-
$statement = $factory($containerMock);
31+
$statement = $factory($containerMock, Statement::class, []);
5832

5933
self::assertInstanceOf(Statement::class, $statement);
6034
}

0 commit comments

Comments
 (0)