Skip to content

Commit 0b654b6

Browse files
committed
Fixed tests in Unit and Integration
Signed-off-by: Simon Mundy <simon.mundy@peptolab.com>
1 parent e70ce59 commit 0b654b6

48 files changed

Lines changed: 288 additions & 233 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

phpstan-baseline.neon

Lines changed: 79 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -4,169 +4,175 @@ parameters:
44
message: '#^Method PhpDb\\Adapter\\Profiler\\ProfilerInterface\:\:profilerFinish\(\) invoked with 1 parameter, 0 required\.$#'
55
identifier: arguments.count
66
count: 1
7-
path: src/Driver/Mysqli/Connection.php
7+
path: src/Connection.php
88

99
-
10-
message: '#^Property PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Connection\:\:\$driver \(PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Mysqli\) does not accept PhpDb\\Adapter\\Driver\\DriverInterface\.$#'
10+
message: '#^Property PhpDb\\Mysql\\Connection\:\:\$driver \(PhpDb\\Mysql\\Driver\) does not accept PhpDb\\Adapter\\Driver\\DriverInterface\.$#'
1111
identifier: assign.propertyType
1212
count: 1
13-
path: src/Driver/Mysqli/Connection.php
13+
path: src/Connection.php
1414

1515
-
16-
message: '#^Property PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Connection\:\:\$resource \(mysqli\) does not accept null\.$#'
16+
message: '#^Property PhpDb\\Mysql\\Connection\:\:\$resource \(mysqli\) does not accept null\.$#'
1717
identifier: assign.propertyType
1818
count: 1
19-
path: src/Driver/Mysqli/Connection.php
19+
path: src/Connection.php
2020

2121
-
2222
message: '#^Strict comparison using \!\=\= between null and null will always evaluate to false\.$#'
2323
identifier: notIdentical.alwaysFalse
2424
count: 1
25-
path: src/Driver/Mysqli/Connection.php
25+
path: src/Connection.php
2626

2727
-
2828
message: '#^Variable \$names in PHPDoc tag @var does not match assigned variable \$findParameterValue\.$#'
2929
identifier: varTag.differentVariable
3030
count: 1
31-
path: src/Driver/Mysqli/Connection.php
31+
path: src/Connection.php
3232

3333
-
34-
message: '#^Instanceof between PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Connection and PhpDb\\Adapter\\Driver\\DriverAwareInterface will always evaluate to true\.$#'
34+
message: '#^Instanceof between PhpDb\\Mysql\\Connection and PhpDb\\Adapter\\Driver\\DriverAwareInterface will always evaluate to true\.$#'
3535
identifier: instanceof.alwaysTrue
3636
count: 1
37-
path: src/Driver/Mysqli/Mysqli.php
37+
path: src/Driver.php
3838

3939
-
40-
message: '#^Instanceof between PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Connection and PhpDb\\Adapter\\Profiler\\ProfilerAwareInterface will always evaluate to true\.$#'
40+
message: '#^Instanceof between PhpDb\\Mysql\\Connection and PhpDb\\Adapter\\Profiler\\ProfilerAwareInterface will always evaluate to true\.$#'
4141
identifier: instanceof.alwaysTrue
4242
count: 1
43-
path: src/Driver/Mysqli/Mysqli.php
43+
path: src/Driver.php
4444

4545
-
46-
message: '#^Instanceof between PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Statement and PhpDb\\Adapter\\Driver\\DriverAwareInterface will always evaluate to true\.$#'
46+
message: '#^Instanceof between PhpDb\\Mysql\\Statement and PhpDb\\Adapter\\Driver\\DriverAwareInterface will always evaluate to true\.$#'
4747
identifier: instanceof.alwaysTrue
4848
count: 1
49-
path: src/Driver/Mysqli/Mysqli.php
49+
path: src/Driver.php
5050

