Skip to content
This repository has been archived by the owner on Dec 28, 2020. It is now read-only.

Commit

Permalink
Merge pull request #166 from Lctrs/feature/arguments
Browse files Browse the repository at this point in the history
uniformize arguments types
  • Loading branch information
lctrs-bot committed Jul 23, 2020
2 parents 7d4f44e + 3342e41 commit f27cae2
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 36 deletions.
11 changes: 6 additions & 5 deletions src/Filter/IsNotNull.php
Expand Up @@ -6,19 +6,20 @@

use Doctrine\DBAL\Query\QueryBuilder;
use Lctrs\DBALSpecification\Filter;
use Lctrs\DBALSpecification\Operand\Operand;

final class IsNotNull implements Filter
{
/** @var string */
private $field;
/** @var Operand */
private $x;

public function __construct(string $field)
public function __construct(Operand $x)
{
$this->field = $field;
$this->x = $x;
}

public function getFilter(QueryBuilder $queryBuilder): ?string
{
return $queryBuilder->expr()->isNotNull($this->field);
return $queryBuilder->expr()->isNotNull($this->x->transform($queryBuilder));
}
}
11 changes: 6 additions & 5 deletions src/Filter/IsNull.php
Expand Up @@ -6,19 +6,20 @@

use Doctrine\DBAL\Query\QueryBuilder;
use Lctrs\DBALSpecification\Filter;
use Lctrs\DBALSpecification\Operand\Operand;

final class IsNull implements Filter
{
/** @var string */
private $field;
/** @var Operand */
private $x;

public function __construct(string $field)
public function __construct(Operand $x)
{
$this->field = $field;
$this->x = $x;
}

public function getFilter(QueryBuilder $queryBuilder): ?string
{
return $queryBuilder->expr()->isNull($this->field);
return $queryBuilder->expr()->isNull($this->x->transform($queryBuilder));
}
}
11 changes: 6 additions & 5 deletions src/Filter/Like.php
Expand Up @@ -7,24 +7,25 @@
use Doctrine\DBAL\Query\QueryBuilder;
use Lctrs\DBALSpecification\Filter;
use Lctrs\DBALSpecification\Operand\LikePattern;
use Lctrs\DBALSpecification\Operand\Operand;

final class Like implements Filter
{
/** @var string */
private $field;
/** @var Operand */
private $x;
/** @var LikePattern */
private $value;

public function __construct(string $field, LikePattern $value)
public function __construct(Operand $x, LikePattern $value)
{
$this->field = $field;
$this->x = $x;
$this->value = $value;
}

public function getFilter(QueryBuilder $queryBuilder): ?string
{
return $queryBuilder->expr()->like(
$this->field,
$this->x->transform($queryBuilder),
$this->value->transform($queryBuilder)
);
}
Expand Down
11 changes: 6 additions & 5 deletions src/Filter/NotLike.php
Expand Up @@ -7,24 +7,25 @@
use Doctrine\DBAL\Query\QueryBuilder;
use Lctrs\DBALSpecification\Filter;
use Lctrs\DBALSpecification\Operand\LikePattern;
use Lctrs\DBALSpecification\Operand\Operand;

final class NotLike implements Filter
{
/** @var string */
private $field;
/** @var Operand */
private $x;
/** @var LikePattern */
private $value;

public function __construct(string $field, LikePattern $value)
public function __construct(Operand $x, LikePattern $value)
{
$this->field = $field;
$this->x = $x;
$this->value = $value;
}

public function getFilter(QueryBuilder $queryBuilder): ?string
{
return $queryBuilder->expr()->notLike(
$this->field,
$this->x->transform($queryBuilder),
$this->value->transform($queryBuilder)
);
}
Expand Down
1 change: 1 addition & 0 deletions src/Operand/LikePattern.php
Expand Up @@ -13,6 +13,7 @@ final class LikePattern
public const CONTAINS = '%%%s%%';
public const ENDS_WITH = '%%%s';
public const STARTS_WITH = '%s%%';

/** @var string */
private $value;
/** @var string */
Expand Down
5 changes: 3 additions & 2 deletions test/Unit/Filter/IsNotNullTest.php
Expand Up @@ -8,6 +8,7 @@
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use Doctrine\DBAL\Query\QueryBuilder;
use Lctrs\DBALSpecification\Filter\IsNotNull;
use Lctrs\DBALSpecification\Operand\Field;
use PHPUnit\Framework\TestCase;

final class IsNotNullTest extends TestCase
Expand All @@ -32,15 +33,15 @@ public function testItCallsNotNull(): void
{
self::assertSame(
'foo IS NOT NULL',
(new IsNotNull('foo'))->getFilter($this->queryBuilder)
(new IsNotNull(new Field('foo')))->getFilter($this->queryBuilder)
);
}

public function testItUsesAlias(): void
{
self::assertSame(
'x.foo IS NOT NULL',
(new IsNotNull('x.foo'))->getFilter($this->queryBuilder)
(new IsNotNull(new Field('x.foo')))->getFilter($this->queryBuilder)
);
}
}
5 changes: 3 additions & 2 deletions test/Unit/Filter/IsNullTest.php
Expand Up @@ -8,6 +8,7 @@
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use Doctrine\DBAL\Query\QueryBuilder;
use Lctrs\DBALSpecification\Filter\IsNull;
use Lctrs\DBALSpecification\Operand\Field;
use PHPUnit\Framework\TestCase;

final class IsNullTest extends TestCase
Expand All @@ -32,15 +33,15 @@ public function testItCallsNotNull(): void
{
self::assertSame(
'foo IS NULL',
(new IsNull('foo'))->getFilter($this->queryBuilder)
(new IsNull(new Field('foo')))->getFilter($this->queryBuilder)
);
}

public function testItUsesAlias(): void
{
self::assertSame(
'x.foo IS NULL',
(new IsNull('x.foo'))->getFilter($this->queryBuilder)
(new IsNull(new Field('x.foo')))->getFilter($this->queryBuilder)
);
}
}
5 changes: 3 additions & 2 deletions test/Unit/Filter/LikeTest.php
Expand Up @@ -8,6 +8,7 @@
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use Doctrine\DBAL\Query\QueryBuilder;
use Lctrs\DBALSpecification\Filter\Like;
use Lctrs\DBALSpecification\Operand\Field;
use Lctrs\DBALSpecification\Operand\LikePattern;
use PHPUnit\Framework\TestCase;

