/** * {@inheritdoc} */ public function getVersionsToPurgeCount(array $options) { $optionResolver = new OptionsResolver(); $this->configureOptions($optionResolver); $options = $optionResolver->resolve($options); $versionsCursor = $this->versionRepository->findPotentiallyPurgeableBy($options); return $versionsCursor->count(); }
function it_purges_the_versions_according_to_an_advisor_and_returns_the_number_of_purged_versions(VersionRepositoryInterface $versionRepository, BulkRemoverInterface $versionRemover, BulkObjectDetacherInterface $objectDetacher, VersionPurgerAdvisorInterface $advisor, VersionInterface $versionToBePurged, VersionInterface $versionNotSupported, VersionInterface $versionToNotPurge) { $versionToBePurged->getResourceName()->willReturn('products'); $versionToBePurged->getId()->willReturn(1); $versionNotSupported->getResourceName()->willReturn('products'); $versionNotSupported->getId()->willReturn(2); $versionToNotPurge->getResourceName()->willReturn('products'); $versionToNotPurge->getId()->willReturn(3); $versionRepository->findPotentiallyPurgeableBy(Argument::type('array'))->willReturn([$versionToBePurged, $versionNotSupported, $versionToNotPurge]); $advisor->supports($versionToBePurged)->shouldBeCalled()->willReturn(true); $advisor->isPurgeable($versionToBePurged, Argument::type('array'))->shouldBeCalled()->willReturn(true); $advisor->supports($versionNotSupported)->shouldBeCalled()->willReturn(false); $advisor->isPurgeable($versionNotSupported, Argument::type('array'))->shouldNotBeCalled(); $advisor->supports($versionToNotPurge)->shouldBeCalled()->willReturn(true); $advisor->isPurgeable($versionToNotPurge, Argument::type('array'))->shouldBeCalled()->willReturn(false); $this->addVersionPurgerAdvisor($advisor); $versionRemover->removeAll([$versionToBePurged, $versionNotSupported])->shouldBeCalled(); $objectDetacher->detachAll([$versionToBePurged, $versionNotSupported])->shouldBeCalled(); $objectDetacher->detach($versionToNotPurge)->shouldBeCalled(); $this->purge([])->shouldReturn(2); }