/** * Test related methods */ public function testGetterSetter() { $this->assertEquals($this->version->getAuthor(), 'admin'); $this->assertEquals($this->version->getResourceId(), 1); $this->assertEquals($this->version->getVersion(), 2); $this->assertEquals($this->version->getSnapshot(), ['field' => 'value']); $this->assertEquals($this->version->getChangeset(), ['field' => 'value']); $this->assertEquals($this->version->getContext(), 'foo'); }
/** * Build a pending version * * @param Version $pending * @param Version|null $previousVersion * * @return Version */ public function buildPendingVersion(Version $pending, Version $previousVersion = null) { $versionNumber = $previousVersion ? $previousVersion->getVersion() + 1 : 1; $oldSnapshot = $previousVersion ? $previousVersion->getSnapshot() : []; $modification = $pending->getChangeset(); $snapshot = $modification + $oldSnapshot; $changeset = $this->buildChangeset($oldSnapshot, $snapshot); $pending->setVersion($versionNumber)->setSnapshot($snapshot)->setChangeset($changeset); return $pending; }
function it_normalize_versions_with_deleted_user($userManager, $translator, Version $version, \DateTime $versionTime) { $version->getId()->willReturn(12); $version->getResourceId()->willReturn(112); $version->getSnapshot()->willReturn('a nice snapshot'); $version->getChangeset()->willReturn('the changeset'); $version->getContext()->willReturn(['locale' => 'en_US', 'channel' => 'mobile']); $version->getVersion()->willReturn(12); $version->getLoggedAt()->willReturn($versionTime); $versionTime->format('Y-m-d H:i:s')->willReturn('1985-10-1 09:41:00'); $version->isPending()->willReturn(false); $version->getAuthor()->willReturn('steve'); $userManager->findUserByUsername('steve')->willReturn(null); $translator->trans('Removed user')->willReturn('Utilisateur supprimé'); $this->normalize($version, 'internal_api')->shouldReturn(['id' => 12, 'author' => 'steve - Utilisateur supprimé', 'resource_id' => '112', 'snapshot' => 'a nice snapshot', 'changeset' => 'the changeset', 'context' => ['locale' => 'en_US', 'channel' => 'mobile'], 'version' => 12, 'logged_at' => '1985-10-1 09:41:00', 'pending' => false]); }
/** * Compute version change set * * @param Version $version */ protected function computeChangeSet(Version $version) { $om = $this->versionManager->getObjectManager(); if ($version->getChangeset()) { $om->persist($version); $om->getUnitOfWork()->computeChangeSet($om->getClassMetadata(get_class($version)), $version); } else { $om->remove($version); } }
/** * {@inheritDoc} */ public function getChangeset() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getChangeset', array()); return parent::getChangeset(); }
/** * Compute version change set * * @param Version $version */ protected function computeChangeSet(Version $version) { $om = $this->container->get('pim_versioning.manager.version')->getObjectManager(); if ($version->getChangeset()) { $om->persist($version); $om->getUnitOfWork()->computeChangeSet($om->getClassMetadata(ClassUtils::getClass($version)), $version); } else { $om->remove($version); } }