1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
<?php
declare(strict_types=1);
namespace Doctrine\Tests\ORM\Functional\Ticket;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Query\Parameter;
use Doctrine\Tests\Models\Company\CompanyEmployee;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\Attributes\Group;
#[Group('DDC-2090')]
#[Group('non-cacheable')]
class DDC2090Test extends OrmFunctionalTestCase
{
protected function setUp(): void
{
$this->useModelSet('company');
parent::setUp();
}
public function testIssue(): void
{
$date1 = new DateTime('2011-11-11 11:11:11');
$date2 = new DateTime('2012-12-12 12:12:12');
$employee1 = new CompanyEmployee();
$employee2 = new CompanyEmployee();
$employee1->setName('Fabio B. Silva');
$employee1->setStartDate(new DateTime('yesterday'));
$employee1->setDepartment('R&D');
$employee1->setSalary(100);
$employee2->setName('Doctrine Bot');
$employee1->setStartDate(new DateTime('yesterday'));
$employee2->setDepartment('QA');
$employee2->setSalary(100);
$this->_em->persist($employee1);
$this->_em->persist($employee2);
$this->_em->flush();
$this->_em->clear();
$this->_em->createQueryBuilder()
->update(CompanyEmployee::class, 'e')
->set('e.startDate', ':date')
->set('e.salary', ':salary')
->where('e = :e')
->setParameters(new ArrayCollection([
new Parameter('e', $employee1),
new Parameter('date', $date1),
new Parameter('salary', 101),
]))
->getQuery()
->useQueryCache(true)
->execute();
$this->_em->createQueryBuilder()
->update(CompanyEmployee::class, 'e')
->set('e.startDate', ':date')
->set('e.salary', ':salary')
->where('e = :e')
->setParameters(new ArrayCollection([
new Parameter('e', $employee2),
new Parameter('date', $date2),
new Parameter('salary', 102),
]))
->getQuery()
->useQueryCache(true)
->execute();
$this->_em->clear();
$e1 = $this->_em->find(CompanyEmployee::class, $employee1->getId());
$e2 = $this->_em->find(CompanyEmployee::class, $employee2->getId());
self::assertEquals(101, $e1->getSalary());
self::assertEquals(102, $e2->getSalary());
self::assertEquals($date1, $e1->getStartDate());
self::assertEquals($date2, $e2->getStartDate());
$this->_em->createQueryBuilder()
->update(CompanyEmployee::class, 'e')
->set('e.startDate', '?1')
->set('e.salary', '?2')
->where('e = ?0')
->setParameters(new ArrayCollection([
new Parameter('0', $employee1),
new Parameter('1', $date1),
new Parameter('2', 101),
]))
->getQuery()
->useQueryCache(true)
->execute();
$this->_em->createQueryBuilder()
->update(CompanyEmployee::class, 'e')
->set('e.startDate', '?1')
->set('e.salary', '?2')
->where('e = ?0')
->setParameters(new ArrayCollection([
new Parameter('0', $employee2),
new Parameter('1', $date2),
new Parameter('2', 102),
]))
->getQuery()
->useQueryCache(true)
->execute();
$this->_em->clear();
$e1 = $this->_em->find(CompanyEmployee::class, $employee1->getId());
$e2 = $this->_em->find(CompanyEmployee::class, $employee2->getId());
self::assertEquals(101, $e1->getSalary());
self::assertEquals(102, $e2->getSalary());
self::assertEquals($date1, $e1->getStartDate());
self::assertEquals($date2, $e2->getStartDate());
}
}
|