Skip to content

Commit c0d6924

Browse files
authored
Merge branch '0.6.x' into fix-connection-doc
2 parents e25e95b + 602d3ce commit c0d6924

70 files changed

Lines changed: 4523 additions & 571 deletions

File tree

Some content is hidden

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

‎phpunit.xml.dist‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
<testsuites>
1919
<testsuite name="unit test">
2020
<directory>./test/unit</directory>
21-
<exclude>./test/unit/Adapter/AdapterServiceFactoryTest.php</exclude>
22-
<exclude>./test/unit/Adapter/Driver/Pdo/ConnectionIntegrationTest.php</exclude>
23-
<exclude>./test/unit/Adapter/Driver/Pdo/StatementIntegrationTest.php</exclude>
24-
<exclude>./test/unit/Adapter/AdapterAwareTraitTest.php</exclude>
2521
</testsuite>
2622
<testsuite name="integration test">
2723
<directory>./test/integration</directory>

‎src/Adapter/Driver/Pdo/AbstractPdo.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ public function getProfiler(): ?ProfilerInterface
6161
public function checkEnvironment(): bool
6262
{
6363
if (! extension_loaded('PDO')) {
64+
// @codeCoverageIgnoreStart
6465
throw new Exception\RuntimeException(
6566
'The PDO extension is required for this adapter but the extension is not loaded'
6667
);
68+
// @codeCoverageIgnoreEnd
6769
}
6870
return true;
6971
}

‎src/Adapter/Driver/Pdo/Statement.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ public function execute(null|array|ParameterContainer $parameters = null): ?Resu
157157

158158
/** START Standard ParameterContainer Merging Block */
159159
if ($parameters instanceof ParameterContainer) {
160-
$this->parameterContainer = $parameters;
161-
$parameters = null;
160+
$this->parameterContainer = $parameters;
161+
$parameters = null;
162162
}
163163

164164
if (is_array($parameters)) {

‎src/ResultSet/AbstractResultSet.php‎

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use function gettype;
2121
use function is_array;
2222
use function is_object;
23-
use function key;
2423
use function method_exists;
2524
use function reset;
2625

@@ -80,12 +79,9 @@ public function initialize(iterable $dataSource): ResultSetInterface
8079
} elseif ($dataSource instanceof IteratorAggregate) {
8180
/** @phpstan-ignore assign.propertyType */
8281
$this->dataSource = $dataSource->getIterator();
83-
} elseif ($dataSource instanceof Iterator) {
84-
$this->dataSource = $dataSource;
8582
} else {
86-
throw new InvalidArgumentException(
87-
'DataSource provided is not an array, nor does it implement Iterator or IteratorAggregate'
88-
);
83+
/** @phpstan-ignore assign.propertyType */
84+
$this->dataSource = $dataSource;
8985
}
9086

9187
return $this;
@@ -214,12 +210,7 @@ public function valid(): bool
214210
return true;
215211
}
216212

217-
if ($this->dataSource instanceof Iterator) {
218-
return $this->dataSource->valid();
219-
} else {
220-
$key = key($this->dataSource);
221-
return $key !== null;
222-
}
213+
return $this->dataSource->valid();
223214
}
224215

225216
/**
@@ -229,11 +220,7 @@ public function valid(): bool
229220
public function rewind(): void
230221
{
231222
if (! is_array($this->buffer)) {
232-
if ($this->dataSource instanceof Iterator) {
233-
$this->dataSource->rewind();
234-
} else {
235-
reset($this->dataSource);
236-
}
223+
$this->dataSource->rewind();
237224
}
238225

239226
$this->position = 0;

‎src/ResultSet/ResultSetReturnType.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ enum ResultSetReturnType: string
88
{
99
case ArrayObject = 'arrayobject';
1010
case Array = 'array';
11+
case Prototype = 'prototype';
1112
}

‎src/ResultSet/RowPrototypeInterface.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,9 @@ interface RowPrototypeInterface
1717
* Exchange the current data for the provided array.
1818
*/
1919
public function exchangeArray(array $array): array;
20+
21+
/**
22+
* Current data as an array and match current RowGateway implementations.
23+
*/
24+
public function toArray(): array;
2025
}

