Skip to content

Commit

Permalink
fix: doctrine query parameter should not apply type when it wasn't sp…
Browse files Browse the repository at this point in the history
…ecified explicitly
  • Loading branch information
Kreyu committed Mar 21, 2024
1 parent adaf7de commit 0d53e81
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/Bridge/Doctrine/Orm/Filter/DoctrineOrmFilterHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ public function handle(ProxyQueryInterface $query, FilterData $data, FilterInter
$queryBuilder = $query->getQueryBuilder();

foreach ($event->getParameters() as $parameter) {
$queryBuilder->setParameter($parameter->getName(), $parameter->getValue(), $parameter->getType());
$queryBuilder->setParameter(
$parameter->getName(),
$parameter->getValue(),
$parameter->typeWasSpecified() ? $parameter->getType() : null,
);
}

$expression = $this->expressionFactory->create($query, $data, $filter, $event->getParameters());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,38 @@ public function testItAppliesExpression(): void
$this->createHandler(expression: 'expression')->handle($this->query, $this->data, $this->filter);
}

public function testItSetsParameter(): void
public function testItSetsParameterWithoutTypeSpecified(): void
{
($queryBuilder = $this->createQueryBuilderMock())
->expects($this->once())
->method('setParameter')
->willReturnCallback(function ($name, $value) {
->willReturnCallback(function ($name, $value, $type) {
$this->assertEquals('foo', $name);
$this->assertEquals('bar', $value);
$this->assertNull($type);
});

$this->query->method('getQueryBuilder')->willReturn($queryBuilder);

$this->createHandler(parameters: [new Parameter('foo', 'bar')])->handle($this->query, $this->data, $this->filter);
}

public function testItSetsParameterWithTypeSpecified()
{
($queryBuilder = $this->createQueryBuilderMock())
->expects($this->once())
->method('setParameter')
->willReturnCallback(function ($name, $value, $type) {
$this->assertEquals('foo', $name);
$this->assertEquals('bar', $value);
$this->assertEquals('date_immutable', $type);
});

$this->query->method('getQueryBuilder')->willReturn($queryBuilder);

$this->createHandler(parameters: [new Parameter('foo', 'bar', 'date_immutable')])->handle($this->query, $this->data, $this->filter);
}

public function testItDispatchesEvents(): void
{
$this->eventDispatcher
Expand Down

0 comments on commit 0d53e81

Please sign in to comment.