From b1bbad3b15b10a39320d849b13674a570aa4db77 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 26 May 2016 22:28:23 +0200 Subject: [PATCH] Unit of work changeset computation test --- .../UnitOfWorkComputeChangesBench.php | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 tests/Doctrine/Performance/ChangeSet/UnitOfWorkComputeChangesBench.php diff --git a/tests/Doctrine/Performance/ChangeSet/UnitOfWorkComputeChangesBench.php b/tests/Doctrine/Performance/ChangeSet/UnitOfWorkComputeChangesBench.php new file mode 100644 index 000000000..25cc2fffd --- /dev/null +++ b/tests/Doctrine/Performance/ChangeSet/UnitOfWorkComputeChangesBench.php @@ -0,0 +1,73 @@ +unitOfWork = EntityManagerFactory::getEntityManager([])->getUnitOfWork(); + + for ($i = 1; $i <= 100; ++$i) { + $user = new CmsUser; + $user->id = $i; + $user->status = 'user'; + $user->username = 'user' . $i; + $user->name = 'Mr.Smith-' . $i; + $this->users[] = $user; + + $this->unitOfWork->registerManaged( + $user, + [ + 'id' => $i, + ], + [ + 'id' => $user->id, + 'status' => $user->status, + 'username' => $user->username, + 'name' => $user->name, + 'address' => $user->address, + 'email' => $user->email, + ] + ); + } + + $this->unitOfWork->computeChangeSets(); + + if ($this->unitOfWork->getScheduledEntityUpdates()) { + throw new \LogicException('Unit of work should be clean at this stage'); + } + + foreach ($this->users AS $user) { + $user->status = 'other'; + $user->username .= '++'; + $user->name = str_replace('Mr.', 'Mrs.', $user->name); + } + } + + public function benchChangeSetComputation() + { + $this->unitOfWork->computeChangeSets(); + } +} +