Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force typing for Postgresql::date_trunc so it can be used in a condition #415

Merged
merged 3 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Query/Postgresql/DateTrunc.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function parse(Parser $parser): void
public function getSql(SqlWalker $sqlWalker): string
{
return sprintf(
'DATE_TRUNC(%s, %s)',
'DATE_TRUNC(%s::text, %s::timestamp)',
$this->fieldText->dispatch($sqlWalker),
$this->fieldTimestamp->dispatch($sqlWalker)
);
Expand Down
16 changes: 15 additions & 1 deletion tests/Query/Postgresql/DateTruncTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace DoctrineExtensions\Tests\Query\Postgresql;

use Doctrine\ORM\QueryBuilder;
use DoctrineExtensions\Tests\Entities\Date;
use DoctrineExtensions\Tests\Query\PostgresqlTestCase;

class DateTruncTest extends PostgresqlTestCase
Expand All @@ -14,8 +15,21 @@
->select("date_trunc('YEAR', dt.created)")
->from('DoctrineExtensions\Tests\Entities\Date', 'dt');

$expected = "SELECT DATE_TRUNC('YEAR', d0_.created) AS sclr_0 FROM Date d0_";
$expected = "SELECT DATE_TRUNC('YEAR'::text, d0_.created::timestamp) AS sclr_0 FROM Date d0_";

$this->assertEquals($expected, $queryBuilder->getQuery()->getSQL());
}

public function testDateTruncCondition()

Check failure on line 23 in tests/Query/Postgresql/DateTruncTest.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (8.3)

Method \DoctrineExtensions\Tests\Query\Postgresql\DateTruncTest::testDateTruncCondition() does not have void return type hint.
{
$queryBuilder = $this->entityManager->getRepository(Date::class)
->createQueryBuilder('dt')
->where("date_trunc('YEAR', dt.created) = date_trunc('YEAR', :date)")
->setParameter('date', new \DateTime('2010-01-01'));

Check failure on line 28 in tests/Query/Postgresql/DateTruncTest.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (8.3)

Class \DateTime should not be referenced via a fully qualified name, but via a use statement.

$expected = "SELECT d0_.id AS id_0, d0_.created AS created_1 FROM Date d0_ WHERE DATE_TRUNC('YEAR'::text, d0_.created::timestamp) = DATE_TRUNC('YEAR'::text, ?::timestamp)";

$this->assertEquals($expected, $queryBuilder->getQuery()->getSQL());

}

Check failure on line 34 in tests/Query/Postgresql/DateTruncTest.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (8.3)

Function closing brace must go on the next line following the body; found 1 blank lines before brace
}
Loading