5151
-
52-
message: '#^Instanceof between PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Statement and PhpDb\\Adapter\\Profiler\\ProfilerAwareInterface will always evaluate to true\.$#'
52+
message: '#^Instanceof between PhpDb\\Mysql\\Statement and PhpDb\\Adapter\\Profiler\\ProfilerAwareInterface will always evaluate to true\.$#'
5353
identifier: instanceof.alwaysTrue
5454
count: 1
55-
path: src/Driver/Mysqli/Mysqli.php
55+
path: src/Driver.php
5656

5757
-
58-
message: '#^Method PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Mysqli\:\:getResultPrototype\(\) should return PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Result but returns PhpDb\\Adapter\\Driver\\ResultInterface\.$#'
58+
message: '#^Method PhpDb\\Mysql\\Driver\:\:getResultPrototype\(\) should return PhpDb\\Mysql\\Result but returns PhpDb\\Adapter\\Driver\\ResultInterface\.$#'
5959
identifier: return.type
6060
count: 1
61-
path: src/Driver/Mysqli/Mysqli.php
61+
path: src/Driver.php
6262

6363
-
64-
message: '#^Parameter \#1 \$resource \(mysqli\|mysqli_stmt\|PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\mysqli_result\) of method PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Mysqli\:\:createResult\(\) should be compatible with parameter \$resource \(resource\) of method PhpDb\\Adapter\\Driver\\DriverInterface\:\:createResult\(\)$#'
64+
message: '#^Parameter \#1 \$resource \(mysqli\|mysqli_stmt\|PhpDb\\Mysql\\mysqli_result\) of method PhpDb\\Mysql\\Driver\:\:createResult\(\) should be compatible with parameter \$resource \(resource\) of method PhpDb\\Adapter\\Driver\\DriverInterface\:\:createResult\(\)$#'
6565
identifier: method.childParameterType
6666
count: 1
67-
path: src/Driver/Mysqli/Mysqli.php
67+
path: src/Driver.php
6868

6969
-
70-
message: '#^Parameter \$resource of method PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Mysqli\:\:createResult\(\) has invalid type PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\mysqli_result\.$#'
70+
message: '#^Parameter \$resource of method PhpDb\\Mysql\\Driver\:\:createResult\(\) has invalid type PhpDb\\Mysql\\mysqli_result\.$#'
7171
identifier: class.notFound
7272
count: 1
73-
path: src/Driver/Mysqli/Mysqli.php
73+
path: src/Driver.php
74+
75+
-
76+
message: '#^Parameter \#2 \$array of function implode expects array\<string\>, array\<int, array\<int, string\>\> given\.$#'
77+
identifier: argument.type
78+
count: 2
79+
path: src/Metadata/Source.php
80+
81+
-
82+
message: '#^Parameter \#2 \$array of function implode expects array\<string\>, array\<int, list\<string\>\> given\.$#'
83+
identifier: argument.type
84+
count: 4
85+
path: src/Metadata/Source.php
86+
87+
-
88+
message: '#^Variable \$isFK might not be defined\.$#'
89+
identifier: variable.undefined
90+
count: 1
91+
path: src/Metadata/Source.php
92+
93+
-
94+
message: '#^Variable \$name might not be defined\.$#'
95+
identifier: variable.undefined
96+
count: 2
97+
path: src/Metadata/Source.php
98+
99+
-
100+
message: '#^Call to function is_string\(\) with string will always evaluate to true\.$#'
101+
identifier: function.alreadyNarrowedType
102+
count: 1
103+
path: src/Pdo/Connection.php
104+
105+
-
106+
message: '#^Parameter \#1 \$resource \(PDOStatement\) of method PhpDb\\Mysql\\Pdo\\Driver\:\:createResult\(\) should be compatible with parameter \$resource \(resource\) of method PhpDb\\Adapter\\Driver\\DriverInterface\:\:createResult\(\)$#'
107+
identifier: method.childParameterType
108+
count: 3
109+
path: src/Pdo/Driver.php
110+
111+
-
112+
message: '#^Parameter \#3 \$rowCount of method PhpDb\\Adapter\\Driver\\Pdo\\Result\:\:initialize\(\) expects Closure\|int, null given\.$#'
113+
identifier: argument.type
114+
count: 1
115+
path: src/Pdo/Driver.php
74116

