Replace deprecated UnitOfWork::clear($entityClassName) with a more granular refresh

We removed EntityManager::clear($entityClassName) already, but this one is deprecated
as well: 212edaa80b/lib/Doctrine/ORM/UnitOfWork.php (L2762)

[MAILPOET-5745]
This commit is contained in:
Jan Jakes
2023-11-30 15:09:38 +01:00
committed by Aschepikov
parent 125b0ab03d
commit a54fd9b8fc
2 changed files with 65 additions and 3 deletions

View File

@@ -0,0 +1,49 @@
<?php declare(strict_types = 1);
namespace MailPoet\Test\Settings;
use MailPoet\Entities\SettingEntity;
use MailPoet\Settings\SettingsRepository;
use MailPoetTest;
class SettingsRepositoryTest extends MailPoetTest {
public function testItFetchesAlwaysFreshData(): void {
$repository = $this->diContainer->get(SettingsRepository::class);
$setting = new SettingEntity();
$setting->setName('name');
$setting->setValue('value');
$this->entityManager->persist($setting);
$this->entityManager->flush();
$this->assertSame('value', $setting->getValue());
$this->entityManager->createQueryBuilder()
->update(SettingEntity::class, 's')
->set('s.value', ':value')
->where('s.name = :name')
->setParameter('value', 'new value')
->setParameter('name', 'name')
->getQuery()
->execute();
$this->assertSame('value', $setting->getValue());
$newSetting = $repository->findOneByName('name');
$this->assertSame($setting, $newSetting);
$this->assertSame('new value', $setting->getValue());
$this->assertSame('new value', $newSetting->getValue());
}
public function testUpdateRefreshesExistingData(): void {
$repository = $this->diContainer->get(SettingsRepository::class);
$setting = new SettingEntity();
$setting->setName('name');
$setting->setValue('value');
$this->entityManager->persist($setting);
$this->entityManager->flush();
$this->assertSame('value', $setting->getValue());
$repository->createOrUpdateByName('name', 'new value');
$this->assertSame('new value', $setting->getValue());
}
}