44
55namespace PhpDbTest \Sqlite \Container ;
66
7+ use PhpDb \Adapter \Exception \InvalidConnectionParametersException ;
78use PhpDb \Sqlite \Container \PdoConnectionFactory ;
89use PhpDb \Sqlite \Pdo \Connection ;
910use 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}
0 commit comments