Skip to content

Commit

Permalink
Replace assertion with exception
Browse files Browse the repository at this point in the history
This issue can actually happen.
  • Loading branch information
greg0ire committed Jun 3, 2024
1 parent 3a7d7c9 commit bf238d0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Query/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2924,7 +2924,10 @@ public function ArithmeticPrimary()
return new AST\ParenthesisExpression($expr);
}

assert($this->lexer->lookahead !== null);
if ($this->lexer->lookahead === null) {
$this->syntaxError('ArithmeticPrimary');
}

switch ($this->lexer->lookahead->type) {
case TokenType::T_COALESCE:
case TokenType::T_NULLIF:
Expand Down
40 changes: 40 additions & 0 deletions tests/Tests/ORM/Functional/Ticket/GH11487Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Query\QueryException;
use Doctrine\Tests\OrmFunctionalTestCase;

class GH11487Test extends OrmFunctionalTestCase
{
public function testItThrowsASyntaxErrorOnUnfinishedQuery(): void
{
$this->expectException(QueryException::class);
$this->expectExceptionMessage('Syntax Error');
$this->_em->createQuery('UPDATE Doctrine\Tests\ORM\Functional\Ticket\TaxType t SET t.default =')->execute();
}
}

/** @Entity */
class TaxType
{
/**
* @var int|null
* @Column(type="integer")
* @Id
* @GeneratedValue
*/
public $id;

/**
* @var bool
* @Column(type="boolean")
*/
public $default = false;
}

0 comments on commit bf238d0

Please sign in to comment.