Skip to content

Commit

Permalink
Fix compatibility with DBAL develop
Browse files Browse the repository at this point in the history
* ResultStatement signature BC break
* PDO::FETCH_* -> FetchMode::*
* PDO::PARAM_* -> ParameterType::*
* AbstractPlatform::DATE_INTERVAL_UNIT_* -> DateIntervalUnit::*
* AbstractPlatform::TRIM_* -> TrimMode::*
  • Loading branch information
Majkl578 committed Feb 14, 2018
1 parent 09266d5 commit c78c393
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 33 deletions.
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
namespace Doctrine\ORM\Internal\Hydration;

use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Events;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\ORM\UnitOfWork;
use PDO;
use function array_merge;

/**
Expand Down Expand Up @@ -146,7 +146,7 @@ public function hydrateAll($stmt, $resultSetMapping, array $hints = [])
*/
public function hydrateRow()
{
$row = $this->stmt->fetch(PDO::FETCH_ASSOC);
$row = $this->stmt->fetch(FetchMode::ASSOCIATIVE);

if (! $row) {
$this->cleanup();
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Doctrine\ORM\Internal\Hydration;

use Doctrine\DBAL\FetchMode;
use Doctrine\ORM\Mapping\ToOneAssociationMetadata;
use PDO;
use function count;
use function end;
use function is_array;
Expand Down Expand Up @@ -72,7 +72,7 @@ protected function hydrateAllData()
{
$result = [];

while ($data = $this->stmt->fetch(PDO::FETCH_ASSOC)) {
while ($data = $this->stmt->fetch(FetchMode::ASSOCIATIVE)) {
$this->hydrateRowData($data, $result);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
namespace Doctrine\ORM\Internal\Hydration;

use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\FetchMode;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ManyToManyAssociationMetadata;
use Doctrine\ORM\Mapping\ToManyAssociationMetadata;
use Doctrine\ORM\Mapping\ToOneAssociationMetadata;
use Doctrine\ORM\PersistentCollection;
use Doctrine\ORM\Query;
use Doctrine\ORM\UnitOfWork;
use PDO;
use ProxyManager\Proxy\GhostObjectInterface;
use function array_fill_keys;
use function array_keys;
Expand Down Expand Up @@ -146,7 +146,7 @@ protected function hydrateAllData()
{
$result = [];

while ($row = $this->stmt->fetch(PDO::FETCH_ASSOC)) {
while ($row = $this->stmt->fetch(FetchMode::ASSOCIATIVE)) {
$this->hydrateRowData($row, $result);
}

Expand Down
4 changes: 3 additions & 1 deletion lib/Doctrine/ORM/Internal/Hydration/ScalarHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Doctrine\ORM\Internal\Hydration;

use Doctrine\DBAL\FetchMode;

/**
* Hydrator that produces flat, rectangular results of scalar data.
* The created result is almost the same as a regular SQL result set, except
Expand All @@ -18,7 +20,7 @@ protected function hydrateAllData()
{
$result = [];

while ($data = $this->stmt->fetch(\PDO::FETCH_ASSOC)) {
while ($data = $this->stmt->fetch(FetchMode::ASSOCIATIVE)) {
$this->hydrateRowData($data, $result);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Doctrine\ORM\Internal\Hydration;

use Doctrine\DBAL\FetchMode;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\InheritanceType;
use Doctrine\ORM\Query;
use PDO;
use function array_keys;
use function array_search;
use function count;
Expand Down Expand Up @@ -56,7 +56,7 @@ protected function hydrateAllData()
{
$result = [];

while ($row = $this->stmt->fetch(PDO::FETCH_ASSOC)) {
while ($row = $this->stmt->fetch(FetchMode::ASSOCIATIVE)) {
$this->hydrateRowData($row, $result);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/Doctrine/ORM/Internal/Hydration/SingleScalarHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Doctrine\ORM\Internal\Hydration;

use Doctrine\DBAL\FetchMode;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\NoResultException;
use function array_shift;
Expand All @@ -20,7 +21,7 @@ class SingleScalarHydrator extends AbstractHydrator
*/
protected function hydrateAllData()
{
$data = $this->stmt->fetchAll(\PDO::FETCH_ASSOC);
$data = $this->stmt->fetchAll(FetchMode::ASSOCIATIVE);
$numRows = count($data);

if ($numRows === 0) {
Expand Down
10 changes: 5 additions & 5 deletions lib/Doctrine/ORM/Query/AST/Functions/TrimFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Doctrine\ORM\Query\AST\Functions;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\TrimMode;
use Doctrine\ORM\Query\AST\Node;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
Expand Down Expand Up @@ -89,18 +89,18 @@ public function parse(Parser $parser)
private function getTrimMode()
{
if ($this->leading) {
return AbstractPlatform::TRIM_LEADING;
return TrimMode::LEADING;
}

if ($this->trailing) {
return AbstractPlatform::TRIM_TRAILING;
return TrimMode::TRAILING;
}

if ($this->both) {
return AbstractPlatform::TRIM_BOTH;
return TrimMode::BOTH;
}

return AbstractPlatform::TRIM_UNSPECIFIED;
return TrimMode::UNSPECIFIED;
}

private function parseTrimMode(Parser $parser)
Expand Down
3 changes: 2 additions & 1 deletion lib/Doctrine/ORM/Query/ParameterTypeInferer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\ORM\Query;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Types\Type;
use function current;
use function is_array;
Expand Down Expand Up @@ -49,6 +50,6 @@ public static function inferType($value)
: Connection::PARAM_STR_ARRAY;
}

return \PDO::PARAM_STR;
return ParameterType::STRING;
}
}
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ public function getRootEntities()
*
* @param string|int $key The parameter position or name.
* @param mixed $value The parameter value.
* @param string|int|null $type PDO::PARAM_* or \Doctrine\DBAL\Types\Type::* constant
* @param string|int|null $type ParameterType::* or \Doctrine\DBAL\Types\Type::* constant
*
* @return self
*/
Expand Down
3 changes: 2 additions & 1 deletion tests/Doctrine/Tests/Mocks/DriverConnectionMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\Tests\Mocks;

use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\ParameterType;

/**
* Mock class for DriverConnection.
Expand Down Expand Up @@ -51,7 +52,7 @@ public function query()
/**
* {@inheritdoc}
*/
public function quote($input, $type=\PDO::PARAM_STR)
public function quote($input, $type = ParameterType::STRING)
{
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Doctrine/Tests/Mocks/HydratorMockStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(array $resultSet)
* @param array|null $ctorArgs
* @return array
*/
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
public function fetchAll($fetchMode = null, ...$args)
{
return $this->resultSet;
}
Expand All @@ -58,7 +58,7 @@ public function fetchColumn($columnNumber = 0)
/**
* {@inheritdoc}
*/
public function fetch($fetchStyle = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
public function fetch($fetchStyle = null, ...$args)
{
$current = current($this->resultSet);
next($this->resultSet);
Expand Down Expand Up @@ -133,7 +133,7 @@ public function getIterator()
/**
* {@inheritdoc}
*/
public function setFetchMode($fetchStyle, $arg2 = null, $arg3 = null)
public function setFetchMode($fetchStyle, ...$args)
{
}
}
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/Mocks/StatementArrayMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public function columnCount()
return 0;
}

public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
public function fetchAll($fetchMode = null, ...$args)
{
return $this->result;
}

public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
public function fetch($fetchMode = null, ...$args)
{
$current = current($this->result);
next($this->result);
Expand Down
6 changes: 3 additions & 3 deletions tests/Doctrine/Tests/Mocks/StatementMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,21 @@ public function columnCount()
/**
* {@inheritdoc}
*/
public function setFetchMode($fetchStyle, $arg2 = null, $arg3 = null)
public function setFetchMode($fetchStyle, ...$args)
{
}

/**
* {@inheritdoc}
*/
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
public function fetch($fetchMode = null, ...$args)
{
}

/**
* {@inheritdoc}
*/
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
public function fetchAll($fetchMode = null, ...$args)
{
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/ORM/Hydration/CustomHydratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Doctrine\Tests\ORM\Hydration;

use Doctrine\DBAL\FetchMode;
use Doctrine\ORM\Internal\Hydration\AbstractHydrator;
use PDO;

class CustomHydratorTest extends HydrationTestCase
{
Expand All @@ -25,6 +25,6 @@ class CustomHydrator extends AbstractHydrator
{
protected function hydrateAllData()
{
return $this->stmt->fetchAll(PDO::FETCH_ASSOC);
return $this->stmt->fetchAll(FetchMode::ASSOCIATIVE);
}
}
6 changes: 3 additions & 3 deletions tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@

namespace Doctrine\Tests\ORM\Query;

use Doctrine\DBAL\ParameterType;
use Doctrine\ORM\Query\ParameterTypeInferer;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\OrmTestCase;
use PDO;

class ParameterTypeInfererTest extends OrmTestCase
{
public function providerParameterTypeInferer()
{
$data = [
[1, Type::INTEGER],
["bar", PDO::PARAM_STR],
["1", PDO::PARAM_STR],
["bar", ParameterType::STRING],
["1", ParameterType::STRING],
[new \DateTime, Type::DATETIME],
[new \DateInterval('P1D'), Type::DATEINTERVAL],
[[2], Connection::PARAM_INT_ARRAY],
Expand Down
5 changes: 3 additions & 2 deletions tests/Doctrine/Tests/ORM/Query/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\DBAL\ParameterType;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Internal\Hydration\IterableResult;
use Doctrine\ORM\Query\Parameter;
Expand Down Expand Up @@ -62,7 +63,7 @@ public function testSetParameters()
public function testFree()
{
$query = $this->em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1");
$query->setParameter(2, 84, \PDO::PARAM_INT);
$query->setParameter(2, 84, ParameterType::INTEGER);

$query->free();

Expand All @@ -74,7 +75,7 @@ public function testClone()
$dql = "select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1";

$query = $this->em->createQuery($dql);
$query->setParameter(2, 84, \PDO::PARAM_INT);
$query->setParameter(2, 84, ParameterType::INTEGER);
$query->setHint('foo', 'bar');

$cloned = clone $query;
Expand Down

0 comments on commit c78c393

Please sign in to comment.