Expand All @@ -33,7 +34,7 @@ public function testItCallsLike(): void
{
self::assertSame(
'foo LIKE :dcValue1',
(new Like('foo', new LikePattern('bar')))->getFilter($this->queryBuilder)
(new Like(new Field('foo'), new LikePattern('bar')))->getFilter($this->queryBuilder)
);
self::assertSame(
'%bar%',
Expand All @@ -45,7 +46,7 @@ public function testItUsesAlias(): void
{
self::assertSame(
'x.foo LIKE :dcValue1',
(new Like('x.foo', new LikePattern('bar')))->getFilter($this->queryBuilder)
(new Like(new Field('x.foo'), new LikePattern('bar')))->getFilter($this->queryBuilder)
);
self::assertSame(
'%bar%',
Expand Down
5 changes: 3 additions & 2 deletions test/Unit/Filter/NotLikeTest.php
Expand Up @@ -8,6 +8,7 @@
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use Doctrine\DBAL\Query\QueryBuilder;
use Lctrs\DBALSpecification\Filter\NotLike;
use Lctrs\DBALSpecification\Operand\Field;
use Lctrs\DBALSpecification\Operand\LikePattern;
use PHPUnit\Framework\TestCase;

Expand All @@ -33,7 +34,7 @@ public function testItCallsLike(): void
{
self::assertSame(
'foo NOT LIKE :dcValue1',
(new NotLike('foo', new LikePattern('bar')))->getFilter($this->queryBuilder)
(new NotLike(new Field('foo'), new LikePattern('bar')))->getFilter($this->queryBuilder)
);
self::assertSame(
'%bar%',
Expand All @@ -45,7 +46,7 @@ public function testItUsesAlias(): void
{
self::assertSame(
'x.foo NOT LIKE :dcValue1',
(new NotLike('x.foo', new LikePattern('bar')))->getFilter($this->queryBuilder)
(new NotLike(new Field('x.foo'), new LikePattern('bar')))->getFilter($this->queryBuilder)
);
self::assertSame(
'%bar%',
Expand Down
5 changes: 3 additions & 2 deletions test/Unit/Logic/AndXTest.php
Expand Up @@ -7,6 +7,7 @@
use Lctrs\DBALSpecification\Filter;
use Lctrs\DBALSpecification\Logic\AndX;
use Lctrs\DBALSpecification\Logic\LogicX;
use Lctrs\DBALSpecification\Operand\Field;
use Lctrs\DBALSpecification\Query\From;
use Lctrs\DBALSpecification\Test\Unit\Filter\Fixture\NullFilter;

Expand All @@ -16,9 +17,9 @@ protected function getLogicX(): LogicX
{
return new AndX([
new NullFilter(),
new Filter\IsNull('foo'),
new Filter\IsNull(new Field('foo')),
new From('aTable'),
new Filter\IsNull('bar'),
new Filter\IsNull(new Field('bar')),
]);
}

Expand Down
5 changes: 3 additions & 2 deletions test/Unit/Logic/OrXTest.php
Expand Up @@ -7,6 +7,7 @@
use Lctrs\DBALSpecification\Filter;
use Lctrs\DBALSpecification\Logic\LogicX;
use Lctrs\DBALSpecification\Logic\OrX;
use Lctrs\DBALSpecification\Operand\Field;
use Lctrs\DBALSpecification\Query\GroupBy;
use Lctrs\DBALSpecification\Query\OrderBy;
use Lctrs\DBALSpecification\Test\Unit\Filter\Fixture\NullFilter;
Expand All @@ -18,8 +19,8 @@ protected function getLogicX(): LogicX
return new OrX([
new NullFilter(),
new OrderBy('baz'),
new Filter\IsNull('foo'),
new Filter\IsNull('bar'),
new Filter\IsNull(new Field('foo')),
new Filter\IsNull(new Field('bar')),
new GroupBy('foo'),
]);
}
Expand Down
3 changes: 2 additions & 1 deletion test/Unit/Query/HavingTest.php
Expand Up @@ -9,6 +9,7 @@
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use Doctrine\DBAL\Query\QueryBuilder;
use Lctrs\DBALSpecification\Filter;
use Lctrs\DBALSpecification\Operand\Field;
use Lctrs\DBALSpecification\Query\Having;
use PHPUnit\Framework\TestCase;

Expand All @@ -32,7 +33,7 @@ protected function setUp(): void

public function testItAddsHaving(): void
{
(new Having(new Filter\IsNull('foo')))->modify($this->queryBuilder);
(new Having(new Filter\IsNull(new Field('foo'))))->modify($this->queryBuilder);

self::assertEquals(
new CompositeExpression('AND', ['foo IS NULL']),
Expand Down
3 changes: 2 additions & 1 deletion test/Unit/Query/InnerJoinTest.php
Expand Up @@ -5,6 +5,7 @@
namespace Lctrs\DBALSpecification\Test\Unit\Query;

use Lctrs\DBALSpecification\Filter;
use Lctrs\DBALSpecification\Operand\Field;
use Lctrs\DBALSpecification\Query\InnerJoin;
use Lctrs\DBALSpecification\Query\Join;

Expand All @@ -16,7 +17,7 @@ protected function getJoin(): Join
'x',
'foo',
'f',
new Filter\IsNull('x.bar')
new Filter\IsNull(new Field('x.bar'))
);
}

Expand Down
3 changes: 2 additions & 1 deletion test/Unit/Query/LeftJoinTest.php
Expand Up @@ -5,6 +5,7 @@
namespace Lctrs\DBALSpecification\Test\Unit\Query;

use Lctrs\DBALSpecification\Filter;
use Lctrs\DBALSpecification\Operand\Field;
use Lctrs\DBALSpecification\Query\Join;
use Lctrs\DBALSpecification\Query\LeftJoin;

Expand All @@ -16,7 +17,7 @@ protected function getJoin(): Join
'x',
'foo',
'f',
new Filter\IsNull('x.bar')
new Filter\IsNull(new Field('x.bar'))
);
}

Expand Down
3 changes: 2 additions & 1 deletion test/Unit/Query/RightJoinTest.php
Expand Up @@ -5,6 +5,7 @@
namespace Lctrs\DBALSpecification\Test\Unit\Query;

use Lctrs\DBALSpecification\Filter;
use Lctrs\DBALSpecification\Operand\Field;
use Lctrs\DBALSpecification\Query\Join;
use Lctrs\DBALSpecification\Query\RightJoin;

Expand All @@ -16,7 +17,7 @@ protected function getJoin(): Join
'x',
'foo',
'f',
new Filter\IsNull('x.bar')
new Filter\IsNull(new Field('x.bar'))
);
}

Expand Down

0 comments on commit f27cae2

Please sign in to comment.