Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yevheniipererva committed Dec 10, 2024
1 parent 83f2898 commit 38ee7a8
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 108 deletions.
10 changes: 5 additions & 5 deletions tests/Tests/ORM/Functional/NativeQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ public function testGenerateSelectClauseNoRenameSingleEntity(): void

$selectClause = $rsm->generateSelectClause();

$this->assertSQLEquals('u.id AS id, u.status AS status, u.username AS username, u.name AS name, u.email_id AS email_id', $selectClause);
$this->assertSQLEquals('u.id AS id, u.reference as reference, u.status AS status, u.username AS username, u.name AS name, u.email_id AS email_id', $selectClause);
}

#[Group('DDC-2055')]
Expand All @@ -489,7 +489,7 @@ public function testGenerateSelectClauseCustomRenames(): void

$selectClause = $rsm->generateSelectClause();

$this->assertSQLEquals('u.id AS id1, u.status AS status, u.username AS username2, u.name AS name, u.email_id AS email_id', $selectClause);
$this->assertSQLEquals('u.id AS id1, u.reference as reference, u.status AS status, u.username AS username2, u.name AS name, u.email_id AS email_id', $selectClause);
}

#[Group('DDC-2055')]
Expand All @@ -500,7 +500,7 @@ public function testGenerateSelectClauseRenameTableAlias(): void

$selectClause = $rsm->generateSelectClause(['u' => 'u1']);

$this->assertSQLEquals('u1.id AS id, u1.status AS status, u1.username AS username, u1.name AS name, u1.email_id AS email_id', $selectClause);
$this->assertSQLEquals('u1.id AS id, u1.reference as reference, u1.status AS status, u1.username AS username, u1.name AS name, u1.email_id AS email_id', $selectClause);
}

#[Group('DDC-2055')]
Expand All @@ -511,7 +511,7 @@ public function testGenerateSelectClauseIncrement(): void

$selectClause = $rsm->generateSelectClause();

$this->assertSQLEquals('u.id AS id0, u.status AS status1, u.username AS username2, u.name AS name3, u.email_id AS email_id4', $selectClause);
$this->assertSQLEquals('u.id AS id0, u.reference as reference1, u.status as status2, u.username as username3, u.name as name4, u.email_id as email_id5', $selectClause);
}

#[Group('DDC-2055')]
Expand All @@ -520,7 +520,7 @@ public function testGenerateSelectClauseToString(): void
$rsm = new ResultSetMappingBuilder($this->_em, ResultSetMappingBuilder::COLUMN_RENAMING_INCREMENT);
$rsm->addRootEntityFromClassMetadata(CmsUser::class, 'u');

$this->assertSQLEquals('u.id AS id0, u.status AS status1, u.username AS username2, u.name AS name3, u.email_id AS email_id4', (string) $rsm);
$this->assertSQLEquals('u.id AS id0, u.reference as reference1, u.status as status2, u.username as username3, u.name as name4, u.email_id as email_id5', (string) $rsm);
}

#[Group('DDC-3899')]
Expand Down
64 changes: 46 additions & 18 deletions tests/Tests/ORM/Functional/QueryParameterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@
use Doctrine\DBAL\Types\Types;
use Doctrine\Tests\Models\CMS\CmsUser;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;

use function hex2bin;
use function sprintf;

#[Group('GH-11278')]
final class QueryParameterTest extends OrmFunctionalTestCase
{
Expand All @@ -27,15 +23,15 @@ protected function setUp(): void
parent::setUp();

$user = new CmsUser();
$user->reference = hex2bin('1');
$user->reference = '0b0001';
$user->name = 'John Doe';
$user->username = 'john';
$user2 = new CmsUser();
$user2->reference = hex2bin('2');
$user2->reference = '0b0010';
$user2->name = 'Jane Doe';
$user2->username = 'jane';
$user3 = new CmsUser();
$user3->reference = hex2bin('3');
$user3->reference = '0b0011';
$user3->name = 'Just Bill';
$user3->username = 'bill';

Expand Down Expand Up @@ -101,27 +97,59 @@ public function testDbalTypeStringInQuery(): void
self::assertSame([['name' => 'John Doe']], $result);
}

#[DataProvider('provideArrayParameters')]
public function testArrayParameterTypeInQuery(string $field, ArrayParameterType $type, array $values): void
public function testArrayParameterTypeInBuilder(): void
{
$result = $this->_em->createQueryBuilder()
->from(CmsUser::class, 'u')
->select('u.name')
->where('u.username IN (:values)')
->orderBy('u.username')
->setParameter('values', ['john', 'jane'], ArrayParameterType::STRING)
->getQuery()
->getArrayResult();

self::assertSame([['name' => 'Jane Doe'], ['name' => 'John Doe']], $result);
}

public function testArrayParameterTypeInQuery(): void
{
$result = $this->_em->createQueryBuilder()
->from(CmsUser::class, 'u')
->select('u.name')
->where('u.username IN (:values)')
->orderBy('u.username')
->getQuery()
->setParameter('values', ['john', 'jane'], ArrayParameterType::STRING)
->getArrayResult();

self::assertSame([['name' => 'Jane Doe'], ['name' => 'John Doe']], $result);
}

public function testArrayParameterTypeBinaryInBuilder(): void
{
$result = $this->_em->createQueryBuilder()
->from(CmsUser::class, 'u')
->select('u.name')
->where(sprintf('u.%s IN (:values)', $field))
->orderBy(sprintf('u.%s', $field))
->setParameter('values', $values, $type)
->where('u.reference IN (:values)')
->orderBy('u.username')
->setParameter('values', ['0b0001', '0b0010'], ArrayParameterType::BINARY)
->getQuery()
->getArrayResult();

self::assertSame([['name' => 'Jane Doe'], ['name' => 'John Doe']], $result);
}