75117
-
76118
message: '#^Instanceof between mysqli_stmt and mysqli_stmt will always evaluate to true\.$#'
77119
identifier: instanceof.alwaysTrue
78120
count: 2
79-
path: src/Driver/Mysqli/Result.php
121+
path: src/Result.php
80122

81123
-
82-
message: '#^Method PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Result\:\:initialize\(\) has PhpDb\\Adapter\\Exception\\InvalidArgumentException in PHPDoc @throws tag but it''s not thrown\.$#'
124+
message: '#^Method PhpDb\\Mysql\\Result\:\:initialize\(\) has PhpDb\\Adapter\\Exception\\InvalidArgumentException in PHPDoc @throws tag but it''s not thrown\.$#'
83125
identifier: throws.unusedType
84126
count: 1
85-
path: src/Driver/Mysqli/Result.php
127+
path: src/Result.php
86128

87129
-
88-
message: '#^Method PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Result\:\:isBuffered\(\) never returns null so it can be removed from the return type\.$#'
130+
message: '#^Method PhpDb\\Mysql\\Result\:\:isBuffered\(\) never returns null so it can be removed from the return type\.$#'
89131
identifier: return.unusedType
90132
count: 1
91-
path: src/Driver/Mysqli/Result.php
133+
path: src/Result.php
92134

93135
-
94136
message: '#^Result of && is always false\.$#'
95137
identifier: booleanAnd.alwaysFalse
96138
count: 1
97-
path: src/Driver/Mysqli/Result.php
139+
path: src/Result.php
98140

99141
-
100142
message: '#^Instanceof between PhpDb\\Adapter\\ParameterContainer and PhpDb\\Adapter\\ParameterContainer will always evaluate to true\.$#'
101143
identifier: instanceof.alwaysTrue
102144
count: 1
103-
path: src/Driver/Mysqli/Statement.php
145+
path: src/Statement.php
104146

105147
-
106148
message: '#^Instanceof between mysqli_stmt and mysqli_stmt will always evaluate to true\.$#'
107149
identifier: instanceof.alwaysTrue
108150
count: 1
109-
path: src/Driver/Mysqli/Statement.php
151+
path: src/Statement.php
110152

111153
-
112-
message: '#^Method PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Statement\:\:execute\(\) never returns null so it can be removed from the return type\.$#'
154+
message: '#^Method PhpDb\\Mysql\\Statement\:\:execute\(\) never returns null so it can be removed from the return type\.$#'
113155
identifier: return.unusedType
114156
count: 1
115-
path: src/Driver/Mysqli/Statement.php
157+
path: src/Statement.php
116158

117159
-
118-
message: '#^Method PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Statement\:\:getParameterContainer\(\) never returns null so it can be removed from the return type\.$#'
160+
message: '#^Method PhpDb\\Mysql\\Statement\:\:getParameterContainer\(\) never returns null so it can be removed from the return type\.$#'
119161
identifier: return.unusedType
120162
count: 1
121-
path: src/Driver/Mysqli/Statement.php
163+
path: src/Statement.php
122164

123165
-
124-
message: '#^Method PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Statement\:\:getSql\(\) never returns null so it can be removed from the return type\.$#'
166+
message: '#^Method PhpDb\\Mysql\\Statement\:\:getSql\(\) never returns null so it can be removed from the return type\.$#'
125167
identifier: return.unusedType
126168
count: 1
127-
path: src/Driver/Mysqli/Statement.php
169+
path: src/Statement.php
128170

