Skip to content

Commit

Permalink
Extract parmeter and remove image paths from service memory
Browse files Browse the repository at this point in the history
  • Loading branch information
Zales0123 committed Nov 12, 2018
1 parent 327ceb5 commit 8852676
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

<service id="sylius.behat.checker.image_existence" class="Sylius\Behat\Service\Checker\ImageExistenceChecker">
<argument type="service" id="__symfony__.sylius.liip.filter_service" />
<argument type="string">%__symfony__.kernel.project_dir%/web/</argument>
<argument type="string">%__symfony__.sylius_core.public_dir%</argument>
</service>

<service id="sylius.behat.paypal_api_mocker" class="Sylius\Behat\Service\Mocker\PaypalApiMocker" public="false">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ public function onFlush(OnFlushEventArgs $event): void

public function postFlush(PostFlushEventArgs $event): void
{
foreach ($this->imagesToDelete as $imagePath) {
foreach ($this->imagesToDelete as $key => $imagePath) {
$this->imageUploader->remove($imagePath);
$this->cacheManager->remove($imagePath, array_keys($this->filterManager->getFilterConfiguration()->all()));
unset($this->imagesToDelete[$key]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ parameters:
sylius.cache:
type: file_system
sylius.uploader.filesystem: sylius_image
sylius_core.public_dir: "%kernel.project_dir%/web"
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,35 @@ function it_removes_saved_images_paths(

$this->postFlush($postFlushEvent);
}

function it_removes_saved_images_paths_from_both_filesystem_and_service_property(
ImageUploaderInterface $imageUploader,
CacheManager $cacheManager,
FilterManager $filterManager,
OnFlushEventArgs $onFlushEvent,
PostFlushEventArgs $postFlushEvent,
EntityManagerInterface $entityManager,
UnitOfWork $unitOfWork,
ImageInterface $image,
ProductInterface $product,
FilterConfiguration $filterConfiguration
): void {
$onFlushEvent->getEntityManager()->willReturn($entityManager);
$entityManager->getUnitOfWork()->willReturn($unitOfWork);
$unitOfWork->getScheduledEntityDeletions()->willReturn([$image, $product]);

$image->getPath()->willReturn('image/path');

$this->onFlush($onFlushEvent);

$imageUploader->remove('image/path')->shouldBeCalledOnce();

$filterManager->getFilterConfiguration()->willReturn($filterConfiguration);
$filterConfiguration->all()->willReturn(['test' => 'Test']);

$cacheManager->remove('image/path', ['test'])->shouldBeCalledOnce();

$this->postFlush($postFlushEvent);
$this->postFlush($postFlushEvent);
}
}

0 comments on commit 8852676

Please sign in to comment.