function let(UnitOfWork $uow, EntityManagerInterface $em, LifecycleEventArgs $parent, $entity, DoctrineEvent $other) { $parent->getEntityManager()->willReturn($em); $em->getUnitOfWork()->willReturn($uow); $uow->getEntityChangeSet($entity)->willReturn(['field1' => ['old', 'new'], 'fiels3' => [1, 2]]); $other->getChangeSet()->willReturn(['field2' => ['e1', 'e2'], 'field1' => ['new', 'newest']]); $other->getSubject()->willReturn($entity); $this->beConstructedWith($entity, $parent); }
/** * Merge changeset of the given event into the current one. * * @param DoctrineEvent $event */ public function merge(DoctrineEvent $event) { if ($this->subject !== $event->getSubject()) { throw new \Exception('Can\'t merge event from two differents instances.'); } $existing = $this->registerChangeSet(); $other = $event->getChangeSet(); foreach ($other as $key => $values) { if (false === array_key_exists($key, $existing)) { $existing[$key] = $values; continue; } if (end($existing[$key]) === current($values)) { array_shift($values); } $existing[$key] = array_merge($existing[$key], $values); } ksort($existing); $this->changeSet = $existing; }