129171
-
130-
message: '#^Property PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Statement\:\:\$driver \(PhpDb\\Adapter\\Mysql\\Driver\\Mysqli\\Mysqli\) does not accept PhpDb\\Adapter\\Driver\\DriverInterface\.$#'
172+
message: '#^Property PhpDb\\Mysql\\Statement\:\:\$driver \(PhpDb\\Mysql\\Driver\) does not accept PhpDb\\Adapter\\Driver\\DriverInterface\.$#'
131173
identifier: assign.propertyType
132174
count: 1
133-
path: src/Driver/Mysqli/Statement.php
134-
135-
-
136-
message: '#^Call to function is_string\(\) with string will always evaluate to true\.$#'
137-
identifier: function.alreadyNarrowedType
138-
count: 1
139-
path: src/Driver/Pdo/Connection.php
140-
141-
-
142-
message: '#^Parameter \#1 \$resource \(PDOStatement\) of method PhpDb\\Adapter\\Mysql\\Driver\\Pdo\\Pdo\:\:createResult\(\) should be compatible with parameter \$resource \(resource\) of method PhpDb\\Adapter\\Driver\\DriverInterface\:\:createResult\(\)$#'
143-
identifier: method.childParameterType
144-
count: 3
145-
path: src/Driver/Pdo/Pdo.php
146-
147-
-
148-
message: '#^Parameter \#2 \$array of function implode expects array\<string\>, array\<int, array\<int, string\>\> given\.$#'
149-
identifier: argument.type
150-
count: 2
151-
path: src/Metadata/Source/MysqlMetadata.php
152-
153-
-
154-
message: '#^Parameter \#2 \$array of function implode expects array\<string\>, array\<int, list\<string\>\> given\.$#'
155-
identifier: argument.type
156-
count: 4
157-
path: src/Metadata/Source/MysqlMetadata.php
158-
159-
-
160-
message: '#^Variable \$isFK might not be defined\.$#'
161-
identifier: variable.undefined
162-
count: 1
163-
path: src/Metadata/Source/MysqlMetadata.php
164-
165-
-
166-
message: '#^Variable \$name might not be defined\.$#'
167-
identifier: variable.undefined
168-
count: 2
169-
path: src/Metadata/Source/MysqlMetadata.php
175+
path: src/Statement.php
170176

171177
-
172178
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertIsInt\(\) with int will always evaluate to true\.$#'

phpunit.xml.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
failOnWarning="true">
1212

1313
<extensions>
14-
<bootstrap class="PhpDbIntegrationTest\Adapter\Mysql\Extension\ListenerExtension" />
14+
<bootstrap class="PhpDbIntegrationTest\Mysql\Extension\ListenerExtension" />
1515
</extensions>
1616
<testsuites>
1717
<testsuite name="unit test">
@@ -27,7 +27,7 @@
2727
</include>
2828
</source>
2929
<php>
30-
<env name="TESTS_PHPDB_ADAPTER_MYSQL" value="true"/>
30+
<env name="TESTS_PHPDB_ADAPTER_MYSQL" value="false"/>
3131
<env name="TESTS_PHPDB_ADAPTER_MYSQL_HOSTNAME" value="mysql"/>
3232
<env name="TESTS_PHPDB_ADAPTER_MYSQL_USERNAME" value="root"/>
3333
<env name="TESTS_PHPDB_ADAPTER_MYSQL_PASSWORD" value=""/>

src/Connection.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace PhpDb\Mysql;
66

