Skip to content

Commit

Permalink
Simplify LanguageRecognitionTest (#9930)
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus authored Jul 25, 2022
1 parent f5246bd commit 6c64bc6
Showing 1 changed file with 8 additions and 28 deletions.
36 changes: 8 additions & 28 deletions tests/Doctrine/Tests/ORM/Query/LanguageRecognitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
use Doctrine\Tests\Mocks\MockTreeWalker;
use Doctrine\Tests\OrmTestCase;

use const PHP_EOL;

class LanguageRecognitionTest extends OrmTestCase
{
/** @var EntityManagerInterface */
Expand All @@ -28,34 +26,16 @@ protected function setUp(): void
$this->entityManager = $this->getTestEntityManager();
}

public function assertValidDQL($dql, $debug = false): void
public function assertValidDQL(string $dql): void
{
try {
$parserResult = $this->parseDql($dql);
$this->addToAssertionCount(1);
} catch (QueryException $e) {
if ($debug) {
echo $e->getTraceAsString() . PHP_EOL;
}

self::fail($e->getMessage());
}
$this->parseDql($dql);
$this->addToAssertionCount(1);
}

public function assertInvalidDQL($dql, $debug = false): void
public function assertInvalidDQL(string $dql): void
{
try {
$parserResult = $this->parseDql($dql);

self::fail('No syntax errors were detected, when syntax errors were expected');
} catch (QueryException $e) {
if ($debug) {
echo $e->getMessage() . PHP_EOL;
echo $e->getTraceAsString() . PHP_EOL;
}

$this->addToAssertionCount(1);
}
$this->expectException(QueryException::class);
$this->parseDql($dql);
}

/**
Expand Down Expand Up @@ -370,7 +350,7 @@ public function testSelectLiteralInSubselect(): void
*/
public function testConstantValueInSelect(): void
{
$this->assertValidDQL("SELECT u.name, 'foo' AS bar FROM Doctrine\Tests\Models\CMS\CmsUser u", true);
$this->assertValidDQL("SELECT u.name, 'foo' AS bar FROM Doctrine\Tests\Models\CMS\CmsUser u");
}

public function testDuplicateAliasInSubselectPart(): void
Expand Down Expand Up @@ -594,7 +574,7 @@ public function testCustomFunctionsReturningStringInStringPrimary(): void
{
$this->entityManager->getConfiguration()->addCustomStringFunction('CC', Query\AST\Functions\ConcatFunction::class);

$this->assertValidDQL("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE CC('%', u.name) LIKE '%foo%'", true);
$this->assertValidDQL("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE CC('%', u.name) LIKE '%foo%'");
}

/**
Expand Down

0 comments on commit 6c64bc6

Please sign in to comment.