/**
  * @param RemoveEvent $event
  */
 public function addRemoveVersion(RemoveEvent $event)
 {
     $author = '';
     $subject = $event->getSubject();
     if (null !== ($token = $this->tokenStorage->getToken()) && $this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
         $author = $token->getUser()->getUsername();
     }
     $previousVersion = $this->versionRepository->getNewestLogEntry(ClassUtils::getClass($subject), $event->getSubjectId());
     $version = $this->versionFactory->create(ClassUtils::getClass($subject), $event->getSubjectId(), $author, 'Deleted');
     $version->setVersion(null !== $previousVersion ? $previousVersion->getVersion() + 1 : 1)->setSnapshot(null !== $previousVersion ? $previousVersion->getSnapshot() : [])->setChangeset([]);
     $options = $event->getArguments();
     $this->versionSaver->save($version, $options);
 }
 function it_creates_a_version_on_object_deletion($versionFactory, $versionRepository, $tokenStorage, $authorizationChecker, $versionSaver, Version $previousVersion, Version $removeVersion, TokenInterface $token, UserInterface $admin, VersionableInterface $price, RemoveEvent $event)
 {
     $tokenStorage->getToken()->willReturn($token);
     $token->getUser()->willReturn($admin);
     $admin->getUsername()->willReturn('admin');
     $authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')->willReturn(true);
     $versionRepository->getNewestLogEntry(Argument::any(), 12)->willReturn($previousVersion);
     $previousVersion->getVersion()->willReturn(11);
     $previousVersion->getSnapshot()->willReturn(['foo' => 'bar']);
     $versionFactory->create(Argument::Any(), 12, 'admin', 'Deleted')->willReturn($removeVersion);
     $removeVersion->setVersion(12)->willReturn($removeVersion);
     $removeVersion->setSnapshot(['foo' => 'bar'])->willReturn($removeVersion);
     $removeVersion->setChangeset([])->willReturn($removeVersion);
     $saveOptions = ['flush' => true];
     $versionSaver->save($removeVersion, $saveOptions)->shouldBeCalled();
     $event->getSubject()->willReturn($price);
     $event->getSubjectId()->willReturn(12);
     $event->getArguments()->willReturn($saveOptions);
     $this->addRemoveVersion($event);
 }