Skip to content

Commit

Permalink
Merge branch '3.0.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Jan 29, 2020
2 parents 77087e7 + 54fb5e0 commit 43819af
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ before_commands:
tools:
external_code_coverage:
timeout: 3600
runs: 29 # 24x Travis (jobs with COVERAGE=yes) + 3x AppVeyor (jobs with coverage=yes) + 2x ContinuousPHP
runs: 26 # 21x Travis (jobs with COVERAGE=yes) + 3x AppVeyor (jobs with coverage=yes) + 2x ContinuousPHP

filter:
excluded_paths:
Expand Down
64 changes: 63 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ before_script:
- if [[ "$DB" == "mysql" || "$DB" == "mysqli" || "$DB" == *"mariadb"* ]]; then mysql < tests/travis/create-mysql-schema.sql; fi;

install:
- travis_retry composer -n install --prefer-dist
- |
if [[ $TRAVIS_PHP_VERSION = "nightly" ]]; then
export COMPOSER_FLAGS="--ignore-platform-reqs"
fi
- travis_retry composer -n install --prefer-dist $COMPOSER_FLAGS

script:
- |
Expand Down Expand Up @@ -302,6 +306,63 @@ jobs:
before_script:
- bash ./tests/travis/install-db2.sh
- bash ./tests/travis/install-db2-ibm_db2.sh
- stage: Test
php: nightly
env: DB=mysql.docker MYSQL_VERSION=8.0
sudo: required
services:
- docker
before_script:
- bash ./tests/travis/install-mysql-8.0.sh
- stage: Test
php: nightly
env: DB=mysqli.docker MYSQL_VERSION=8.0
sudo: required
services:
- docker
before_script:
- bash ./tests/travis/install-mysql-8.0.sh
- stage: Test
php: nightly
env: DB=mariadb MARIADB_VERSION=10.3
addons:
mariadb: 10.3
- stage: Test
php: nightly
env: DB=mariadb.mysqli MARIADB_VERSION=10.3
addons:
mariadb: 10.3
- stage: Test
php: nightly
env: DB=pgsql POSTGRESQL_VERSION=11.0
sudo: required
services:
- docker
before_script:
- bash ./tests/travis/install-postgres-11.sh
- stage: Test
php: nightly
env: DB=sqlite
- stage: Test
php: nightly
env: DB=sqlsrv
sudo: required
services:
- docker
before_script:
- bash ./tests/travis/install-sqlsrv-dependencies.sh
- bash ./tests/travis/install-mssql-sqlsrv.sh
- bash ./tests/travis/install-mssql.sh
- stage: Test
php: nightly
env: DB=pdo_sqlsrv
sudo: required
services:
- docker
before_script:
- bash ./tests/travis/install-sqlsrv-dependencies.sh
- bash ./tests/travis/install-mssql-pdo_sqlsrv.sh
- bash ./tests/travis/install-mssql.sh

- stage: Test
if: type = cron
Expand All @@ -313,3 +374,4 @@ jobs:

allow_failures:
- env: DEPENDENCIES=dev
- php: nightly
15 changes: 15 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,21 @@ The Drizzle project is abandoned and is therefore not supported by Doctrine DBAL
Use binary fields of a size which fits all target platforms, or use blob explicitly instead.
- Binary fields are no longer represented as streams in PHP. They are represented as strings.

# Upgrade to 2.11

## Deprecated `ExpressionBuilder` methods

The usage of the `andX()` and `orX()` methods of the `ExpressionBuilder` class has been deprecated. Use `and()` and `or()` instead.

## Deprecated `CompositeExpression` methods

The usage of the `add()` and `addMultiple()` methods of the `CompositeExpression` class has been deprecated. Use `with()` instead, which returns a new instance.
In the future, the `add*()` methods will be removed and the class will be effectively immutable.

## Deprecated calling `QueryBuilder` methods with an array argument

Calling the `select()`, `addSelect()`, `groupBy()` and `addGroupBy()` methods with an array argument is deprecated.

# Upgrade to 2.10