‎src/Sql/AbstractSql.php‎

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@
2121
use function count;
2222
use function current;
2323
use function get_object_vars;
24-
use function gettype;
2524
use function implode;
2625
use function is_array;
27-
use function is_callable;
28-
use function is_object;
2926
use function is_string;
3027
use function key;
3128
use function rtrim;
@@ -151,14 +148,6 @@ protected function processExpression(
151148
: $platform->quoteValue((string) $argument->getValue()),
152149
$argument instanceof Identifier => $platform->quoteIdentifierInFragment($argument->getValue()),
153150
$argument instanceof Literal => $argument->getValue(),
154-
$argument instanceof Values => $this->processValuesArgument(
155-
$argument,
156-
$expressionParamIndex,
157-
$namedParameterPrefix,
158-
$platform,
159-
$driver,
160-
$parameterContainer
161-
),
162151
$argument instanceof Identifiers => $this->processIdentifiersArgument($argument, $platform),
163152
$argument instanceof SelectArgument => $this->processExpressionOrSelect(
164153
$argument,
@@ -234,36 +223,6 @@ protected function processExpressionOrSelect(
234223
};
235224
}
236225

237-
protected function processValuesArgument(
238-
ArgumentInterface $argument,
239-
int &$expressionParamIndex,
240-
string $namedParameterPrefix,
241-
PlatformInterface $platform,
242-
?DriverInterface $driver = null,
243-
?ParameterContainer $parameterContainer = null
244-
): string {
245-
$values = $argument->getValue();
246-
$processedValues = [];
247-
248-
if ($parameterContainer instanceof ParameterContainer) {
249-
foreach ($values as $value) {
250-
$processedValues[] = $this->processExpressionParameterName(
251-
$value,
252-
$namedParameterPrefix,
253-
$expressionParamIndex,
254-
$driver,
255-
$parameterContainer
256-
);
257-
}
258-
} else {
259-
foreach ($values as $value) {
260-
$processedValues[] = $platform->quoteValue((string) $value);
261-
}
262-
}
263-
264-
return implode(', ', $processedValues);
265-
}
266-
267226
protected function processIdentifiersArgument(
268227
ArgumentInterface $argument,
269228
PlatformInterface $platform
@@ -419,13 +378,8 @@ protected function processJoin(
419378
: '') . $platform->quoteIdentifier($joinName[0]);
420379
} elseif ($joinName instanceof Select) {
421380
$joinName = '(' . $this->processSubSelect($joinName, $platform, $driver, $parameterContainer) . ')';
422-
} elseif (is_string($joinName) || (is_object($joinName) && is_callable([$joinName, '__toString']))) {
423-
$joinName = $platform->quoteIdentifier($joinName);
424381
} else {
425-
throw new Exception\InvalidArgumentException(sprintf(
426-
'Join name expected to be Expression|TableIdentifier|Select|string, "%s" given',
427-
gettype($joinName)
428-
));
382+
$joinName = $platform->quoteIdentifier($joinName);
429383
}
430384

431385
$joinSpecArgArray[$j] = [
@@ -511,9 +465,6 @@ protected function resolveTable(
511465
return $table;
512466
}
513467

514-
/**
515-
* Copy variables from the subject into the local properties
516-
*/
517468
protected function localizeVariables(): void
518469
{
519470
if (! $this instanceof PlatformDecoratorInterface) {

‎test/integration/Adapter/Driver/Pdo/AbstractAdapterTestCase.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
use function getmypid;
1010
use function shell_exec;
1111

12-
#[CoversMethod(AdapterInterface::class, '__construct()')]
12+
#[CoversMethod(AdapterInterface::class, 'getDriver')]
13+
#[CoversMethod(AdapterInterface::class, 'getPlatform')]
1314
abstract class AbstractAdapterTestCase extends TestCase
1415
{
1516
use AdapterTrait;

‎test/unit/Adapter/AdapterAwareTraitTest.php‎

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

77
use PhpDb\Adapter\Adapter;
88
use PhpDb\Adapter\AdapterAwareTrait;
9-
use PhpDb\Adapter\AdapterInterface;
109
use PhpDb\Adapter\Driver\DriverInterface;
1110
use PhpDb\Adapter\Platform\PlatformInterface;
11+
use PhpDbTest\Adapter\TestAsset\ConcreteAdapterAwareObject;
12+
use PHPUnit\Framework\Attributes\CoversMethod;
13+
use PHPUnit\Framework\Attributes\Group;
1214
use PHPUnit\Framework\TestCase;
1315
use ReflectionProperty;
1416

17+
#[CoversMethod(AdapterAwareTrait::class, 'setDbAdapter')]
18+
#[Group('unit')]
1519
class AdapterAwareTraitTest extends TestCase
1620
{
1721
public function testSetDbAdapter(): void
1822
{
19-
$object = new class {
20-
use AdapterAwareTrait;
21-
22-
public function getAdapter(): ?AdapterInterface
23-
{
24-
return $this->adapter ?? null;
25-
}
26-
};
23+
$object = new ConcreteAdapterAwareObject();
2724

2825
self::assertNull($object->getAdapter());
2926

@@ -39,9 +36,7 @@ public function getAdapter(): ?AdapterInterface
3936

4037
public function testSetDbAdapterSetsProperty(): void
4138
{
42-
$object = new class {
43-
use AdapterAwareTrait;
44-
};
39+
$object = new ConcreteAdapterAwareObject();
4540

4641
$driver = $this->createMock(DriverInterface::class);
4742
$platform = $this->createMock(PlatformInterface::class);

0 commit comments

Comments
 (0)