From 758737457ad64b85b4cbbf8c4354ac646b43c387 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Wed, 22 Mar 2023 08:57:13 +0100 Subject: [PATCH 01/58] Up psalm to level 2 --- psalm.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/psalm.xml b/psalm.xml index 286ab14b..54ce0b8d 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,5 +1,5 @@ - + From 8d89c88ae52c7d23fc7d7bde69b61ea46207a579 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Wed, 22 Mar 2023 09:01:46 +0100 Subject: [PATCH 02/58] Drop php < 8 code --- tests/BaseTest.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/BaseTest.php b/tests/BaseTest.php index 0f16f207..e8998f1c 100644 --- a/tests/BaseTest.php +++ b/tests/BaseTest.php @@ -98,12 +98,7 @@ protected function getEntityManager(): EntityManager $mappingPaths[] = __DIR__.'/Fixtures/PHP81Issue'; } - if (version_compare(\PHP_VERSION, '8.0.0', '>=')) { - $config = ORMSetup::createAttributeMetadataConfiguration($mappingPaths, true); - } else { - $config = ORMSetup::createAnnotationMetadataConfiguration($mappingPaths, true); - } - + $config = ORMSetup::createAttributeMetadataConfiguration($mappingPaths, true); $connection = $this->_getConnection($config); $this->em = new EntityManager($connection, $config, new EventManager()); From 5efea1df3552f04f77a2b44bcc3cb959b4d27d7f Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Wed, 22 Mar 2023 09:04:37 +0100 Subject: [PATCH 03/58] Update Issue156Contact.php --- tests/Fixtures/Issue/Issue156Contact.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/Fixtures/Issue/Issue156Contact.php b/tests/Fixtures/Issue/Issue156Contact.php index e532e332..d91583be 100644 --- a/tests/Fixtures/Issue/Issue156Contact.php +++ b/tests/Fixtures/Issue/Issue156Contact.php @@ -23,13 +23,10 @@ #[ORM\DiscriminatorColumn(name: 'discriminator', type: Types::STRING)] class Issue156Contact { - /** - * @var int - */ #[ORM\Id] #[ORM\Column(type: Types::INTEGER)] #[ORM\GeneratedValue] - protected $id; + protected ?int $id = null; /** * @var Collection From eb5d2731c9ab05f68e87d0d43b861c72473954fd Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Wed, 22 Mar 2023 09:06:54 +0100 Subject: [PATCH 04/58] Update AbstractDataEntity.php --- tests/Fixtures/Relation/AbstractDataEntity.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/Fixtures/Relation/AbstractDataEntity.php b/tests/Fixtures/Relation/AbstractDataEntity.php index f4791ff8..29444385 100644 --- a/tests/Fixtures/Relation/AbstractDataEntity.php +++ b/tests/Fixtures/Relation/AbstractDataEntity.php @@ -16,22 +16,16 @@ use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; -/** - * Abstract data entity. - */ #[ORM\Entity] #[ORM\InheritanceType('SINGLE_TABLE')] #[ORM\DiscriminatorColumn(name: 'type', type: Types::STRING)] #[ORM\DiscriminatorMap(['private' => DataPrivateEntity::class, 'legal' => DataLegalEntity::class])] abstract class AbstractDataEntity { - /** - * @var int - */ #[ORM\Column(type: Types::INTEGER)] #[ORM\Id] #[ORM\GeneratedValue] - protected $id; + protected ?int $id = null; #[ORM\OneToOne(targetEntity: DataContainerEntity::class, mappedBy: 'data')] private ?DataContainerEntity $dataContainer = null; From a0fa3522920d90755776c4506dc17c276b56b045 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Wed, 22 Mar 2023 09:10:38 +0100 Subject: [PATCH 05/58] Update Issue308User.php --- tests/Fixtures/Issue/Issue308User.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/Fixtures/Issue/Issue308User.php b/tests/Fixtures/Issue/Issue308User.php index b2c27b4f..0f212924 100644 --- a/tests/Fixtures/Issue/Issue308User.php +++ b/tests/Fixtures/Issue/Issue308User.php @@ -22,19 +22,13 @@ #[ORM\Entity] class Issue308User { - /** - * @var int - */ #[ORM\Id] #[ORM\Column(type: Types::INTEGER)] #[ORM\GeneratedValue] - protected $id; + protected ?int $id = null; - /** - * @var Issue308User|null - */ #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')] - protected $parent; + protected ?Issue308User $parent = null; /** * @var Collection From 3073a09000a7db5484eaf581f1b13d24081e0a63 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Wed, 22 Mar 2023 09:12:06 +0100 Subject: [PATCH 06/58] Update DataContainerEntity.php --- tests/Fixtures/Relation/DataContainerEntity.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/Fixtures/Relation/DataContainerEntity.php b/tests/Fixtures/Relation/DataContainerEntity.php index e50b85ef..24294e0c 100644 --- a/tests/Fixtures/Relation/DataContainerEntity.php +++ b/tests/Fixtures/Relation/DataContainerEntity.php @@ -16,19 +16,13 @@ use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; -/** - * Data container entity. - */ #[ORM\Entity] class DataContainerEntity { - /** - * @var int - */ #[ORM\Id] #[ORM\Column(type: Types::INTEGER)] #[ORM\GeneratedValue] - protected $id; + protected ?int $id = null; #[ORM\OneToOne(targetEntity: AbstractDataEntity::class, inversedBy: 'dataContainer', cascade: ['persist', 'remove'])] private ?AbstractDataEntity $data = null; From 27e260a039b784a471ff5311c46cbd89c9e302d7 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Wed, 22 Mar 2023 09:15:57 +0100 Subject: [PATCH 07/58] Update OwnerEntity.php --- tests/Fixtures/Relation/OwnerEntity.php | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/tests/Fixtures/Relation/OwnerEntity.php b/tests/Fixtures/Relation/OwnerEntity.php index 5bb86cdd..bfd03d8a 100644 --- a/tests/Fixtures/Relation/OwnerEntity.php +++ b/tests/Fixtures/Relation/OwnerEntity.php @@ -21,31 +21,25 @@ #[ORM\Entity] class OwnerEntity { - /** - * @var int|null - */ #[ORM\Id] #[ORM\Column(type: Types::INTEGER, name: 'some_strange_key_name')] #[ORM\GeneratedValue] - protected $id; + protected ?int $id = null; - /** - * @var string|null - */ #[ORM\Column(type: Types::STRING, name: 'crazy_title_to_mess_up_audit')] - protected $title; + protected ?string $title = null; /** * @var Collection */ #[ORM\OneToMany(targetEntity: OwnedEntity1::class, mappedBy: 'owner')] - protected $owned1; + protected Collection $owned1; /** * @var Collection */ #[ORM\OneToMany(targetEntity: OwnedEntity2::class, mappedBy: 'owner')] - protected $owned2; + protected Collection $owned2; /** * @var Collection @@ -54,16 +48,18 @@ class OwnerEntity #[ORM\JoinTable(name: 'owner_owned3')] #[ORM\JoinColumn(name: 'owner_id', referencedColumnName: 'some_strange_key_name')] #[ORM\InverseJoinColumn(name: 'owned3_id', referencedColumnName: 'strange_owned_id_name')] - protected $owned3; + protected Collection $owned3; /** * @var Collection */ #[ORM\ManyToMany(targetEntity: OwnedEntity4::class, mappedBy: 'owners')] - protected $ownedInverse; + protected Collection $ownedInverse; public function __construct() { + $this->owned1 = new ArrayCollection(); + $this->owned2 = new ArrayCollection(); $this->owned3 = new ArrayCollection(); $this->ownedInverse = new ArrayCollection(); } From d2fa27f811a563ceaff439d0b3915b175da90c80 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Wed, 22 Mar 2023 09:18:45 +0100 Subject: [PATCH 08/58] Update Page.php --- tests/Fixtures/Relation/Page.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/Fixtures/Relation/Page.php b/tests/Fixtures/Relation/Page.php index f1cae63c..b2dd2c45 100644 --- a/tests/Fixtures/Relation/Page.php +++ b/tests/Fixtures/Relation/Page.php @@ -21,13 +21,10 @@ #[ORM\Entity] class Page implements \Stringable { - /** - * @var int|null - */ #[ORM\Id] #[ORM\Column(type: Types::INTEGER)] #[ORM\GeneratedValue] - protected $id; + protected ?int $id = null; /** * A page can have many aliases. @@ -35,16 +32,17 @@ class Page implements \Stringable * @var Collection */ #[ORM\OneToMany(targetEntity: PageAlias::class, mappedBy: 'page', cascade: ['persist'])] - protected $pageAliases; + protected Collection $pageAliases; /** * @var Collection */ #[ORM\OneToMany(targetEntity: PageLocalization::class, mappedBy: 'page', indexBy: 'locale')] - protected $localizations; + protected Collection $localizations; public function __construct() { + $this->pageAliases = new ArrayCollection(); $this->localizations = new ArrayCollection(); } From 2875f491f89cda379aaab3e6a054d0ef81695027 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Wed, 22 Mar 2023 09:24:56 +0100 Subject: [PATCH 09/58] Update BaseTest.php --- tests/BaseTest.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/tests/BaseTest.php b/tests/BaseTest.php index e8998f1c..a11b8265 100644 --- a/tests/BaseTest.php +++ b/tests/BaseTest.php @@ -19,6 +19,7 @@ use Doctrine\DBAL\Types\Type; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\ORMSetup; use Doctrine\ORM\Tools\SchemaTool; @@ -34,17 +35,9 @@ abstract class BaseTest extends TestCase */ protected static $conn; - /** - * NEXT_MAJOR: Use `\Doctrine\ORM\EntityManagerInterface` instead. - * - * @var EntityManager - */ - protected $em; + protected ?EntityManagerInterface $em = null; - /** - * @var AuditManager - */ - protected $auditManager; + protected ?AuditManager $auditManager = null; /** * @var string[] @@ -82,7 +75,7 @@ protected function tearDown(): void $this->tearDownEntitySchema(); } - protected function getEntityManager(): EntityManager + protected function getEntityManager(): EntityManagerInterface { if (null !== $this->em) { return $this->em; From e1024cae9db67e9a33b5c199749e4806eb5212ac Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Wed, 22 Mar 2023 09:35:54 +0100 Subject: [PATCH 10/58] Actualizar BaseTest.php --- tests/BaseTest.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/tests/BaseTest.php b/tests/BaseTest.php index a11b8265..93a6d26d 100644 --- a/tests/BaseTest.php +++ b/tests/BaseTest.php @@ -35,9 +35,9 @@ abstract class BaseTest extends TestCase */ protected static $conn; - protected ?EntityManagerInterface $em = null; + protected EntityManagerInterface $em; - protected ?AuditManager $auditManager = null; + protected AuditManager $auditManager; /** * @var string[] @@ -61,6 +61,10 @@ abstract class BaseTest extends TestCase protected $customTypes = []; private ?SchemaTool $schemaTool = null; + + private $entityManagerInitialized = false; + + private $auditManagerInitialized = false; protected function setUp(): void { @@ -75,9 +79,9 @@ protected function tearDown(): void $this->tearDownEntitySchema(); } - protected function getEntityManager(): EntityManagerInterface + protected function getEntityManager(): void { - if (null !== $this->em) { + if ($this->entityManagerInitialized) { return $this->em; } @@ -103,6 +107,8 @@ protected function getEntityManager(): EntityManagerInterface $this->em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('db_'.$customTypeName, $customTypeName); } + $this->entityManagerInitialized = true; + return $this->em; } @@ -138,7 +144,7 @@ protected function _getConnection(Configuration $config): Connection protected function getAuditManager(): AuditManager { - if (null !== $this->auditManager) { + if ($this->auditManagerInitialized) { return $this->auditManager; } @@ -146,10 +152,12 @@ protected function getAuditManager(): AuditManager $auditConfig->setGlobalIgnoreColumns(['ignoreme']); $auditConfig->setUsernameCallable(static fn (): string => 'beberlei'); - $auditManager = new AuditManager($auditConfig, $this->getClock()); - $auditManager->registerEvents($this->getEntityManager()->getEventManager()); + $this->auditManager = new AuditManager($auditConfig, $this->getClock()); + $this->auditManager->registerEvents($this->getEntityManager()->getEventManager()); + + $this->auditManagerInitialized = true; - return $this->auditManager = $auditManager; + return $this->auditManager; } protected function getClock(): ?ClockInterface From dfdc8c2dfc79032faf5229529587093e183f5ff6 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Wed, 22 Mar 2023 09:38:21 +0100 Subject: [PATCH 11/58] Actualizar BaseTest.php --- tests/BaseTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/BaseTest.php b/tests/BaseTest.php index 93a6d26d..697ab89d 100644 --- a/tests/BaseTest.php +++ b/tests/BaseTest.php @@ -61,9 +61,9 @@ abstract class BaseTest extends TestCase protected $customTypes = []; private ?SchemaTool $schemaTool = null; - + private $entityManagerInitialized = false; - + private $auditManagerInitialized = false; protected function setUp(): void @@ -79,7 +79,7 @@ protected function tearDown(): void $this->tearDownEntitySchema(); } - protected function getEntityManager(): void + protected function getEntityManager(): EntityManagerInterface { if ($this->entityManagerInitialized) { return $this->em; From fb0e7331548847ff14640737606c481dfa198fde Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Wed, 22 Mar 2023 09:44:58 +0100 Subject: [PATCH 12/58] Actualizar BaseTest.php --- tests/BaseTest.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/BaseTest.php b/tests/BaseTest.php index 697ab89d..bcb0007f 100644 --- a/tests/BaseTest.php +++ b/tests/BaseTest.php @@ -19,7 +19,6 @@ use Doctrine\DBAL\Types\Type; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; -use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\ORMSetup; use Doctrine\ORM\Tools\SchemaTool; @@ -35,7 +34,10 @@ abstract class BaseTest extends TestCase */ protected static $conn; - protected EntityManagerInterface $em; + /** + * NEXT_MAJOR: Change typehint to EntityManagerInterface. + */ + protected EntityManager $em; protected AuditManager $auditManager; @@ -62,9 +64,9 @@ abstract class BaseTest extends TestCase private ?SchemaTool $schemaTool = null; - private $entityManagerInitialized = false; + private bool $entityManagerInitialized = false; - private $auditManagerInitialized = false; + private bool $auditManagerInitialized = false; protected function setUp(): void { From 29efc214b6cbae21d8611ef092af93f64221353e Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Wed, 22 Mar 2023 09:47:26 +0100 Subject: [PATCH 13/58] Actualizar BaseTest.php --- tests/BaseTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/BaseTest.php b/tests/BaseTest.php index bcb0007f..acc6624d 100644 --- a/tests/BaseTest.php +++ b/tests/BaseTest.php @@ -81,7 +81,7 @@ protected function tearDown(): void $this->tearDownEntitySchema(); } - protected function getEntityManager(): EntityManagerInterface + protected function getEntityManager(): EntityManager { if ($this->entityManagerInitialized) { return $this->em; From f95156218e235beb7668f59b3c355801018d42b5 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Wed, 22 Mar 2023 09:50:03 +0100 Subject: [PATCH 14/58] Actualizar BaseTest.php --- tests/BaseTest.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/tests/BaseTest.php b/tests/BaseTest.php index acc6624d..35899957 100644 --- a/tests/BaseTest.php +++ b/tests/BaseTest.php @@ -64,10 +64,6 @@ abstract class BaseTest extends TestCase private ?SchemaTool $schemaTool = null; - private bool $entityManagerInitialized = false; - - private bool $auditManagerInitialized = false; - protected function setUp(): void { $this->getEntityManager(); @@ -83,7 +79,7 @@ protected function tearDown(): void protected function getEntityManager(): EntityManager { - if ($this->entityManagerInitialized) { + if (isset($this->em)) { return $this->em; } @@ -109,8 +105,6 @@ protected function getEntityManager(): EntityManager $this->em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('db_'.$customTypeName, $customTypeName); } - $this->entityManagerInitialized = true; - return $this->em; } @@ -146,7 +140,7 @@ protected function _getConnection(Configuration $config): Connection protected function getAuditManager(): AuditManager { - if ($this->auditManagerInitialized) { + if (isset($this->auditManager)) { return $this->auditManager; } @@ -157,8 +151,6 @@ protected function getAuditManager(): AuditManager $this->auditManager = new AuditManager($auditConfig, $this->getClock()); $this->auditManager->registerEvents($this->getEntityManager()->getEventManager()); - $this->auditManagerInitialized = true; - return $this->auditManager; } From 64d3ad2d2342df3e7d4048ea22c3e423190f966a Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Wed, 22 Mar 2023 09:58:20 +0100 Subject: [PATCH 15/58] Update AuditedCollection.php --- src/Collection/AuditedCollection.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Collection/AuditedCollection.php b/src/Collection/AuditedCollection.php index 218a2884..bf299c4b 100644 --- a/src/Collection/AuditedCollection.php +++ b/src/Collection/AuditedCollection.php @@ -84,7 +84,7 @@ public function __construct( * @return true */ #[\ReturnTypeWillChange] - public function add($element) + public function add(mixed $element) { throw new AuditedCollectionException('The AuditedCollection is read-only'); } @@ -100,7 +100,7 @@ public function clear(): void * @return bool */ #[\ReturnTypeWillChange] - public function contains($element) + public function contains(mixed $element) { $this->forceLoad(); @@ -135,7 +135,7 @@ public function remove($key) * @return bool */ #[\ReturnTypeWillChange] - public function removeElement($element) + public function removeElement(mixed $element) { throw new AuditedCollectionException('Audited collections does not support removal'); } @@ -346,7 +346,7 @@ public function partition(\Closure $p) * @return TKey|false */ #[\ReturnTypeWillChange] - public function indexOf($element) + public function indexOf(mixed $element) { $this->forceLoad(); From 13b7e27135153d179bac414f3b8edda19ec20806 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Wed, 22 Mar 2023 10:03:46 +0100 Subject: [PATCH 16/58] Update AuditedCollection.php --- src/Collection/AuditedCollection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Collection/AuditedCollection.php b/src/Collection/AuditedCollection.php index bf299c4b..3fa65651 100644 --- a/src/Collection/AuditedCollection.php +++ b/src/Collection/AuditedCollection.php @@ -394,7 +394,7 @@ public function offsetExists($offset) * @phpstan-return T */ #[\ReturnTypeWillChange] - public function offsetGet($offset) + public function offsetGet(mixed $offset) { if ($this->loadedEntities->offsetExists($offset)) { $entity = $this->loadedEntities->offsetGet($offset); From 6585cee02e92b6614fb5f9ae3c8a69296b387976 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Wed, 22 Mar 2023 10:04:46 +0100 Subject: [PATCH 17/58] Update AuditedCollection.php --- src/Collection/AuditedCollection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Collection/AuditedCollection.php b/src/Collection/AuditedCollection.php index 3fa65651..ec57e533 100644 --- a/src/Collection/AuditedCollection.php +++ b/src/Collection/AuditedCollection.php @@ -381,7 +381,7 @@ public function getIterator() * @return bool */ #[\ReturnTypeWillChange] - public function offsetExists($offset) + public function offsetExists(mixed $offset) { $this->forceLoad(); From 312d64ca309a1b81ab43dc00694d6dbd16fe09cb Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Wed, 22 Mar 2023 10:05:51 +0100 Subject: [PATCH 18/58] Update AuditedCollection.php --- src/Collection/AuditedCollection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Collection/AuditedCollection.php b/src/Collection/AuditedCollection.php index ec57e533..83aaa662 100644 --- a/src/Collection/AuditedCollection.php +++ b/src/Collection/AuditedCollection.php @@ -417,12 +417,12 @@ public function offsetGet(mixed $offset) return $resolvedEntity; } - public function offsetSet($offset, $value): void + public function offsetSet(mixed $offset, mixed $value): void { throw new AuditedCollectionException('AuditedCollection is read-only'); } - public function offsetUnset($offset): void + public function offsetUnset(mixed $offset): void { throw new AuditedCollectionException('Audited collections does not support removal'); } From 34b25bef0623fe4c1a6ac32d8db6946b6d5ba870 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Wed, 22 Mar 2023 10:08:38 +0100 Subject: [PATCH 19/58] Actualizar AuditedCollection.php --- src/Collection/AuditedCollection.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Collection/AuditedCollection.php b/src/Collection/AuditedCollection.php index 83aaa662..14fe63fe 100644 --- a/src/Collection/AuditedCollection.php +++ b/src/Collection/AuditedCollection.php @@ -354,6 +354,8 @@ public function indexOf(mixed $element) } /** + * @param int $offset + * * @return object[] * * @phpstan-return array From eb0fc3685bf146eb0af5b215042f4a606822ee70 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Wed, 22 Mar 2023 10:19:39 +0100 Subject: [PATCH 20/58] Update src/Collection/AuditedCollection.php --- src/Collection/AuditedCollection.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Collection/AuditedCollection.php b/src/Collection/AuditedCollection.php index 14fe63fe..2dfab955 100644 --- a/src/Collection/AuditedCollection.php +++ b/src/Collection/AuditedCollection.php @@ -355,6 +355,7 @@ public function indexOf(mixed $element) /** * @param int $offset + * @param int|null $length * * @return object[] * From e3ece7e36647aee6ef9ba4bb4121b01bdc56463c Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Wed, 22 Mar 2023 16:31:48 +0100 Subject: [PATCH 21/58] Actualizar AuditedCollection.php --- src/Collection/AuditedCollection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Collection/AuditedCollection.php b/src/Collection/AuditedCollection.php index 2dfab955..ce714d29 100644 --- a/src/Collection/AuditedCollection.php +++ b/src/Collection/AuditedCollection.php @@ -354,7 +354,7 @@ public function indexOf(mixed $element) } /** - * @param int $offset + * @param int $offset * @param int|null $length * * @return object[] From ef2d5c861b62bd0c3982c9a2c5807049d04bace5 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Wed, 22 Mar 2023 16:35:07 +0100 Subject: [PATCH 22/58] Actualizar AuditedCollection.php --- src/Collection/AuditedCollection.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Collection/AuditedCollection.php b/src/Collection/AuditedCollection.php index ce714d29..0bc67258 100644 --- a/src/Collection/AuditedCollection.php +++ b/src/Collection/AuditedCollection.php @@ -123,6 +123,8 @@ public function isEmpty() } /** + * @param string|int $key + * * @return T|null */ #[\ReturnTypeWillChange] @@ -152,6 +154,8 @@ public function containsKey($key) } /** + * @param string|int $key + * * @return object * * @phpstan-return T From 898b8fab8345c298b5a7bb103705d0ea91a608ae Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 17:37:56 +0100 Subject: [PATCH 23/58] Actualizar AuditedCollection.php --- src/Collection/AuditedCollection.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Collection/AuditedCollection.php b/src/Collection/AuditedCollection.php index 0bc67258..43c31d73 100644 --- a/src/Collection/AuditedCollection.php +++ b/src/Collection/AuditedCollection.php @@ -143,6 +143,8 @@ public function removeElement(mixed $element) } /** + * @param int|string $key + * * @return bool */ #[\ReturnTypeWillChange] From d69cea7b008886fece7f5406c8d7433331996247 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 19:39:46 +0100 Subject: [PATCH 24/58] Actualizar AuditConfiguration.php --- src/AuditConfiguration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AuditConfiguration.php b/src/AuditConfiguration.php index bdbb96ac..7f24530f 100644 --- a/src/AuditConfiguration.php +++ b/src/AuditConfiguration.php @@ -214,7 +214,7 @@ public function getCurrentUsername() } /** - * @param callable $usernameCallable + * @param callable|null $usernameCallable */ public function setUsernameCallable($usernameCallable): void { From e9f90e2e3559bb44256c7d236a5b9fcec083807a Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 20:14:34 +0100 Subject: [PATCH 25/58] Actualizar LogRevisionsListener.php --- src/EventListener/LogRevisionsListener.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/EventListener/LogRevisionsListener.php b/src/EventListener/LogRevisionsListener.php index 3de60573..9c6adf59 100644 --- a/src/EventListener/LogRevisionsListener.php +++ b/src/EventListener/LogRevisionsListener.php @@ -27,6 +27,7 @@ use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Persisters\Entity\EntityPersister; use Doctrine\ORM\UnitOfWork; +use Doctrine\ORM\Utility\PersisterHelper; use Doctrine\Persistence\Mapping\MappingException; use Psr\Clock\ClockInterface; use SimpleThings\EntityAudit\AuditConfiguration; @@ -183,7 +184,7 @@ public function postFlush(PostFlushEventArgs $eventArgs): void foreach ($this->deferredChangedManyToManyEntityRevisionsToPersist as $deferredChangedManyToManyEntityRevisionToPersist) { $this->recordRevisionForManyToManyEntity( $deferredChangedManyToManyEntityRevisionToPersist->getEntity(), - $em->getConnection(), + $em, $deferredChangedManyToManyEntityRevisionToPersist->getRevType(), $deferredChangedManyToManyEntityRevisionToPersist->getEntityData(), $deferredChangedManyToManyEntityRevisionToPersist->getAssoc(), @@ -545,7 +546,7 @@ private function saveRevisionEntityData(EntityManagerInterface $em, ClassMetadat // so we have to defer writing the revision record to the DB to the postFlush event by which point we know that the entity is gonna be flushed and have the ID assigned $this->deferredChangedManyToManyEntityRevisionsToPersist[] = new DeferredChangedManyToManyEntityRevisionToPersist($relatedEntity, $revType, $entityData, $assoc, $class, $targetClass); } else { - $this->recordRevisionForManyToManyEntity($relatedEntity, $conn, $revType, $entityData, $assoc, $class, $targetClass); + $this->recordRevisionForManyToManyEntity($relatedEntity, $em, $revType, $entityData, $assoc, $class, $targetClass); } } } @@ -612,19 +613,20 @@ private function saveRevisionEntityData(EntityManagerInterface $em, ClassMetadat * @param ClassMetadata $class * @param ClassMetadata $targetClass */ - private function recordRevisionForManyToManyEntity(object $relatedEntity, Connection $conn, string $revType, array $entityData, array $assoc, ClassMetadata $class, ClassMetadata $targetClass): void + private function recordRevisionForManyToManyEntity(object $relatedEntity, EntityManagerInterface $em, string $revType, array $entityData, array $assoc, ClassMetadata $class, ClassMetadata $targetClass): void { + $conn = $em->getConnection(); $joinTableParams = [$this->getRevisionId($conn), $revType]; $joinTableTypes = [\PDO::PARAM_INT, \PDO::PARAM_STR]; foreach ($assoc['relationToSourceKeyColumns'] as $targetColumn) { $joinTableParams[] = $entityData[$class->fieldNames[$targetColumn]]; - $joinTableTypes[] = $class->getTypeOfColumn($targetColumn); + $joinTableTypes[] = PersisterHelper::getTypeOfColumn($targetColumn, $targetClass, $em); } foreach ($assoc['relationToTargetKeyColumns'] as $targetColumn) { $reflField = $targetClass->reflFields[$targetClass->fieldNames[$targetColumn]]; \assert(null !== $reflField); $joinTableParams[] = $reflField->getValue($relatedEntity); - $joinTableTypes[] = $targetClass->getTypeOfColumn($targetColumn); + $joinTableTypes[] = PersisterHelper::getTypeOfColumn($targetColumn, $targetClass, $em); } $conn->executeStatement( $this->getInsertJoinTableRevisionSQL($class, $targetClass, $assoc), From af3fb5e98bcfdd2c2f04415ad596a1003b10f68d Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 20:21:52 +0100 Subject: [PATCH 26/58] Update src/EventListener/LogRevisionsListener.php --- src/EventListener/LogRevisionsListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EventListener/LogRevisionsListener.php b/src/EventListener/LogRevisionsListener.php index 9c6adf59..f340be6f 100644 --- a/src/EventListener/LogRevisionsListener.php +++ b/src/EventListener/LogRevisionsListener.php @@ -620,7 +620,7 @@ private function recordRevisionForManyToManyEntity(object $relatedEntity, Entity $joinTableTypes = [\PDO::PARAM_INT, \PDO::PARAM_STR]; foreach ($assoc['relationToSourceKeyColumns'] as $targetColumn) { $joinTableParams[] = $entityData[$class->fieldNames[$targetColumn]]; - $joinTableTypes[] = PersisterHelper::getTypeOfColumn($targetColumn, $targetClass, $em); + $joinTableTypes[] = PersisterHelper::getTypeOfColumn($targetColumn, $class, $em); } foreach ($assoc['relationToTargetKeyColumns'] as $targetColumn) { $reflField = $targetClass->reflFields[$targetClass->fieldNames[$targetColumn]]; From aaf4a5b651090b00167621692400fc143e09383d Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 20:35:21 +0100 Subject: [PATCH 27/58] Actualizar LogRevisionsListener.php --- src/EventListener/LogRevisionsListener.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/EventListener/LogRevisionsListener.php b/src/EventListener/LogRevisionsListener.php index f340be6f..7cc5fb1f 100644 --- a/src/EventListener/LogRevisionsListener.php +++ b/src/EventListener/LogRevisionsListener.php @@ -362,12 +362,7 @@ private function getRevisionId(Connection $conn) ] ); - $platform = $conn->getDatabasePlatform(); - $sequenceName = $platform->supportsSequences() - ? $platform->getIdentitySequenceName($this->config->getRevisionTableName(), 'id') - : null; - - $revisionId = $conn->lastInsertId($sequenceName); + $revisionId = $conn->lastInsertId(); if (false === $revisionId) { throw new \RuntimeException('Unable to retrieve the last revision id.'); } From e548d030fc31ddbacd761f82adee9ba7860a99c9 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 21:13:43 +0100 Subject: [PATCH 28/58] Actualizar psalm.xml --- psalm.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/psalm.xml b/psalm.xml index 54ce0b8d..8e1e5863 100644 --- a/psalm.xml +++ b/psalm.xml @@ -12,4 +12,9 @@ + + + + + From 3c649ec3f366a8f98a7c9de9ca0c6fab83027a70 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 21:16:58 +0100 Subject: [PATCH 29/58] Actualizar AuditedCollection.php --- src/Collection/AuditedCollection.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Collection/AuditedCollection.php b/src/Collection/AuditedCollection.php index 43c31d73..539514c2 100644 --- a/src/Collection/AuditedCollection.php +++ b/src/Collection/AuditedCollection.php @@ -146,6 +146,8 @@ public function removeElement(mixed $element) * @param int|string $key * * @return bool + * + * @phpstan-param TKey $key */ #[\ReturnTypeWillChange] public function containsKey($key) From adca8ca8c9106a0d6a5e3ff279ab47e8b42f3f7f Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 21:19:57 +0100 Subject: [PATCH 30/58] Actualizar BaseTest.php --- tests/BaseTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/BaseTest.php b/tests/BaseTest.php index 35899957..8b520778 100644 --- a/tests/BaseTest.php +++ b/tests/BaseTest.php @@ -37,9 +37,9 @@ abstract class BaseTest extends TestCase /** * NEXT_MAJOR: Change typehint to EntityManagerInterface. */ - protected EntityManager $em; + protected ?EntityManager $em = null; - protected AuditManager $auditManager; + protected ?AuditManager $auditManager = null; /** * @var string[] @@ -79,7 +79,7 @@ protected function tearDown(): void protected function getEntityManager(): EntityManager { - if (isset($this->em)) { + if (null !== $this->em) { return $this->em; } @@ -140,7 +140,7 @@ protected function _getConnection(Configuration $config): Connection protected function getAuditManager(): AuditManager { - if (isset($this->auditManager)) { + if (null !== $this->auditManager) { return $this->auditManager; } From e4eb4b1a280a301b2ba76dd09a7958f52e985f60 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 22:46:42 +0100 Subject: [PATCH 31/58] Actualizar CoreTest.php --- tests/CoreTest.php | 227 +++++++++++++++++++++++++-------------------- 1 file changed, 126 insertions(+), 101 deletions(-) diff --git a/tests/CoreTest.php b/tests/CoreTest.php index ed0fa4ff..2c1e4de7 100644 --- a/tests/CoreTest.php +++ b/tests/CoreTest.php @@ -64,18 +64,20 @@ public function testAuditable(): void $doggy = new Dog('woof', 80); $cat = new Cat('pusheen', '#b5a89f'); - $this->em->persist($user); - $this->em->persist($article); - $this->em->persist($rabbit); - $this->em->persist($foxy); - $this->em->persist($doggy); - $this->em->persist($cat); - $this->em->flush(); - - static::assertCount(1, $this->em->getConnection()->fetchAllAssociative('SELECT id FROM revisions')); - static::assertCount(1, $this->em->getConnection()->fetchAllAssociative('SELECT * FROM UserAudit_audit')); - static::assertCount(1, $this->em->getConnection()->fetchAllAssociative('SELECT * FROM ArticleAudit_audit')); - static::assertCount(2, $this->em->getConnection()->fetchAllAssociative('SELECT * FROM AnimalAudit_audit')); + $em = $this->getEntityManager(); + + $em->persist($user); + $em->persist($article); + $em->persist($rabbit); + $em->persist($foxy); + $em->persist($doggy); + $em->persist($cat); + $em->flush(); + + static::assertCount(1, $em->getConnection()->fetchAllAssociative('SELECT id FROM revisions')); + static::assertCount(1, $em->getConnection()->fetchAllAssociative('SELECT * FROM UserAudit_audit')); + static::assertCount(1, $em->getConnection()->fetchAllAssociative('SELECT * FROM ArticleAudit_audit')); + static::assertCount(2, $em->getConnection()->fetchAllAssociative('SELECT * FROM AnimalAudit_audit')); $article->setText('oeruoa'); $rabbit->setName('Rabbit'); @@ -83,22 +85,22 @@ public function testAuditable(): void $foxy->setName('Foxy'); $foxy->setTailLength(55); - $this->em->flush(); + $em->flush(); - static::assertCount(2, $this->em->getConnection()->fetchAllAssociative('SELECT id FROM revisions')); - static::assertCount(2, $this->em->getConnection()->fetchAllAssociative('SELECT * FROM ArticleAudit_audit')); - static::assertCount(4, $this->em->getConnection()->fetchAllAssociative('SELECT * FROM AnimalAudit_audit')); + static::assertCount(2, $em->getConnection()->fetchAllAssociative('SELECT id FROM revisions')); + static::assertCount(2, $em->getConnection()->fetchAllAssociative('SELECT * FROM ArticleAudit_audit')); + static::assertCount(4, $em->getConnection()->fetchAllAssociative('SELECT * FROM AnimalAudit_audit')); - $this->em->remove($user); - $this->em->remove($article); - $this->em->remove($rabbit); - $this->em->remove($foxy); - $this->em->flush(); + $em->remove($user); + $em->remove($article); + $em->remove($rabbit); + $em->remove($foxy); + $em->flush(); - static::assertCount(3, $this->em->getConnection()->fetchAllAssociative('SELECT id FROM revisions')); - static::assertCount(2, $this->em->getConnection()->fetchAllAssociative('SELECT * FROM UserAudit_audit')); - static::assertCount(3, $this->em->getConnection()->fetchAllAssociative('SELECT * FROM ArticleAudit_audit')); - static::assertCount(6, $this->em->getConnection()->fetchAllAssociative('SELECT * FROM AnimalAudit_audit')); + static::assertCount(3, $em->getConnection()->fetchAllAssociative('SELECT id FROM revisions')); + static::assertCount(2, $em->getConnection()->fetchAllAssociative('SELECT * FROM UserAudit_audit')); + static::assertCount(3, $em->getConnection()->fetchAllAssociative('SELECT * FROM ArticleAudit_audit')); + static::assertCount(6, $em->getConnection()->fetchAllAssociative('SELECT * FROM AnimalAudit_audit')); } public function testFind(): void @@ -107,12 +109,14 @@ public function testFind(): void $foxy = new Fox('foxy', 55); $cat = new Cat('pusheen', '#b5a89f'); - $this->em->persist($cat); - $this->em->persist($user); - $this->em->persist($foxy); - $this->em->flush(); + $em = $this->getEntityManager(); - $reader = $this->auditManager->createAuditReader($this->em); + $em->persist($cat); + $em->persist($user); + $em->persist($foxy); + $em->flush(); + + $reader = $this->auditManager->createAuditReader($em); $userId = $user->getId(); static::assertNotNull($userId); @@ -122,7 +126,7 @@ public function testFind(): void static::assertInstanceOf(UserAudit::class, $auditUser, 'Audited User is also a User instance.'); static::assertSame($user->getId(), $auditUser->getId(), 'Ids of audited user and real user should be the same.'); static::assertSame($user->getName(), $auditUser->getName(), 'Name of audited user and real user should be the same.'); - static::assertFalse($this->em->contains($auditUser), 'Audited User should not be in the identity map.'); + static::assertFalse($em->contains($auditUser), 'Audited User should not be in the identity map.'); static::assertNotSame($user, $auditUser, 'User and Audited User instances are not the same.'); $foxyId = $foxy->getId(); @@ -134,7 +138,7 @@ public function testFind(): void static::assertSame($foxy->getId(), $auditFox->getId(), 'Ids of audited SINGLE_TABLE class and real SINGLE_TABLE class should be the same.'); static::assertSame($foxy->getName(), $auditFox->getName(), 'Loaded and original attributes should be the same for SINGLE_TABLE inheritance.'); static::assertSame($foxy->getTailLength(), $auditFox->getTailLength(), 'Loaded and original attributes should be the same for SINGLE_TABLE inheritance.'); - static::assertFalse($this->em->contains($auditFox), 'Audited SINGLE_TABLE inheritance class should not be in the identity map.'); + static::assertFalse($em->contains($auditFox), 'Audited SINGLE_TABLE inheritance class should not be in the identity map.'); static::assertNotSame($foxy, $auditFox, 'Audited and new entities should not be the same object for SINGLE_TABLE inheritance.'); $catId = $cat->getId(); @@ -146,13 +150,13 @@ public function testFind(): void static::assertSame($cat->getId(), $auditCat->getId(), 'Ids of audited JOINED class and real JOINED class should be the same.'); static::assertSame($cat->getName(), $auditCat->getName(), 'Loaded and original attributes should be the same for JOINED inheritance.'); static::assertSame($cat->getColor(), $auditCat->getColor(), 'Loaded and original attributes should be the same for JOINED inheritance.'); - static::assertFalse($this->em->contains($auditCat), 'Audited JOINED inheritance class should not be in the identity map.'); + static::assertFalse($em->contains($auditCat), 'Audited JOINED inheritance class should not be in the identity map.'); static::assertNotSame($cat, $auditCat, 'Audited and new entities should not be the same object for JOINED inheritance.'); } public function testFindNoRevisionFound(): void { - $reader = $this->auditManager->createAuditReader($this->em); + $reader = $this->auditManager->createAuditReader($this->getEntityManager()); $this->expectException(NoRevisionFoundException::class); $this->expectExceptionMessage(sprintf( @@ -165,7 +169,7 @@ public function testFindNoRevisionFound(): void public function testFindNotAudited(): void { - $reader = $this->auditManager->createAuditReader($this->em); + $reader = $this->auditManager->createAuditReader($this->getEntityManager()); $this->expectException(NotAuditedException::class); $this->expectExceptionMessage('Class "stdClass" is not audited.'); @@ -177,15 +181,17 @@ public function testFindRevisionHistory(): void { $user = new UserAudit('beberlei'); - $this->em->persist($user); - $this->em->flush(); + $this->getEntityManager(); + + $em->persist($user); + $em->flush(); $article = new ArticleAudit('test', 'yadda!', $user, 'text'); - $this->em->persist($article); - $this->em->flush(); + $em->persist($article); + $em->flush(); - $reader = $this->auditManager->createAuditReader($this->em); + $reader = $this->auditManager->createAuditReader($em); $revisions = $reader->findRevisionHistory(); static::assertCount(2, $revisions); @@ -208,16 +214,18 @@ public function testFindEntitesChangedAtRevision(): void $rabbit = new Rabbit('rabbit', 'white'); $cat = new Cat('pusheen', '#b5a89f'); $dog = new Dog('doggy', 80); - - $this->em->persist($dog); - $this->em->persist($cat); - $this->em->persist($foxy); - $this->em->persist($rabbit); - $this->em->persist($user); - $this->em->persist($article); - $this->em->flush(); - - $reader = $this->auditManager->createAuditReader($this->em); + + $em = $this->getEntityManager(); + + $em->persist($dog); + $em->persist($cat); + $em->persist($foxy); + $em->persist($rabbit); + $em->persist($user); + $em->persist($article); + $em->flush(); + + $reader = $this->auditManager->createAuditReader($em); $changedEntities = $reader->findEntitiesChangedAtRevision(1); // duplicated entries means a bug with discriminators @@ -239,16 +247,18 @@ public function testFindEntitesChangedAtRevision(): void public function testNotVersionedRelationFind(): void { + $em = $this->getEntityManager(); + // Insert user without the manager to skip revision registering. - $this->em->getConnection()->insert( - $this->em->getClassMetadata(UserAudit::class)->getTableName(), + $em->getConnection()->insert( + $em->getClassMetadata(UserAudit::class)->getTableName(), [ 'id' => 1, 'name' => 'beberlei', ] ); - $userAudit = $this->em->getRepository(UserAudit::class)->find(1); + $userAudit = $em->getRepository(UserAudit::class)->find(1); static::assertNotNull($userAudit); $article = new ArticleAudit( @@ -258,10 +268,10 @@ public function testNotVersionedRelationFind(): void 'text' ); - $this->em->persist($article); - $this->em->flush(); + $em->persist($article); + $em->flush(); - $reader = $this->auditManager->createAuditReader($this->em); + $reader = $this->auditManager->createAuditReader($em); $articleAudit = $reader->find(ArticleAudit::class, 1, 1); static::assertNotNull($articleAudit); @@ -274,12 +284,14 @@ public function testNotVersionedReverseRelationFind(): void { $user = new UserAudit('beberlei'); - $this->em->persist($user); - $this->em->flush(); + $em = $this->getEntityManager(); + + $em->persist($user); + $em->flush(); // Insert user without the manager to skip revision registering. - $this->em->getConnection()->insert( - $this->em->getClassMetadata(ProfileAudit::class)->getTableName(), + $em->getConnection()->insert( + $em->getClassMetadata(ProfileAudit::class)->getTableName(), [ 'id' => 1, 'biography' => 'He is an amazing contributor!', @@ -287,7 +299,7 @@ public function testNotVersionedReverseRelationFind(): void ] ); - $reader = $this->auditManager->createAuditReader($this->em); + $reader = $this->auditManager->createAuditReader($em); $userAudit = $reader->find(UserAudit::class, 1, 1); static::assertNotNull($userAudit); @@ -304,19 +316,21 @@ public function testFindRevisions(): void $cat = new Cat('pusheen', '#b5a89f'); $dog = new Dog('doggy', 80); - $this->em->persist($dog); - $this->em->persist($cat); - $this->em->persist($user); - $this->em->persist($foxy); - $this->em->persist($rabbit); - $this->em->flush(); + $em = $this->getEntityManager(); + + $em->persist($dog); + $em->persist($cat); + $em->persist($user); + $em->persist($foxy); + $em->persist($rabbit); + $em->flush(); $foxy->setName('Foxy'); $dog->setName('doge'); $user->setName('beberlei2'); - $this->em->flush(); + $em->flush(); - $reader = $this->auditManager->createAuditReader($this->em); + $reader = $this->auditManager->createAuditReader($em); $userId = $user->getId(); static::assertNotNull($userId); @@ -353,13 +367,15 @@ public function testFindCurrentRevision(): void { $user = new UserAudit('Broncha'); - $this->em->persist($user); - $this->em->flush(); + $em = $this->getEntityManager(); + + $em->persist($user); + $em->flush(); $user->setName('Rajesh'); - $this->em->flush(); + $em->flush(); - $reader = $this->auditManager->createAuditReader($this->em); + $reader = $this->auditManager->createAuditReader($em); $userId = $user->getId(); static::assertNotNull($userId); @@ -368,7 +384,7 @@ public function testFindCurrentRevision(): void static::assertSame('2', (string) $revision); $user->setName('David'); - $this->em->flush(); + $em->flush(); $revision = $reader->getCurrentRevision(UserAudit::class, $userId); static::assertSame('3', (string) $revision); @@ -379,15 +395,17 @@ public function testGlobalIgnoreColumns(): void $user = new UserAudit('welante'); $article = new ArticleAudit('testcolumn', 'yadda!', $user, 'text'); - $this->em->persist($user); - $this->em->persist($article); - $this->em->flush(); + $em = $this->getEntityManager(); + + $em->persist($user); + $em->persist($article); + $em->flush(); $article->setText('testcolumn2'); - $this->em->persist($article); - $this->em->flush(); + $em->persist($article); + $em->flush(); - $reader = $this->auditManager->createAuditReader($this->em); + $reader = $this->auditManager->createAuditReader($em); $articleId = $article->getId(); static::assertNotNull($articleId); @@ -396,8 +414,8 @@ public function testGlobalIgnoreColumns(): void static::assertSame('2', (string) $revision); $article->setIgnoreme('textnew'); - $this->em->persist($article); - $this->em->flush(); + $em->persist($article); + $em->flush(); $revision = $reader->getCurrentRevision(ArticleAudit::class, $articleId); static::assertSame('2', (string) $revision); @@ -407,18 +425,20 @@ public function testDeleteUnInitProxy(): void { $user = new UserAudit('beberlei'); - $this->em->persist($user); - $this->em->flush(); + $em = $this->getEntityManager(); + + $em->persist($user); + $em->flush(); unset($user); - $this->em->clear(); + $em->clear(); - $user = $this->em->getReference(UserAudit::class, 1); + $user = $em->getReference(UserAudit::class, 1); static::assertNotNull($user); - $this->em->remove($user); - $this->em->flush(); + $em->remove($user); + $em->flush(); - $reader = $this->auditManager->createAuditReader($this->em); + $reader = $this->auditManager->createAuditReader($em); $changedEntities = $reader->findEntitiesChangedAtRevision(2); static::assertCount(1, $changedEntities); @@ -436,13 +456,16 @@ public function testUsernameResolvingIsDynamic(): void ); $user = new UserAudit('beberlei'); - $this->em->persist($user); - $this->em->flush(); + + $em = $this->getEntityManager(); + + $em->persist($user); + $em->flush(); $user->setName('b.eberlei'); - $this->em->flush(); + $em->flush(); - $reader = $this->auditManager->createAuditReader($this->em); + $reader = $this->auditManager->createAuditReader($em); $revisions = $reader->findRevisionHistory(); static::assertCount(2, $revisions); @@ -460,25 +483,27 @@ public function testUsernameResolvingIsDynamic(): void public function testRevisionForeignKeys(): void { - $isSqlitePlatform = $this->em->getConnection()->getDatabasePlatform() instanceof SqlitePlatform; + $isSqlitePlatform = $em->getConnection()->getDatabasePlatform() instanceof SqlitePlatform; $updateForeignKeysConfig = false; + $em = $this->getEntityManager(); + if ($isSqlitePlatform) { - $foreignKeysConfig = $this->em->getConnection()->executeQuery('PRAGMA foreign_keys;')->fetchOne(); + $foreignKeysConfig = $em->getConnection()->executeQuery('PRAGMA foreign_keys;')->fetchOne(); $updateForeignKeysConfig = '0' === $foreignKeysConfig || 0 === $foreignKeysConfig; if ($updateForeignKeysConfig) { // Enable the "foreign_keys" pragma. - $this->em->getConnection()->executeQuery('PRAGMA foreign_keys = ON;'); + $em->getConnection()->executeQuery('PRAGMA foreign_keys = ON;'); } } $user = new UserAudit('phansys'); - $this->em->persist($user); - $this->em->flush(); + $em->persist($user); + $em->flush(); - $reader = $this->auditManager->createAuditReader($this->em); + $reader = $this->auditManager->createAuditReader($em); $userId = $user->getId(); static::assertNotNull($userId); @@ -496,11 +521,11 @@ public function testRevisionForeignKeys(): void $this->expectExceptionMessageMatches('#SQLSTATE\[[\d]+\]: #'); try { - $this->em->getConnection()->delete($revisionsTableName, ['id' => $revision]); + $em->getConnection()->delete($revisionsTableName, ['id' => $revision]); } finally { if ($updateForeignKeysConfig) { // Restore the original value for the "foreign_keys" pragma. - $this->em->getConnection()->executeQuery('PRAGMA foreign_keys = OFF;'); + $em->getConnection()->executeQuery('PRAGMA foreign_keys = OFF;'); } } } From 130a43f3bf82f110b4dff865ab780acbeac2d7f8 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 22:49:35 +0100 Subject: [PATCH 32/58] Actualizar ClockTest.php --- tests/ClockTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/ClockTest.php b/tests/ClockTest.php index b03858ed..08441f41 100644 --- a/tests/ClockTest.php +++ b/tests/ClockTest.php @@ -28,10 +28,12 @@ final class ClockTest extends BaseTest public function testFixedClockIsUsed(): void { + $em = $this->getEntityManager(); + $user = new Issue318User(); $user->setAlias('alias'); - $this->em->persist($user); - $this->em->flush(); + $em->persist($user); + $em->flush(); $userId = $user->getId(); From c1d508dbcaa7239d9d3d1bd5df4faadd767f3435 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 22:52:02 +0100 Subject: [PATCH 33/58] Actualizar ClockTest.php --- tests/ClockTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ClockTest.php b/tests/ClockTest.php index 08441f41..f975537f 100644 --- a/tests/ClockTest.php +++ b/tests/ClockTest.php @@ -39,7 +39,7 @@ public function testFixedClockIsUsed(): void \assert(\is_int($userId)); - $reader = $this->auditManager->createAuditReader($this->em); + $reader = $this->getAuditManager()->createAuditReader($em); $revisions = $reader->findRevisions(Issue318User::class, $userId); From 04bf7b4a3dfe7e694b359e15267259e7b75ed7b1 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 22:53:57 +0100 Subject: [PATCH 34/58] Actualizar CoreTest.php --- tests/CoreTest.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/CoreTest.php b/tests/CoreTest.php index 2c1e4de7..ad306dc2 100644 --- a/tests/CoreTest.php +++ b/tests/CoreTest.php @@ -116,7 +116,7 @@ public function testFind(): void $em->persist($foxy); $em->flush(); - $reader = $this->auditManager->createAuditReader($em); + $reader = $this->getAuditManager()->createAuditReader($em); $userId = $user->getId(); static::assertNotNull($userId); @@ -156,7 +156,7 @@ public function testFind(): void public function testFindNoRevisionFound(): void { - $reader = $this->auditManager->createAuditReader($this->getEntityManager()); + $reader = $this->getAuditManager()->createAuditReader($this->getEntityManager()); $this->expectException(NoRevisionFoundException::class); $this->expectExceptionMessage(sprintf( @@ -169,7 +169,7 @@ public function testFindNoRevisionFound(): void public function testFindNotAudited(): void { - $reader = $this->auditManager->createAuditReader($this->getEntityManager()); + $reader = $this->getAuditManager()->createAuditReader($this->getEntityManager()); $this->expectException(NotAuditedException::class); $this->expectExceptionMessage('Class "stdClass" is not audited.'); @@ -181,7 +181,7 @@ public function testFindRevisionHistory(): void { $user = new UserAudit('beberlei'); - $this->getEntityManager(); + $em = $this->getEntityManager(); $em->persist($user); $em->flush(); @@ -191,7 +191,7 @@ public function testFindRevisionHistory(): void $em->persist($article); $em->flush(); - $reader = $this->auditManager->createAuditReader($em); + $reader = $this->getAuditManager()->createAuditReader($em); $revisions = $reader->findRevisionHistory(); static::assertCount(2, $revisions); @@ -225,7 +225,7 @@ public function testFindEntitesChangedAtRevision(): void $em->persist($article); $em->flush(); - $reader = $this->auditManager->createAuditReader($em); + $reader = $this->getAuditManager()->createAuditReader($em); $changedEntities = $reader->findEntitiesChangedAtRevision(1); // duplicated entries means a bug with discriminators @@ -271,7 +271,7 @@ public function testNotVersionedRelationFind(): void $em->persist($article); $em->flush(); - $reader = $this->auditManager->createAuditReader($em); + $reader = $this->getAuditManager()->createAuditReader($em); $articleAudit = $reader->find(ArticleAudit::class, 1, 1); static::assertNotNull($articleAudit); @@ -299,7 +299,7 @@ public function testNotVersionedReverseRelationFind(): void ] ); - $reader = $this->auditManager->createAuditReader($em); + $reader = $this->getAuditManager()->createAuditReader($em); $userAudit = $reader->find(UserAudit::class, 1, 1); static::assertNotNull($userAudit); @@ -330,7 +330,7 @@ public function testFindRevisions(): void $user->setName('beberlei2'); $em->flush(); - $reader = $this->auditManager->createAuditReader($em); + $reader = $this->getAuditManager()->createAuditReader($em); $userId = $user->getId(); static::assertNotNull($userId); @@ -375,7 +375,7 @@ public function testFindCurrentRevision(): void $user->setName('Rajesh'); $em->flush(); - $reader = $this->auditManager->createAuditReader($em); + $reader = $this->getAuditManager()->createAuditReader($em); $userId = $user->getId(); static::assertNotNull($userId); @@ -405,7 +405,7 @@ public function testGlobalIgnoreColumns(): void $em->persist($article); $em->flush(); - $reader = $this->auditManager->createAuditReader($em); + $reader = $this->getAuditManager()->createAuditReader($em); $articleId = $article->getId(); static::assertNotNull($articleId); @@ -438,7 +438,7 @@ public function testDeleteUnInitProxy(): void $em->remove($user); $em->flush(); - $reader = $this->auditManager->createAuditReader($em); + $reader = $this->getAuditManager()->createAuditReader($em); $changedEntities = $reader->findEntitiesChangedAtRevision(2); static::assertCount(1, $changedEntities); @@ -451,7 +451,7 @@ public function testDeleteUnInitProxy(): void public function testUsernameResolvingIsDynamic(): void { - $this->auditManager->getConfiguration()->setUsernameCallable( + $this->getAuditManager()->getConfiguration()->setUsernameCallable( static fn () => 'user: '.uniqid() ); @@ -465,7 +465,7 @@ public function testUsernameResolvingIsDynamic(): void $user->setName('b.eberlei'); $em->flush(); - $reader = $this->auditManager->createAuditReader($em); + $reader = $this->getAuditManager()->createAuditReader($em); $revisions = $reader->findRevisionHistory(); static::assertCount(2, $revisions); @@ -503,7 +503,7 @@ public function testRevisionForeignKeys(): void $em->persist($user); $em->flush(); - $reader = $this->auditManager->createAuditReader($em); + $reader = $this->getAuditManager()->createAuditReader($em); $userId = $user->getId(); static::assertNotNull($userId); @@ -515,7 +515,7 @@ public function testRevisionForeignKeys(): void $revision = $reader->getCurrentRevision(UserAudit::class, $userId); static::assertSame('1', (string) $revision); - $revisionsTableName = $this->auditManager->getConfiguration()->getRevisionTableName(); + $revisionsTableName = $this->getAuditManager()->getConfiguration()->getRevisionTableName(); $this->expectException(DriverException::class); $this->expectExceptionMessageMatches('#SQLSTATE\[[\d]+\]: #'); From 2eae445be8bf1f472507abcc51a102293ae09518 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 22:55:50 +0100 Subject: [PATCH 35/58] Actualizar CoreTest.php --- tests/CoreTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/CoreTest.php b/tests/CoreTest.php index ad306dc2..20625395 100644 --- a/tests/CoreTest.php +++ b/tests/CoreTest.php @@ -483,11 +483,11 @@ public function testUsernameResolvingIsDynamic(): void public function testRevisionForeignKeys(): void { + $em = $this->getEntityManager(); + $isSqlitePlatform = $em->getConnection()->getDatabasePlatform() instanceof SqlitePlatform; $updateForeignKeysConfig = false; - $em = $this->getEntityManager(); - if ($isSqlitePlatform) { $foreignKeysConfig = $em->getConnection()->executeQuery('PRAGMA foreign_keys;')->fetchOne(); $updateForeignKeysConfig = '0' === $foreignKeysConfig || 0 === $foreignKeysConfig; From 6fb0a05c381e7909c6c3da2c57f225f167d9c75f Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 22:58:57 +0100 Subject: [PATCH 36/58] Actualizar Issue111Test.php --- tests/Issue/Issue111Test.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/Issue/Issue111Test.php b/tests/Issue/Issue111Test.php index 6bdc59d2..7b7f752d 100644 --- a/tests/Issue/Issue111Test.php +++ b/tests/Issue/Issue111Test.php @@ -29,18 +29,20 @@ final class Issue111Test extends BaseTest public function testIssue111(): void { - $this->em->getEventManager()->addEventSubscriber(new SoftDeleteableListener()); + $em = $this->getEntityManager(); + + $em->getEventManager()->addEventSubscriber(new SoftDeleteableListener()); $e = new Issue111Entity(); $e->setStatus('test status'); - $this->em->persist($e); - $this->em->flush(); // #1 + $em->persist($e); + $em->flush(); // #1 - $this->em->remove($e); - $this->em->flush(); // #2 + $em->remove($e); + $em->flush(); // #2 - $reader = $this->auditManager->createAuditReader($this->em); + $reader = $this->getAuditManager()->createAuditReader($em); $ae = $reader->find(Issue111Entity::class, 1, 2); static::assertNotNull($ae); From 1d9b921e751aad11cfc271b2abb19302ffffb982 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 22:59:39 +0100 Subject: [PATCH 37/58] Actualizar Issue156Test.php --- tests/Issue/Issue156Test.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/Issue/Issue156Test.php b/tests/Issue/Issue156Test.php index 92ea44a0..62a04dde 100644 --- a/tests/Issue/Issue156Test.php +++ b/tests/Issue/Issue156Test.php @@ -40,14 +40,16 @@ public function testIssue156(): void $number->setNumber('0123567890'); $client->addTelephoneNumber($number); - $this->em->persist($client); - $this->em->persist($number); - $this->em->flush(); + $em = $this->getEntityManager(); + + $em->persist($client); + $em->persist($number); + $em->flush(); $numberId = $number->getId(); static::assertNotNull($numberId); - $auditReader = $this->auditManager->createAuditReader($this->em); + $auditReader = $this->getAuditManager()->createAuditReader($em); $auditReader->find(Issue156ContactTelephoneNumber::class, $numberId, 1); } } From 166234941ad193522c236e20ec29b14f20c34f49 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 23:00:33 +0100 Subject: [PATCH 38/58] Actualizar Issue196Test.php --- tests/Issue/Issue196Test.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/Issue/Issue196Test.php b/tests/Issue/Issue196Test.php index 623b2b93..352c6311 100644 --- a/tests/Issue/Issue196Test.php +++ b/tests/Issue/Issue196Test.php @@ -35,17 +35,20 @@ public function testIssue196(): void { $entity = new Issue196Entity(); $entity->setSqlConversionField('THIS SHOULD BE LOWER CASE'); - $this->em->persist($entity); - $this->em->flush(); - $this->em->clear(); + + $em = $this->getEntityManager(); + + $em->persist($entity); + $em->flush(); + $em->clear(); $entityId = $entity->getId(); static::assertNotNull($entityId); - $persistedEntity = $this->em->find(Issue196Entity::class, $entityId); + $persistedEntity = $em->find(Issue196Entity::class, $entityId); static::assertNotNull($persistedEntity); - $auditReader = $this->auditManager->createAuditReader($this->em); + $auditReader = $this->getAuditManager()->createAuditReader($em); $currentRevision = $auditReader->getCurrentRevision(Issue196Entity::class, $entityId); static::assertNotNull($currentRevision); $currentRevisionEntity = $auditReader->find(Issue196Entity::class, $entityId, $currentRevision); From de6c186c14e166304d252fcd939d26f0c14b562b Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 23:01:25 +0100 Subject: [PATCH 39/58] Actualizar Issue198Test.php --- tests/Issue/Issue198Test.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/Issue/Issue198Test.php b/tests/Issue/Issue198Test.php index caa0c846..1577318a 100644 --- a/tests/Issue/Issue198Test.php +++ b/tests/Issue/Issue198Test.php @@ -34,17 +34,19 @@ public function testIssue198(): void $owner = new Issue198Owner(); $car = new Issue198Car(); - $this->em->persist($owner); - $this->em->persist($car); - $this->em->flush(); + $em = $this->getEntityManager(); + + $em->persist($owner); + $em->persist($car); + $em->flush(); $owner->addCar($car); - $this->em->persist($owner); - $this->em->persist($car); - $this->em->flush(); + $em->persist($owner); + $em->persist($car); + $em->flush(); - $auditReader = $this->auditManager->createAuditReader($this->em); + $auditReader = $this->getAuditManager()->createAuditReader($em); $carId = $car->getId(); static::assertNotNull($carId); From 1feefc8db317dc7aa9c0dab92298952a4ae651de Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 23:02:31 +0100 Subject: [PATCH 40/58] Actualizar Issue308Test.php --- tests/Issue/Issue308Test.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/Issue/Issue308Test.php b/tests/Issue/Issue308Test.php index db4e9f66..355c7126 100644 --- a/tests/Issue/Issue308Test.php +++ b/tests/Issue/Issue308Test.php @@ -32,13 +32,16 @@ public function testIssue308(): void $user = new Issue308User(); $child1 = new Issue308User(); $user->addChild($child1); - $this->em->persist($child1); - $this->em->persist($user); - $this->em->flush(); + + $em = $this->getEntityManager(); + + $em->persist($child1); + $em->persist($user); + $em->flush(); static::assertInstanceOf(Collection::class, $user->getChildren()); - $auditReader = $this->auditManager->createAuditReader($this->em); + $auditReader = $this->getAuditManager()->createAuditReader($em); $auditReader->setLoadAuditedCollections(true); $userId = $user->getId(); From a6daad8cf3dcb36ed20702b08c9c0ffa96b9f991 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 23:03:52 +0100 Subject: [PATCH 41/58] Actualizar Issue318Test.php --- tests/Issue/Issue318Test.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/Issue/Issue318Test.php b/tests/Issue/Issue318Test.php index 6b6b6020..9a230432 100644 --- a/tests/Issue/Issue318Test.php +++ b/tests/Issue/Issue318Test.php @@ -30,9 +30,12 @@ public function testIssue318(): void { $user = new Issue318User(); $user->setAlias('alias'); - $this->em->persist($user); - $this->em->flush(); - $userMetadata = $this->em->getClassMetadata($user::class); + + $em = $this->getEntityManager(); + + $em->persist($user); + $em->flush(); + $userMetadata = $em->getClassMetadata($user::class); $classes = [$userMetadata]; $schema = $this->getSchemaTool()->getSchemaFromMetadata($classes); $schemaName = $schema->getName(); From 2decfadd1857a22c94449b3b7fdae52329dd7442 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 23:04:39 +0100 Subject: [PATCH 42/58] Actualizar Issue31Test.php --- tests/Issue/Issue31Test.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/Issue/Issue31Test.php b/tests/Issue/Issue31Test.php index 1c345d03..12891983 100644 --- a/tests/Issue/Issue31Test.php +++ b/tests/Issue/Issue31Test.php @@ -34,20 +34,22 @@ final class Issue31Test extends BaseTest */ public function testIssue31(): void { + $em = $this->getEntityManager(); + $reve = new Issue31Reve(); $reve->setTitre('reve'); - $this->em->persist($reve); - $this->em->flush(); + $em->persist($reve); + $em->flush(); $user = new Issue31User(); $user->setTitre('user'); $user->setReve($reve); - $this->em->persist($user); - $this->em->flush(); + $em->persist($user); + $em->flush(); - $this->em->remove($user); - $this->em->flush(); + $em->remove($user); + $em->flush(); } } From 95046ecef76e249a59e1899ca12b21372b05262d Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 23:06:17 +0100 Subject: [PATCH 43/58] Actualizar Issue87Test.php --- tests/Issue/Issue87Test.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/Issue/Issue87Test.php b/tests/Issue/Issue87Test.php index c82c74ad..570dff19 100644 --- a/tests/Issue/Issue87Test.php +++ b/tests/Issue/Issue87Test.php @@ -46,12 +46,14 @@ public function testIssue87(): void $comment->setProject($project); $comment->setText('text comment'); - $this->em->persist($org); - $this->em->persist($project); - $this->em->persist($comment); - $this->em->flush(); + $em = $this->getEntityManager(); - $auditReader = $this->auditManager->createAuditReader($this->em); + $em->persist($org); + $em->persist($project); + $em->persist($comment); + $em->flush(); + + $auditReader = $this->getAuditManager()->createAuditReader($em); $projectId = $project->getId(); static::assertNotNull($projectId); @@ -75,7 +77,7 @@ public function testIssue87(): void static::assertSame('test project', $commentProject->getTitle()); $project->setTitle('changed project title'); - $this->em->flush(); + $em->flush(); $auditedComment = $auditReader->find(Issue87ProjectComment::class, $commentId, 2); static::assertNotNull($auditedComment); From ed9fd885e97aa8700248771ccb6771de458de1d6 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 23:07:19 +0100 Subject: [PATCH 44/58] Actualizar Issue9Test.php --- tests/Issue/Issue9Test.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/Issue/Issue9Test.php b/tests/Issue/Issue9Test.php index d842c6ee..61f811b0 100644 --- a/tests/Issue/Issue9Test.php +++ b/tests/Issue/Issue9Test.php @@ -41,12 +41,14 @@ public function testIssue9(): void $address->setCustomer($customer); - $this->em->persist($customer); - $this->em->persist($address); + $em = $this->getEntityManager(); - $this->em->flush(); // #1 + $em->persist($customer); + $em->persist($address); - $reader = $this->auditManager->createAuditReader($this->em); + $em->flush(); // #1 + + $reader = $this->getAuditManager()->createAuditReader($em); $addressId = $address->getId(); static::assertNotNull($addressId); From 79d6c972c82f7d71b19570e257c2278ee9ef5fb3 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 23:15:06 +0100 Subject: [PATCH 45/58] Actualizar RelationTest.php --- tests/RelationTest.php | 265 ++++++++++++++++++++++------------------- 1 file changed, 143 insertions(+), 122 deletions(-) diff --git a/tests/RelationTest.php b/tests/RelationTest.php index c2bc7dc9..3e700424 100644 --- a/tests/RelationTest.php +++ b/tests/RelationTest.php @@ -100,29 +100,31 @@ public function testUndefinedIndexesInUOWForRelations(): void $owned2->setTitle('owned2'); $owned2->setOwner($owner); - $this->em->persist($owner); - $this->em->persist($owned1); - $this->em->persist($owned2); + $em = $this->getEntityManager(); - $this->em->flush(); + $em->persist($owner); + $em->persist($owned1); + $em->persist($owned2); + + $em->flush(); unset($owner, $owned1, $owned2); - $this->em->clear(); + $em->clear(); - $owner = $this->em->getReference(OwnerEntity::class, 1); + $owner = $em->getReference(OwnerEntity::class, 1); static::assertNotNull($owner); - $this->em->remove($owner); - $owned1 = $this->em->getReference(OwnedEntity1::class, 1); + $em->remove($owner); + $owned1 = $em->getReference(OwnedEntity1::class, 1); static::assertNotNull($owned1); - $this->em->remove($owned1); - $owned2 = $this->em->getReference(OwnedEntity2::class, 1); + $em->remove($owned1); + $owned2 = $em->getReference(OwnedEntity2::class, 1); static::assertNotNull($owned2); - $this->em->remove($owned2); + $em->remove($owned2); - $this->em->flush(); + $em->flush(); - $reader = $this->auditManager->createAuditReader($this->em); + $reader = $this->getAuditManager()->createAuditReader($em); $changedEntities = $reader->findEntitiesChangedAtRevision(2); static::assertIsArray($changedEntities); @@ -148,17 +150,18 @@ public function testUndefinedIndexesInUOWForRelations(): void public function testIssue92(): void { - $auditReader = $this->auditManager->createAuditReader($this->em); + $em = $this->getEntityManager(); + $auditReader = $this->getAuditManager()->createAuditReader($em); $owner1 = new OwnerEntity(); $owner1->setTitle('test'); $owner2 = new OwnerEntity(); $owner2->setTitle('test'); - $this->em->persist($owner1); - $this->em->persist($owner2); + $em->persist($owner1); + $em->persist($owner2); - $this->em->flush(); + $em->flush(); $owned1 = new OwnedEntity1(); $owned1->setOwner($owner1); @@ -172,15 +175,15 @@ public function testIssue92(): void $owned3->setOwner($owner2); $owned3->setTitle('test'); - $this->em->persist($owned1); - $this->em->persist($owned2); - $this->em->persist($owned3); + $em->persist($owned1); + $em->persist($owned2); + $em->persist($owned3); - $this->em->flush(); + $em->flush(); $owned2->setOwner($owner2); - $this->em->flush(); // 3 + $em->flush(); // 3 $owner1Id = $owner1->getId(); static::assertNotNull($owner1Id); @@ -192,42 +195,43 @@ public function testIssue92(): void public function testOneToOne(): void { - $auditReader = $this->auditManager->createAuditReader($this->em); + $em = $this->getEntityManager(); + $auditReader = $this->getAuditManager()->createAuditReader($em); $master = new OneToOneMasterEntity(); $master->setTitle('master#1'); - $this->em->persist($master); - $this->em->flush(); // #1 + $em->persist($master); + $em->flush(); // #1 $notAudited = new OneToOneNotAuditedEntity(); $notAudited->setTitle('notaudited'); - $this->em->persist($notAudited); + $em->persist($notAudited); $master->setNotAudited($notAudited); - $this->em->flush(); // #2 + $em->flush(); // #2 $audited = new OneToOneAuditedEntity(); $audited->setTitle('audited'); $master->setAudited($audited); - $this->em->persist($audited); + $em->persist($audited); - $this->em->flush(); // #3 + $em->flush(); // #3 $audited->setTitle('changed#4'); - $this->em->flush(); // #4 + $em->flush(); // #4 $master->setTitle('changed#5'); - $this->em->flush(); // #5 + $em->flush(); // #5 - $this->em->remove($audited); + $em->remove($audited); - $this->em->flush(); // #6 + $em->flush(); // #6 $masterId = $master->getId(); static::assertNotNull($masterId); @@ -308,7 +312,8 @@ public function testOneToOne(): void public function testManyToMany(): void { - $auditReader = $this->auditManager->createAuditReader($this->em); + $em = $this->getEntityManager(); + $auditReader = $this->getAuditManager()->createAuditReader($em); $owner = new OwnerEntity(); $owner->setTitle('owner#1'); @@ -325,12 +330,12 @@ public function testManyToMany(): void $owned4->setTitle('owned4'); $owned4->addOwner($owner); - $this->em->persist($owner); - $this->em->persist($owned31); - $this->em->persist($owned32); - $this->em->persist($owned4); + $em->persist($owner); + $em->persist($owned31); + $em->persist($owned32); + $em->persist($owned4); - $this->em->flush(); // #1 + $em->flush(); // #1 $ownerId = $owner->getId(); static::assertNotNull($ownerId); @@ -354,14 +359,15 @@ public function testManyToMany(): void */ public function testRelations(): void { - $auditReader = $this->auditManager->createAuditReader($this->em); + $em = $this->getEntityManager(); + $auditReader = $this->getAuditManager()->createAuditReader($em); // create owner $owner = new OwnerEntity(); $owner->setTitle('rev#1'); - $this->em->persist($owner); - $this->em->flush(); + $em->persist($owner); + $em->flush(); $ownerId = $owner->getId(); static::assertNotNull($ownerId); @@ -373,15 +379,15 @@ public function testRelations(): void $owned21->setTitle('owned21'); $owned21->setOwner($owner); - $this->em->persist($owned21); - $this->em->flush(); + $em->persist($owned21); + $em->flush(); // should not add a revision static::assertCount(1, $auditReader->findRevisions(OwnerEntity::class, $ownerId)); $owner->setTitle('changed#2'); - $this->em->flush(); + $em->flush(); // should add a revision static::assertCount(2, $auditReader->findRevisions(OwnerEntity::class, $ownerId)); @@ -390,9 +396,9 @@ public function testRelations(): void $owned11->setTitle('created#3'); $owned11->setOwner($owner); - $this->em->persist($owned11); + $em->persist($owned11); - $this->em->flush(); + $em->flush(); // should not add a revision for owner static::assertCount(2, $auditReader->findRevisions(OwnerEntity::class, $ownerId)); @@ -402,9 +408,9 @@ public function testRelations(): void static::assertCount(1, $auditReader->findRevisions(OwnedEntity1::class, $owned11Id)); // should not mess foreign keys - $rows = $this->em->getConnection()->fetchAllAssociative('SELECT strange_owned_id_name FROM OwnedEntity1'); + $rows = $em->getConnection()->fetchAllAssociative('SELECT strange_owned_id_name FROM OwnedEntity1'); static::assertSame($ownerId, (int) $rows[0]['strange_owned_id_name']); - $this->em->refresh($owner); + $em->refresh($owner); static::assertCount(1, $owner->getOwned1()); static::assertCount(1, $owner->getOwned2()); @@ -413,24 +419,24 @@ public function testRelations(): void $owned12->setTitle('created#4'); $owned12->setOwner($owner); - $this->em->persist($owned12); - $this->em->flush(); + $em->persist($owned12); + $em->flush(); // we have a forth revision where Owner with title changed#2 has one owned2 and two owned1 entities (created#3, created#4) $owner->setTitle('changed#5'); - $this->em->flush(); + $em->flush(); // we have a fifth revision where Owner with title changed#5 has one owned2 and two owned1 entities (created#3, created#4) $owner->setTitle('changed#6'); $owned12->setTitle('changed#6'); - $this->em->flush(); + $em->flush(); - $this->em->remove($owned11); + $em->remove($owned11); $owned12->setTitle('changed#7'); $owner->setTitle('changed#7'); - $this->em->flush(); + $em->flush(); // we have a seventh revision where Owner with title changed#7 has one owned2 and one owned1 entity (changed#7) $ownerId = $owner->getId(); @@ -559,7 +565,8 @@ public function testRelations(): void */ public function testRemoval(): void { - $auditReader = $this->auditManager->createAuditReader($this->em); + $em = $this->getEntityManager(); + $auditReader = $this->getAuditManager()->createAuditReader($em); $owner1 = new OwnerEntity(); $owner1->setTitle('owner1'); @@ -579,28 +586,28 @@ public function testRemoval(): void $owned3->setTitle('owned3'); $owned3->setOwner($owner1); - $this->em->persist($owner1); - $this->em->persist($owner2); - $this->em->persist($owned1); - $this->em->persist($owned2); - $this->em->persist($owned3); + $em->persist($owner1); + $em->persist($owner2); + $em->persist($owned1); + $em->persist($owned2); + $em->persist($owned3); - $this->em->flush(); // #1 + $em->flush(); // #1 $owned1->setOwner($owner2); - $this->em->flush(); // #2 + $em->flush(); // #2 - $this->em->remove($owned1); - $this->em->flush(); // #3 + $em->remove($owned1); + $em->flush(); // #3 $owned2->setTitle('updated owned2'); - $this->em->flush(); // #4 + $em->flush(); // #4 - $this->em->remove($owned2); - $this->em->flush(); // #5 + $em->remove($owned2); + $em->flush(); // #5 - $this->em->remove($owned3); - $this->em->flush(); // #6 + $em->remove($owned3); + $em->flush(); // #6 $owner1Id = $owner1->getId(); static::assertNotNull($owner1Id); @@ -635,7 +642,8 @@ public function testRemoval(): void */ public function testDetaching(): void { - $auditReader = $this->auditManager->createAuditReader($this->em); + $em = $this->getEntityManager(); + $auditReader = $this->getAuditManager()->createAuditReader($em); $owner = new OwnerEntity(); $owner->setTitle('created#1'); @@ -643,10 +651,10 @@ public function testDetaching(): void $owned = new OwnedEntity1(); $owned->setTitle('created#1'); - $this->em->persist($owner); - $this->em->persist($owned); + $em->persist($owner); + $em->persist($owned); - $this->em->flush(); // #1 + $em->flush(); // #1 $ownerId1 = $owner->getId(); static::assertNotNull($ownerId1); @@ -656,34 +664,34 @@ public function testDetaching(): void $owned->setTitle('associated#2'); $owned->setOwner($owner); - $this->em->flush(); // #2 + $em->flush(); // #2 $owned->setTitle('deassociated#3'); $owned->setOwner(null); - $this->em->flush(); // #3 + $em->flush(); // #3 $owned->setTitle('associated#4'); $owned->setOwner($owner); - $this->em->flush(); // #4 + $em->flush(); // #4 - $this->em->remove($owned); + $em->remove($owned); - $this->em->flush(); // #5 + $em->flush(); // #5 $owned = new OwnedEntity1(); $owned->setTitle('recreated#6'); $owned->setOwner($owner); - $this->em->persist($owned); - $this->em->flush(); // #6 + $em->persist($owned); + $em->flush(); // #6 $ownedId2 = $owned->getId(); static::assertNotNull($ownedId2); - $this->em->remove($owner); - $this->em->flush(); // #7 + $em->remove($owner); + $em->flush(); // #7 $auditedEntity = $auditReader->find(OwnerEntity::class, $ownerId1, 1); static::assertNotNull($auditedEntity); @@ -727,7 +735,8 @@ public function testDetaching(): void public function testOneXRelations(): void { - $auditReader = $this->auditManager->createAuditReader($this->em); + $em = $this->getEntityManager(); + $auditReader = $this->getAuditManager()->createAuditReader($em); $owner = new OwnerEntity(); $owner->setTitle('owner'); @@ -736,15 +745,15 @@ public function testOneXRelations(): void $owned->setTitle('owned'); $owned->setOwner($owner); - $this->em->persist($owner); - $this->em->persist($owned); + $em->persist($owner); + $em->persist($owned); - $this->em->flush(); + $em->flush(); // first revision done $owner->setTitle('changed#2'); $owned->setTitle('changed#2'); - $this->em->flush(); + $em->flush(); $ownerId = $owner->getId(); static::assertNotNull($ownerId); @@ -770,25 +779,27 @@ public function testOneXRelations(): void public function testOneToManyJoinedInheritance(): void { + $em = $this->getEntityManager(); + $food = new FoodCategory(); - $this->em->persist($food); + $em->persist($food); $parmesanCheese = new CheeseProduct('Parmesan'); - $this->em->persist($parmesanCheese); + $em->persist($parmesanCheese); $cheddarCheese = new CheeseProduct('Cheddar'); - $this->em->persist($cheddarCheese); + $em->persist($cheddarCheese); $vine = new WineProduct('Champagne'); - $this->em->persist($vine); + $em->persist($vine); $food->addProduct($parmesanCheese); $food->addProduct($cheddarCheese); $food->addProduct($vine); - $this->em->flush(); + $em->flush(); - $reader = $this->auditManager->createAuditReader($this->em); + $reader = $this->getAuditManager()->createAuditReader($em); $foodId = $food->getId(); static::assertNotNull($foodId); @@ -813,21 +824,23 @@ public function testOneToManyJoinedInheritance(): void public function testOneToManyWithIndexBy(): void { + $em = $this->getEntityManager(); + $page = new Page(); - $this->em->persist($page); + $em->persist($page); $gbLocalization = new PageLocalization('en-GB'); - $this->em->persist($gbLocalization); + $em->persist($gbLocalization); $usLocalization = new PageLocalization('en-US'); - $this->em->persist($usLocalization); + $em->persist($usLocalization); $page->addLocalization($gbLocalization); $page->addLocalization($usLocalization); - $this->em->flush(); + $em->flush(); - $reader = $this->auditManager->createAuditReader($this->em); + $reader = $this->getAuditManager()->createAuditReader($em); $pageId = $page->getId(); static::assertNotNull($pageId); @@ -851,28 +864,30 @@ public function testOneToManyWithIndexBy(): void */ public function testOneToManyCollectionDeletedElements(): void { + $em = $this->getEntityManager(); + $owner = new OwnerEntity(); - $this->em->persist($owner); + $em->persist($owner); $ownedOne = new OwnedEntity1(); $ownedOne->setTitle('Owned#1'); $ownedOne->setOwner($owner); - $this->em->persist($ownedOne); + $em->persist($ownedOne); $ownedTwo = new OwnedEntity1(); $ownedTwo->setTitle('Owned#2'); $ownedTwo->setOwner($owner); - $this->em->persist($ownedTwo); + $em->persist($ownedTwo); $ownedThree = new OwnedEntity1(); $ownedThree->setTitle('Owned#3'); $ownedThree->setOwner($owner); - $this->em->persist($ownedThree); + $em->persist($ownedThree); $ownedFour = new OwnedEntity1(); $ownedFour->setTitle('Owned#4'); $ownedFour->setOwner($owner); - $this->em->persist($ownedFour); + $em->persist($ownedFour); $owner->addOwned1($ownedOne); $owner->addOwned1($ownedTwo); @@ -880,18 +895,18 @@ public function testOneToManyCollectionDeletedElements(): void $owner->addOwned1($ownedFour); $owner->setTitle('Owner with four owned elements.'); - $this->em->flush(); // #1 + $em->flush(); // #1 $owner->setTitle('Owner with three owned elements.'); - $this->em->remove($ownedTwo); + $em->remove($ownedTwo); - $this->em->flush(); // #2 + $em->flush(); // #2 $owner->setTitle('Just another revision.'); - $this->em->flush(); // #3 + $em->flush(); // #3 - $reader = $this->auditManager->createAuditReader($this->em); + $reader = $this->getAuditManager()->createAuditReader($em); $ownerId = $owner->getId(); static::assertNotNull($ownerId); @@ -916,6 +931,8 @@ public function testOneToManyCollectionDeletedElements(): void public function testOneToOneEdgeCase(): void { + $em = $this->getEntityManager(); + $base = new RelationOneToOneEntity(); $referenced = new RelationFoobarEntity(); @@ -925,12 +942,12 @@ public function testOneToOneEdgeCase(): void $base->setReferencedEntity($referenced); $referenced->setOneToOne($base); - $this->em->persist($base); - $this->em->persist($referenced); + $em->persist($base); + $em->persist($referenced); - $this->em->flush(); + $em->flush(); - $reader = $this->auditManager->createAuditReader($this->em); + $reader = $this->getAuditManager()->createAuditReader($em); $baseId = $base->getId(); static::assertNotNull($baseId); @@ -952,17 +969,21 @@ public function testOneToOneEdgeCase(): void */ public function testJoinOnObject(): void { + $em = $this->getEntityManager(); + $page = new Page(); - $this->em->persist($page); - $this->em->flush(); + $em->persist($page); + $em->flush(); $pageAlias = new PageAlias($page, 'This is the alias'); - $this->em->persist($pageAlias); - $this->em->flush(); + $em->persist($pageAlias); + $em->flush(); } public function testOneToOneBidirectional(): void { + $em = $this->getEntityManager(); + $private1 = new DataPrivateEntity(); $private1->setName('private1'); @@ -984,12 +1005,12 @@ public function testOneToOneBidirectional(): void $container3->setData($legal2); $container3->setName('container3'); - $this->em->persist($container1); - $this->em->persist($container2); - $this->em->persist($container3); - $this->em->flush(); + $em->persist($container1); + $em->persist($container2); + $em->persist($container3); + $em->flush(); - $reader = $this->auditManager->createAuditReader($this->em); + $reader = $this->getAuditManager()->createAuditReader($em); $legal2Id = $legal2->getId(); static::assertNotNull($legal2Id); From e6b057ea9ba2a637fa2ec25971325e2e4921368e Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 23:17:50 +0100 Subject: [PATCH 46/58] Actualizar IssueConvertToPHPTest.php --- tests/Issue/IssueConvertToPHPTest.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/Issue/IssueConvertToPHPTest.php b/tests/Issue/IssueConvertToPHPTest.php index d63b904a..87ab8da4 100644 --- a/tests/Issue/IssueConvertToPHPTest.php +++ b/tests/Issue/IssueConvertToPHPTest.php @@ -35,17 +35,20 @@ public function testConvertToPHP(): void { $entity = new ConvertToPHPEntity(); $entity->setSqlConversionField('TEST CONVERT TO PHP'); - $this->em->persist($entity); - $this->em->flush(); - $this->em->clear(); + + $em = $this->getEntityManager(); + + $em->persist($entity); + $em->flush(); + $em->clear(); $entityId = $entity->getId(); static::assertNotNull($entityId); - $persistedEntity = $this->em->find(ConvertToPHPEntity::class, $entityId); + $persistedEntity = $em->find(ConvertToPHPEntity::class, $entityId); static::assertNotNull($persistedEntity); - $auditReader = $this->auditManager->createAuditReader($this->em); + $auditReader = $this->getAuditManager()->createAuditReader($em); $currentRevision = $auditReader->getCurrentRevision(ConvertToPHPEntity::class, $entityId); static::assertNotNull($currentRevision); $currentRevisionEntity = $auditReader->find(ConvertToPHPEntity::class, $entityId, $currentRevision); From 6a736dbcd572d171bd9c6e72ceaeca92d5d3ccea Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 23:18:51 +0100 Subject: [PATCH 47/58] Actualizar IssueDuplicateRevisionTest.php --- tests/Issue/IssueDuplicateRevisionTest.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/Issue/IssueDuplicateRevisionTest.php b/tests/Issue/IssueDuplicateRevisionTest.php index 97b463cf..251f10df 100644 --- a/tests/Issue/IssueDuplicateRevisionTest.php +++ b/tests/Issue/IssueDuplicateRevisionTest.php @@ -34,28 +34,30 @@ final class IssueDuplicateRevisionTest extends BaseTest public function testDuplicateRevisionKeyConstraintFailure(): void { + $em = $this->getEntityManager(); + $primaryOwner = new DuplicateRevisionFailureTestPrimaryOwner(); - $this->em->persist($primaryOwner); + $em->persist($primaryOwner); $secondaryOwner = new DuplicateRevisionFailureTestSecondaryOwner(); - $this->em->persist($secondaryOwner); + $em->persist($secondaryOwner); $primaryOwner->addSecondaryOwner($secondaryOwner); $element = new DuplicateRevisionFailureTestOwnedElement(); - $this->em->persist($element); + $em->persist($element); $primaryOwner->addElement($element); $secondaryOwner->addElement($element); - $this->em->flush(); + $em->flush(); - $this->em->getUnitOfWork()->clear(); + $em->getUnitOfWork()->clear(); - $primaryOwner = $this->em->find(DuplicateRevisionFailureTestPrimaryOwner::class, 1); + $primaryOwner = $em->find(DuplicateRevisionFailureTestPrimaryOwner::class, 1); static::assertNotNull($primaryOwner); - $this->em->remove($primaryOwner); - $this->em->flush(); + $em->remove($primaryOwner); + $em->flush(); } } From ffec6d174338c3d12b410dc6898df857180e9ea9 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 23:20:29 +0100 Subject: [PATCH 48/58] Actualizar IssueEntityWithEnumTest.php --- tests/Issue/IssueEntityWithEnumTest.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/tests/Issue/IssueEntityWithEnumTest.php b/tests/Issue/IssueEntityWithEnumTest.php index 97afba99..f9894169 100644 --- a/tests/Issue/IssueEntityWithEnumTest.php +++ b/tests/Issue/IssueEntityWithEnumTest.php @@ -34,22 +34,23 @@ public function testIssueEntityWithEnums(): void { $entity = new IssueEntityWithEnum(Status::Foo); - $this->em->persist($entity); - $this->em->flush(); + $em = $this->getEntityManager(); - $entityId = $entity->getId(); + $em->persist($entity); + $em->flush(); + $entityId = $entity->getId(); \assert(\is_int($entityId)); - $this->em->clear(); + $em->clear(); /** @var IssueEntityWithEnum $entity */ - $entity = $this->em->getRepository(IssueEntityWithEnum::class)->findOneBy(['id' => $entityId]); + $entity = $em->getRepository(IssueEntityWithEnum::class)->findOneBy(['id' => $entityId]); $entity->setStatus(Status::Qwe); - $this->em->flush(); + $em->flush(); - $reader = $this->auditManager->createAuditReader($this->em); + $reader = $this->getAuditManager()->createAuditReader($this->em); $auditEntity = $reader->find(IssueEntityWithEnum::class, $entityId, 1); static::assertInstanceOf(IssueEntityWithEnum::class, $auditEntity); @@ -59,13 +60,13 @@ public function testIssueEntityWithEnums(): void static::assertInstanceOf(IssueEntityWithEnum::class, $auditEntity); static::assertSame(Status::Qwe, $auditEntity->getStatus()); - $this->em->clear(); + $em->clear(); /** @var IssueEntityWithEnum $entity */ - $entity = $this->em->getRepository(IssueEntityWithEnum::class)->findOneBy(['id' => $entityId]); + $entity = $em->getRepository(IssueEntityWithEnum::class)->findOneBy(['id' => $entityId]); - $this->em->remove($entity); - $this->em->flush(); + $em->remove($entity); + $em->flush(); $auditEntity = $reader->find(IssueEntityWithEnum::class, $entityId, 3); static::assertInstanceOf(IssueEntityWithEnum::class, $auditEntity); From e308baf855b785a2c2ae4785f8fce67f503b8f53 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 23:21:14 +0100 Subject: [PATCH 49/58] Actualizar IssueEscapedColumnsTest.php --- tests/Issue/IssueEscapedColumnsTest.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/Issue/IssueEscapedColumnsTest.php b/tests/Issue/IssueEscapedColumnsTest.php index e50cd31d..4970eed3 100644 --- a/tests/Issue/IssueEscapedColumnsTest.php +++ b/tests/Issue/IssueEscapedColumnsTest.php @@ -31,10 +31,13 @@ public function testEscapedColumns(): void $e = new EscapedColumnsEntity(); $e->setLeft(1); $e->setLft(2); - $this->em->persist($e); - $this->em->flush(); - $reader = $this->auditManager->createAuditReader($this->em); + $em = $this->getEntityManager(); + + $em->persist($e); + $em->flush(); + + $reader = $this->getAuditManager()->createAuditReader($em); $eId = $e->getId(); static::assertNotNull($eId); From 132df691d076cc5aa2739339b381f56f5adb5295 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 23:22:46 +0100 Subject: [PATCH 50/58] Actualizar IssueSelfReferencingManyToManyEntityTest.php --- ...sueSelfReferencingManyToManyEntityTest.php | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/tests/Issue/IssueSelfReferencingManyToManyEntityTest.php b/tests/Issue/IssueSelfReferencingManyToManyEntityTest.php index 244602d6..6d268ca8 100644 --- a/tests/Issue/IssueSelfReferencingManyToManyEntityTest.php +++ b/tests/Issue/IssueSelfReferencingManyToManyEntityTest.php @@ -34,23 +34,25 @@ public function testSelfReferencingManyToManyAssociationWithClassTableInheritanc $entityTwo = new SelfReferencingManyToManyEntity('xyz'); $entity->addLinkedEntity($entityTwo); - $this->em->persist($entity); - $this->em->persist($entityTwo); - $this->em->flush(); + $em = $this->getEntityManager(); + + $em->persist($entity); + $em->persist($entityTwo); + $em->flush(); $entityId = $entity->getId(); \assert(\is_int($entityId)); - $this->em->clear(); + $em->clear(); /** @var SelfReferencingManyToManyEntity $entity */ - $entity = $this->em->getRepository(SelfReferencingManyToManyEntity::class)->find($entityId); + $entity = $em->getRepository(SelfReferencingManyToManyEntity::class)->find($entityId); $entity->setTitle('bar'); - $this->em->flush(); + $em->flush(); - $reader = $this->auditManager->createAuditReader($this->em); + $reader = $this->getAuditManager()->createAuditReader($em); $auditEntity = $reader->find(SelfReferencingManyToManyEntity::class, $entityId, 1); static::assertInstanceOf(SelfReferencingManyToManyEntity::class, $auditEntity); @@ -60,13 +62,13 @@ public function testSelfReferencingManyToManyAssociationWithClassTableInheritanc static::assertInstanceOf(SelfReferencingManyToManyEntity::class, $auditEntity); static::assertSame('bar', $auditEntity->getTitle()); - $this->em->clear(); + $em->clear(); /** @var SelfReferencingManyToManyEntity $entity */ - $entity = $this->em->getRepository(SelfReferencingManyToManyEntity::class)->find($entityId); + $entity = $em->getRepository(SelfReferencingManyToManyEntity::class)->find($entityId); - $this->em->remove($entity); - $this->em->flush(); + $em->remove($entity); + $em->flush(); $auditEntity = $reader->find(SelfReferencingManyToManyEntity::class, $entityId, 3); static::assertInstanceOf(SelfReferencingManyToManyEntity::class, $auditEntity); From 900f73993f74e14f50fbc91e2d5bad8aa6ee3555 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 23:24:39 +0100 Subject: [PATCH 51/58] Actualizar IssueUnidirectionalManyToManyEntityTest.php --- ...ssueUnidirectionalManyToManyEntityTest.php | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/tests/Issue/IssueUnidirectionalManyToManyEntityTest.php b/tests/Issue/IssueUnidirectionalManyToManyEntityTest.php index fd73c5a0..ef5ba662 100644 --- a/tests/Issue/IssueUnidirectionalManyToManyEntityTest.php +++ b/tests/Issue/IssueUnidirectionalManyToManyEntityTest.php @@ -35,9 +35,11 @@ public function testUnidirectionalManyToManyAssociationWorksWhenTheMainEntityIsT $entityTwo = new UnidirectionalManyToManyLinkedEntity('xyz'); $entity->addLinkedEntity($entityTwo); - $this->em->persist($entity); - $this->em->persist($entityTwo); - $this->em->flush(); + $em = $this->getEntityManager(); + + $em->persist($entity); + $em->persist($entityTwo); + $em->flush(); $entityOneId = $entity->getId(); $entityTwoId = $entityTwo->getId(); @@ -54,9 +56,11 @@ public function testUnidirectionalManyToManyAssociationWorksWhenTheLinkedEntityI $entityTwo = new UnidirectionalManyToManyLinkedEntity('xyz'); $entity->addLinkedEntity($entityTwo); - $this->em->persist($entityTwo); - $this->em->persist($entity); - $this->em->flush(); + $em = $this->getEntityManager(); + + $em->persist($entityTwo); + $em->persist($entity); + $em->flush(); $entityOneId = $entity->getId(); $entityTwoId = $entityTwo->getId(); @@ -69,18 +73,20 @@ public function testUnidirectionalManyToManyAssociationWorksWhenTheLinkedEntityI private function assertAuditRecordsWereCorrectlyRecorded(int $mainEntityId, int $linkedEntityId): void { - $this->em->clear(); + $em = $this->getEntityManager(); + + $em->clear(); /** @var UnidirectionalManyToManyEntity $entity */ - $entity = $this->em->getRepository(UnidirectionalManyToManyEntity::class)->find($mainEntityId); + $entity = $em->getRepository(UnidirectionalManyToManyEntity::class)->find($mainEntityId); /** @var UnidirectionalManyToManyLinkedEntity $entityTwo */ - $entityTwo = $this->em->getRepository(UnidirectionalManyToManyLinkedEntity::class)->find($linkedEntityId); + $entityTwo = $em->getRepository(UnidirectionalManyToManyLinkedEntity::class)->find($linkedEntityId); $entity->setTitle('bar'); $entityTwo->setName('zxy'); - $this->em->flush(); + $em->flush(); - $reader = $this->auditManager->createAuditReader($this->em); + $reader = $this->getAuditManager()->createAuditReader($em); $auditEntity = $reader->find(UnidirectionalManyToManyEntity::class, $mainEntityId, 1); static::assertInstanceOf(UnidirectionalManyToManyEntity::class, $auditEntity); @@ -96,13 +102,13 @@ private function assertAuditRecordsWereCorrectlyRecorded(int $mainEntityId, int static::assertInstanceOf(UnidirectionalManyToManyLinkedEntity::class, $auditEntity->getLinkedEntities()[0]); static::assertSame('zxy', $auditEntity->getLinkedEntities()[0]->getName()); - $this->em->clear(); + $em->clear(); /** @var UnidirectionalManyToManyEntity $entity */ - $entity = $this->em->getRepository(UnidirectionalManyToManyEntity::class)->find($mainEntityId); + $entity = $em->getRepository(UnidirectionalManyToManyEntity::class)->find($mainEntityId); - $this->em->remove($entity); - $this->em->flush(); + $em->remove($entity); + $em->flush(); $auditEntity = $reader->find(UnidirectionalManyToManyEntity::class, $mainEntityId, 3); static::assertInstanceOf(UnidirectionalManyToManyEntity::class, $auditEntity); From 89f2c34981dfefe16a6660adb35dd3a90a5093ac Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 23:26:57 +0100 Subject: [PATCH 52/58] Actualizar Issue308Test.php --- tests/Issue/Issue308Test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Issue/Issue308Test.php b/tests/Issue/Issue308Test.php index 355c7126..81f194a1 100644 --- a/tests/Issue/Issue308Test.php +++ b/tests/Issue/Issue308Test.php @@ -34,7 +34,7 @@ public function testIssue308(): void $user->addChild($child1); $em = $this->getEntityManager(); - + $em->persist($child1); $em->persist($user); $em->flush(); From 61d5d113f8d40a729755fa529cfa53f2cf3f364f Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 23:27:22 +0100 Subject: [PATCH 53/58] Actualizar IssueEntityWithEnumTest.php --- tests/Issue/IssueEntityWithEnumTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Issue/IssueEntityWithEnumTest.php b/tests/Issue/IssueEntityWithEnumTest.php index f9894169..b3918140 100644 --- a/tests/Issue/IssueEntityWithEnumTest.php +++ b/tests/Issue/IssueEntityWithEnumTest.php @@ -50,7 +50,7 @@ public function testIssueEntityWithEnums(): void $entity->setStatus(Status::Qwe); $em->flush(); - $reader = $this->getAuditManager()->createAuditReader($this->em); + $reader = $this->getAuditManager()->createAuditReader($em); $auditEntity = $reader->find(IssueEntityWithEnum::class, $entityId, 1); static::assertInstanceOf(IssueEntityWithEnum::class, $auditEntity); From 119d857e8e838b107d63cd4d1f8b91b24cbc746e Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 23:29:11 +0100 Subject: [PATCH 54/58] Actualizar ClockTest.php --- tests/ClockTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ClockTest.php b/tests/ClockTest.php index f975537f..8fb81d50 100644 --- a/tests/ClockTest.php +++ b/tests/ClockTest.php @@ -29,7 +29,7 @@ final class ClockTest extends BaseTest public function testFixedClockIsUsed(): void { $em = $this->getEntityManager(); - + $user = new Issue318User(); $user->setAlias('alias'); $em->persist($user); From ced2f3596e402e6442e9d9cbb2b39597614e6214 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 23:29:25 +0100 Subject: [PATCH 55/58] Actualizar Issue318Test.php --- tests/Issue/Issue318Test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Issue/Issue318Test.php b/tests/Issue/Issue318Test.php index 9a230432..b228a3d3 100644 --- a/tests/Issue/Issue318Test.php +++ b/tests/Issue/Issue318Test.php @@ -32,7 +32,7 @@ public function testIssue318(): void $user->setAlias('alias'); $em = $this->getEntityManager(); - + $em->persist($user); $em->flush(); $userMetadata = $em->getClassMetadata($user::class); From 7a4ea22f4f90852a96ca919b48f1ea7ca106f8c9 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 23:34:00 +0100 Subject: [PATCH 56/58] Actualizar CoreTest.php --- tests/CoreTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CoreTest.php b/tests/CoreTest.php index 20625395..2c0a886a 100644 --- a/tests/CoreTest.php +++ b/tests/CoreTest.php @@ -214,7 +214,7 @@ public function testFindEntitesChangedAtRevision(): void $rabbit = new Rabbit('rabbit', 'white'); $cat = new Cat('pusheen', '#b5a89f'); $dog = new Dog('doggy', 80); - + $em = $this->getEntityManager(); $em->persist($dog); From 77f98cdc7474c2bc930272ff3074e8c29f6b0214 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 23:40:00 +0100 Subject: [PATCH 57/58] Actualizar rector.php --- rector.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rector.php b/rector.php index 8bd34980..86170250 100644 --- a/rector.php +++ b/rector.php @@ -39,7 +39,9 @@ CountOnNullRector::class, ExceptionHandlerTypehintRector::class, UnionTypesRector::class => [ + __DIR__.'/src/AuditConfigurator.php', __DIR__.'/src/AuditReader.php', + __DIR__.'/src/Controller/AuditController.php', __DIR__.'/src/EventListener/LogRevisionsListener.php', __DIR__.'/src/Revision.php', ], From 29aaa0c33c62f02fea9aefd19ac068c551e489ed Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 23 Mar 2023 23:41:35 +0100 Subject: [PATCH 58/58] Update rector.php --- rector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rector.php b/rector.php index 86170250..a3b7a016 100644 --- a/rector.php +++ b/rector.php @@ -39,7 +39,7 @@ CountOnNullRector::class, ExceptionHandlerTypehintRector::class, UnionTypesRector::class => [ - __DIR__.'/src/AuditConfigurator.php', + __DIR__.'/src/AuditConfiguration.php', __DIR__.'/src/AuditReader.php', __DIR__.'/src/Controller/AuditController.php', __DIR__.'/src/EventListener/LogRevisionsListener.php',