## Deprecated `Doctrine\DBAL\Event\ConnectionEventArgs` methods
Expand Down
4 changes: 2 additions & 2 deletions docs/en/reference/query-builder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,13 @@ Most notably you can use expressions to build nested And-/Or statements:
->select('id', 'name')
->from('users')
->where(
$queryBuilder->expr()->andX(
$queryBuilder->expr()->and(
$queryBuilder->expr()->eq('username', '?'),
$queryBuilder->expr()->eq('email', '?')
)
);
The ``andX()`` and ``orX()`` methods accept an arbitrary amount
The ``and()`` and ``or()`` methods accept an arbitrary amount
of arguments and can be nested in each other.

There is a bunch of methods to create comparisons and other SQL snippets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use function array_key_exists;
use function assert;
use function count;
use function func_get_args;
use function is_array;
use function is_int;
use function is_object;
Expand Down Expand Up @@ -228,7 +227,7 @@ public function fetchAll(?int $fetchMode = null, ...$args) : array

switch ($fetchMode) {
case FetchMode::CUSTOM_OBJECT:
while (($row = $this->fetch(...func_get_args())) !== false) {
while (($row = $this->fetch($fetchMode, ...$args)) !== false) {
$rows[] = $row;
}

Expand Down
23 changes: 23 additions & 0 deletions lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public function __construct(string $type, array $parts = [])
/**
* Adds multiple parts to composite expression.
*
* @deprecated This class will be made immutable. Use with() instead.
*
* @param array<int, self|string> $parts
*
* @return $this
Expand All @@ -67,6 +69,8 @@ public function addMultiple(array $parts = []) : self
/**
* Adds an expression to composite expression.
*
* @deprecated This class will be made immutable. Use with() instead.
*
* @param self|string $part
*
* @return $this
Expand All @@ -86,6 +90,25 @@ public function add($part) : self
return $this;
}

/**
* Returns a new CompositeExpression with the given parts added.
*
* @param self|string $part
* @param self|string ...$parts
*/
public function with($part, ...$parts) : self
{
$that = clone $this;

$that->parts[] = $part;

foreach ($parts as $part) {
$that->parts[] = $part;
}

return $that;
}

/**
* Retrieves the amount of expressions on composite expression.
*/
Expand Down
33 changes: 22 additions & 11 deletions lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\DBAL\Query\Expression;

use Doctrine\DBAL\Connection;
use function array_merge;
use function implode;
use function sprintf;

Expand Down Expand Up @@ -40,11 +41,27 @@ public function __construct(Connection $connection)
/**
* Creates a conjunction of the given expressions.
*
* Example:
* @param string|CompositeExpression $expression
* @param string|CompositeExpression ...$expressions
*/
public function and($expression, ...$expressions) : CompositeExpression
{
return new CompositeExpression(CompositeExpression::TYPE_AND, array_merge([$expression], $expressions));
}

/**
* Creates a disjunction of the given expressions.
*
* [php]
* // (u.type = ?) AND (u.role = ?)
* $expr->andX('u.type = ?', 'u.role = ?'));
* @param string|CompositeExpression $expression
* @param string|CompositeExpression ...$expressions
*/
public function or($expression, ...$expressions) : CompositeExpression
{
return new CompositeExpression(CompositeExpression::TYPE_OR, array_merge([$expression], $expressions));
}

/**
* @deprecated Use `and()` instead.
*
* @param string|CompositeExpression ...$expressions Requires at least one defined when converting to string.
*/
Expand All @@ -54,13 +71,7 @@ public function andX(...$expressions) : CompositeExpression
}

/**
* Creates a disjunction of the given expressions.
*
* Example:
*
* [php]
* // (u.type = ?) OR (u.role = ?)
* $qb->where($qb->expr()->orX('u.type = ?', 'u.role = ?'));
* @deprecated Use `or()` instead.
*
* @param string|CompositeExpression ...$expressions Requires at least one defined when converting to string.
*/
Expand Down
54 changes: 0 additions & 54 deletions tests/Doctrine/Tests/DBAL/Functional/PDOStatementTest.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testCount() : void

self::assertCount(1, $expr);

$expr->add('u.group_id = 2');
$expr = $expr->with('u.group_id = 2');

self::assertCount(2, $expr);
}
Expand All @@ -42,6 +42,26 @@ public function testAdd() : void
self::assertCount(3, $expr);
}

public function testWith() : void
{
$expr = new CompositeExpression(CompositeExpression::TYPE_OR, ['u.group_id = 1']);

self::assertCount(1, $expr);

// test immutability
$expr->with(new CompositeExpression(CompositeExpression::TYPE_OR, ['u.user_id = 1']));

self::assertCount(1, $expr);

$expr = $expr->with(new CompositeExpression(CompositeExpression::TYPE_OR, ['u.user_id = 1']));

self::assertCount(2, $expr);

$expr = $expr->with('u.user_id = 1');

self::assertCount(3, $expr);
}

/**
* @param string[]|CompositeExpression[] $parts
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,19 @@ protected function setUp() : void
/**
* @param string[]|CompositeExpression[] $parts
*
* @dataProvider provideDataForAndX
* @dataProvider provideDataForAnd
*/
public function testAnd(array $parts, string $expected) : void
{
$composite = $this->expr->and(...$parts);

self::assertEquals($expected, (string) $composite);
}

/**
* @param string[]|CompositeExpression[] $parts
*
* @dataProvider provideDataForAnd
*/
public function testAndX(array $parts, string $expected) : void
{
Expand All @@ -47,7 +59,7 @@ public function testAndX(array $parts, string $expected) : void
/**
* @return mixed[][]
*/
public static function provideDataForAndX() : iterable
public static function provideDataForAnd() : iterable
{
return [
[
Expand Down Expand Up @@ -92,7 +104,19 @@ public static function provideDataForAndX() : iterable
/**
* @param string[]|CompositeExpression[] $parts
*
* @dataProvider provideDataForOrX
* @dataProvider provideDataForOr
*/
public function testOr(array $parts, string $expected) : void
{
$composite = $this->expr->or(...$parts);

self::assertEquals($expected, (string) $composite);
}

/**
* @param string[]|CompositeExpression[] $parts
*
* @dataProvider provideDataForOr
*/
public function testOrX(array $parts, string $expected) : void
{
Expand All @@ -108,7 +132,7 @@ public function testOrX(array $parts, string $expected) : void
/**
* @return mixed[][]
*/
public static function provideDataForOrX() : iterable
public static function provideDataForOr() : iterable
{
return [
[
Expand Down
Loading

0 comments on commit 43819af

Please sign in to comment.