77
use Exception as GenericException;
8+
use mysqli;
89
use Override;
910
use PhpDb\Adapter\Driver\AbstractConnection;
1011
use PhpDb\Adapter\Driver\ConnectionInterface;
@@ -27,7 +28,7 @@ class Connection extends AbstractConnection implements DriverAwareInterface
2728
{
2829
protected Driver $driver;
2930

30-
/** @var \mysqli */
31+
/** @var mysqli */
3132
protected $resource;
3233

3334
/**
@@ -36,11 +37,11 @@ class Connection extends AbstractConnection implements DriverAwareInterface
3637
* @throws InvalidArgumentException
3738
*/
3839
public function __construct(
39-
array|\mysqli|null $connectionInfo = null
40+
array|mysqli|null $connectionInfo = null
4041
) {
4142
if (is_array($connectionInfo)) {
4243
$this->setConnectionParameters($connectionInfo);
43-
} elseif ($connectionInfo instanceof \mysqli) {
44+
} elseif ($connectionInfo instanceof mysqli) {
4445
$this->setResource($connectionInfo);
4546
} elseif (null !== $connectionInfo) {
4647
throw new Exception\InvalidArgumentException(
@@ -75,7 +76,7 @@ public function getCurrentSchema(): string|false
7576
*
7677
* @return $this Provides a fluent interface
7778
*/
78-
public function setResource(\mysqli $resource): static
79+
public function setResource(mysqli $resource): static
7980
{
8081
$this->resource = $resource;
8182

@@ -86,7 +87,7 @@ public function setResource(\mysqli $resource): static
8687
#[Override]
8788
public function connect(): ConnectionInterface
8889
{
89-
if ($this->resource instanceof \mysqli) {
90+
if ($this->resource instanceof mysqli) {
9091
return $this;
9192
}
9293

@@ -185,14 +186,14 @@ public function connect(): ConnectionInterface
185186
/** @inheritDoc */
186187
public function isConnected(): bool
187188
{
188-
return $this->resource instanceof \mysqli;
189+
return $this->resource instanceof mysqli;
189190
}
190191

191192
/** @inheritDoc */
192193
#[Override]
193194
public function disconnect(): ConnectionInterface
194195
{
195-
if ($this->resource instanceof \mysqli) {
196+
if ($this->resource instanceof mysqli) {
196197
$this->resource->close();
197198
}
198199
$this->resource = null;
@@ -285,10 +286,10 @@ public function getLastGeneratedValue(?string $name = null): string|int|false|nu
285286
*
286287
* todo: why do we have this random method here?
287288
*
288-
* @return \mysqli
289+
* @return mysqli
289290
*/
290291
protected function createResource()
291292
{
292-
return new \mysqli();
293+
return new mysqli();
293294
}
294295
}

src/Container/ConnectionInterfaceFactory.php

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

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

src/Container/DriverInterfaceFactory.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
namespace PhpDb\Mysql\Container;
66

77
use Laminas\ServiceManager\ServiceManager;
8+
use PhpDb\Adapter\Driver\ConnectionInterface;
89
use PhpDb\Adapter\Driver\DriverInterface;
910
use PhpDb\Adapter\Driver\ResultInterface;
11+
use PhpDb\Adapter\Driver\StatementInterface;
1012
use PhpDb\Exception\ContainerException;
1113
use PhpDb\Mysql\Connection;
1214
use PhpDb\Mysql\Driver;
@@ -29,16 +31,16 @@ public function __invoke(
2931
);
3032
}
3133

32-
/** @var Driver\ConnectionInterface&Connection $connectionInstance */
34+
/** @var ConnectionInterface&Connection $connectionInstance */
3335
$connectionInstance = $container->build(Connection::class, $options);
3436

35-
/** @var Driver\StatementInterface&Statement $statementInstance */
37+
/** @var StatementInterface&Statement $statementInstance */
3638
$statementInstance = $container->build(
3739
Statement::class,
3840
$options['options'] ?? []
3941
);
4042

41-
/** @var Driver\ResultInterface&Result $resultInstance */
43+
/** @var ResultInterface&Result $resultInstance */
4244
$resultInstance = $container->has(ResultInterface::class)
4345
? $container->get(ResultInterface::class)
4446
: new Result();

0 commit comments

Comments
 (0)