-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 3.1.x: Backport QueryParameterTest (#11288) Test different ways of settings query parameters Be less restrictive in DiscriminatorColumnMapping phpdoc (#11226) Allow (Array)ParameterType in QueryBuilder Do not implicitly cast glob's return type Do not cast file_put_contents's return type Do not implicitly cast getLockTime()'s return type Do not implicitly cast getLockContent()'s return value
- Loading branch information
Showing
5 changed files
with
146 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional; | ||
|
||
use Doctrine\DBAL\ArrayParameterType; | ||
use Doctrine\DBAL\ParameterType; | ||
use Doctrine\DBAL\Types\Types; | ||
use Doctrine\Tests\Models\CMS\CmsUser; | ||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
use PHPUnit\Framework\Attributes\Group; | ||
|
||
#[Group('GH-11278')] | ||
final class QueryParameterTest extends OrmFunctionalTestCase | ||
{ | ||
private int $userId; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->useModelSet('cms'); | ||
|
||
parent::setUp(); | ||
|
||
$user = new CmsUser(); | ||
$user->name = 'John Doe'; | ||
$user->username = 'john'; | ||
$user2 = new CmsUser(); | ||
$user2->name = 'Jane Doe'; | ||
$user2->username = 'jane'; | ||
$user3 = new CmsUser(); | ||
$user3->name = 'Just Bill'; | ||
$user3->username = 'bill'; | ||
|
||
$this->_em->persist($user); | ||
$this->_em->persist($user2); | ||
$this->_em->persist($user3); | ||
$this->_em->flush(); | ||
|
||
$this->userId = $user->id; | ||
|
||
$this->_em->clear(); | ||
} | ||
|
||
public function testParameterTypeInBuilder(): void | ||
{ | ||
$result = $this->_em->createQueryBuilder() | ||
->from(CmsUser::class, 'u') | ||
->select('u.name') | ||
->where('u.id = :id') | ||
->setParameter('id', $this->userId, ParameterType::INTEGER) | ||
->getQuery() | ||
->getArrayResult(); | ||
|
||
self::assertSame([['name' => 'John Doe']], $result); | ||
} | ||
|
||
public function testParameterTypeInQuery(): void | ||
{ | ||
$result = $this->_em->createQueryBuilder() | ||
->from(CmsUser::class, 'u') | ||
->select('u.name') | ||
->where('u.id = :id') | ||
->getQuery() | ||
->setParameter('id', $this->userId, ParameterType::INTEGER) | ||
->getArrayResult(); | ||
|
||
self::assertSame([['name' => 'John Doe']], $result); | ||
} | ||
|
||
public function testDbalTypeStringInBuilder(): void | ||
{ | ||
$result = $this->_em->createQueryBuilder() | ||
->from(CmsUser::class, 'u') | ||
->select('u.name') | ||
->where('u.id = :id') | ||
->setParameter('id', $this->userId, Types::INTEGER) | ||
->getQuery() | ||
->getArrayResult(); | ||
|
||
self::assertSame([['name' => 'John Doe']], $result); | ||
} | ||
|
||
public function testDbalTypeStringInQuery(): void | ||
{ | ||
$result = $this->_em->createQueryBuilder() | ||
->from(CmsUser::class, 'u') | ||
->select('u.name') | ||
->where('u.id = :id') | ||
->getQuery() | ||
->setParameter('id', $this->userId, Types::INTEGER) | ||
->getArrayResult(); | ||
|
||
self::assertSame([['name' => 'John Doe']], $result); | ||
} | ||
|
||
public function testArrayParameterTypeInBuilder(): void | ||
{ | ||
$result = $this->_em->createQueryBuilder() | ||
->from(CmsUser::class, 'u') | ||
->select('u.name') | ||
->where('u.username IN (:usernames)') | ||
->orderBy('u.username') | ||
->setParameter('usernames', ['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 (:usernames)') | ||
->orderBy('u.username') | ||
->getQuery() | ||
->setParameter('usernames', ['john', 'jane'], ArrayParameterType::STRING) | ||
->getArrayResult(); | ||
|
||
self::assertSame([['name' => 'Jane Doe'], ['name' => 'John Doe']], $result); | ||
} | ||
} |