public static function provideArrayParameters(): array
public function testArrayParameterTypeBinaryInQuery(): void
{
return [
'string' => ['username', ArrayParameterType::STRING, ['john', 'jane']],
'binary' => ['reference', ArrayParameterType::BINARY, [hex2bin('1'), hex2bin('2')]],
'integer' => ['id' => ArrayParameterType::INTEGER, [1, 2]],
];
$result = $this->_em->createQueryBuilder()
->from(CmsUser::class, 'u')
->select('u.name')
->where('u.reference IN (:values)')
->orderBy('u.username')
->getQuery()
->setParameter('values', ['0b0001', '0b0010'], ArrayParameterType::BINARY)
->getArrayResult();

self::assertSame([['name' => 'Jane Doe'], ['name' => 'John Doe']], $result);
}
}
2 changes: 1 addition & 1 deletion tests/Tests/ORM/Query/CustomTreeWalkersJoinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function testAddsJoin(): void
{
$this->assertSqlGeneration(
'select u from Doctrine\Tests\Models\CMS\CmsUser u',
'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, c1_.id AS id_4, c1_.country AS country_5, c1_.zip AS zip_6, c1_.city AS city_7, c0_.email_id AS email_id_8, c1_.user_id AS user_id_9 FROM cms_users c0_ LEFT JOIN cms_addresses c1_ ON c0_.id = c1_.user_id',
'SELECT c0_.id AS id_0, c0_.reference AS reference_1, c0_.status AS status_2, c0_.username AS username_3, c0_.name AS name_4, c1_.id AS id_5, c1_.country AS country_6, c1_.zip AS zip_7, c1_.city AS city_8, c0_.email_id AS email_id_9, c1_.user_id AS user_id_10 FROM cms_users c0_ LEFT JOIN cms_addresses c1_ ON c0_.id = c1_.user_id',
);
}

Expand Down
8 changes: 4 additions & 4 deletions tests/Tests/ORM/Query/CustomTreeWalkersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function testSupportsQueriesWithoutWhere(): void
{
$this->assertSqlGeneration(
'select u from Doctrine\Tests\Models\CMS\CmsUser u',
'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, c0_.email_id AS email_id_4 FROM cms_users c0_ WHERE c0_.id = 1',
'SELECT c0_.id AS id_0, c0_.reference AS reference_1, c0_.status AS status_2, c0_.username AS username_3, c0_.name AS name_4, c0_.email_id AS email_id_5 FROM cms_users c0_ WHERE c0_.id = 1',
[CustomTreeWalker::class],
);
}
Expand All @@ -83,7 +83,7 @@ public function testSupportsQueriesWithMultipleConditionalExpressions(): void
{
$this->assertSqlGeneration(
'select u from Doctrine\Tests\Models\CMS\CmsUser u where u.name = :name or u.name = :otherName',
'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, c0_.email_id AS email_id_4 FROM cms_users c0_ WHERE (c0_.name = ? OR c0_.name = ?) AND c0_.id = 1',
'SELECT c0_.id AS id_0, c0_.reference AS reference_1, c0_.status AS status_2, c0_.username AS username_3, c0_.name AS name_4, c0_.email_id AS email_id_5 FROM cms_users c0_ WHERE (c0_.name = ? OR c0_.name = ?) AND c0_.id = 1',
[CustomTreeWalker::class],
);
}
Expand All @@ -92,7 +92,7 @@ public function testSupportsQueriesWithSimpleConditionalExpression(): void
{
$this->assertSqlGeneration(
'select u from Doctrine\Tests\Models\CMS\CmsUser u where u.name = :name',
'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, c0_.email_id AS email_id_4 FROM cms_users c0_ WHERE c0_.name = ? AND c0_.id = 1',
'SELECT c0_.id AS id_0, c0_.reference AS reference_1, c0_.status AS status_2, c0_.username AS username_3, c0_.name AS name_4, c0_.email_id AS email_id_5 FROM cms_users c0_ WHERE c0_.name = ? AND c0_.id = 1',
[CustomTreeWalker::class],
);
}
Expand All @@ -113,7 +113,7 @@ public function testSupportsSeveralHintsQueries(): void
{
$this->assertSqlGeneration(
'select u from Doctrine\Tests\Models\CMS\CmsUser u',
'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3, c1_.id AS id_4, c1_.country AS country_5, c1_.zip AS zip_6, c1_.city AS city_7, c0_.email_id AS email_id_8, c1_.user_id AS user_id_9 FROM cms_users c0_ LEFT JOIN cms_addresses c1_ ON c0_.id = c1_.user_id WHERE c0_.id = 1',
'SELECT c0_.id AS id_0, c0_.reference AS reference_1, c0_.status AS status_2, c0_.username AS username_3, c0_.name AS name_4, c1_.id AS id_5, c1_.country AS country_6, c1_.zip AS zip_7, c1_.city AS city_8, c0_.email_id AS email_id_9, c1_.user_id AS user_id_10 FROM cms_users c0_ LEFT JOIN cms_addresses c1_ ON c0_.id = c1_.user_id WHERE c0_.id = 1',
[CustomTreeWalkerJoin::class, CustomTreeWalker::class],
);
}
Expand Down
Loading

0 comments on commit 38ee7a8

Please sign in to comment.