/**
  * @When /^I delete the ("[^"]+" product)$/
  * @When /^I try to delete the ("([^"]+)" product)$/
  */
 public function iDeleteTheProduct(ProductInterface $product)
 {
     try {
         $this->sharedStorage->set('product_id', $product->getId());
         $this->productRepository->remove($product);
     } catch (DBALException $exception) {
         $this->sharedStorage->set('last_exception', $exception);
     }
 }
Exemplo n.º 2
0
 function it_throws_exception_while_trying_to_remove_a_coupon_and_actually_removing_it(SharedStorageInterface $sharedStorage, RepositoryInterface $couponRepository, CouponInterface $coupon)
 {
     $coupon->getId()->willReturn(5);
     $couponRepository->remove($coupon)->shouldBeCalled();
     $sharedStorage->set('last_exception', Argument::any())->shouldNotBeCalled();
     $this->shouldThrow(\Exception::class)->during('iTryToDeleteCoupon', [$coupon]);
 }
Exemplo n.º 3
0
 /**
  * @Given the store does not have any zones defined
  */
 public function theStoreDoesNotHaveAnyZonesDefined()
 {
     $zones = $this->zoneRepository->findAll();
     foreach ($zones as $zone) {
         $this->zoneRepository->remove($zone);
     }
 }
Exemplo n.º 4
0
 /**
  * @Given the locale :localeCode does not exist in the store
  */
 public function theStoreDoesNotHaveLocale($localeCode)
 {
     /** @var LocaleInterface $locale */
     $locale = $this->localeRepository->findOneBy(['code' => $localeCode]);
     if (null !== $locale) {
         $this->localeRepository->remove($locale);
     }
 }
Exemplo n.º 5
0
 /**
  * @param Request $request
  *
  * @return Response
  */
 public function deleteAction(Request $request)
 {
     $configuration = $this->requestConfigurationFactory->create($this->metadata, $request);
     $this->isGrantedOr403($configuration, ResourceActions::DELETE);
     $resource = $this->findOr404($configuration);
     $event = $this->eventDispatcher->dispatchPreEvent(ResourceActions::DELETE, $configuration, $resource);
     if ($event->isStopped() && !$configuration->isHtmlRequest()) {
         throw new HttpException($event->getErrorCode(), $event->getMessage());
     }
     if ($event->isStopped()) {
         $this->flashHelper->addFlashFromEvent($configuration, $event);
         return $this->redirectHandler->redirectToIndex($configuration, $resource);
     }
     $this->repository->remove($resource);
     $this->eventDispatcher->dispatchPostEvent(ResourceActions::DELETE, $configuration, $resource);
     if (!$configuration->isHtmlRequest()) {
         return $this->viewHandler->handle($configuration, View::create(null, 204));
     }
     $this->flashHelper->addSuccessFlash($configuration, ResourceActions::DELETE, $resource);
     return $this->redirectHandler->redirectToIndex($configuration, $resource);
 }
Exemplo n.º 6
0
 /**
  * @param Request $request
  *
  * @return Response
  */
 public function deleteAction(Request $request)
 {
     $configuration = $this->requestConfigurationFactory->create($this->metadata, $request);
     $this->isGrantedOr403($configuration, ResourceActions::DELETE);
     $resource = $this->findOr404($configuration);
     if ($configuration->isCsrfProtectionEnabled() && !$this->isCsrfTokenValid($resource->getId(), $request->get('_csrf_token'))) {
         throw new HttpException(Response::HTTP_FORBIDDEN, 'Invalid csrf token.');
     }
     $event = $this->eventDispatcher->dispatchPreEvent(ResourceActions::DELETE, $configuration, $resource);
     if ($event->isStopped() && !$configuration->isHtmlRequest()) {
         throw new HttpException($event->getErrorCode(), $event->getMessage());
     }
     if ($event->isStopped()) {
         $this->flashHelper->addFlashFromEvent($configuration, $event);
         return $this->redirectHandler->redirectToIndex($configuration, $resource);
     }
     $this->repository->remove($resource);
     $this->eventDispatcher->dispatchPostEvent(ResourceActions::DELETE, $configuration, $resource);
     if (!$configuration->isHtmlRequest()) {
         return $this->viewHandler->handle($configuration, View::create(null, Response::HTTP_NO_CONTENT));
     }
     $this->flashHelper->addSuccessFlash($configuration, ResourceActions::DELETE, $resource);
     return $this->redirectHandler->redirectToIndex($configuration, $resource);
 }
Exemplo n.º 7
0
 /**
  * @When /^I delete ("([^"]+)" coupon)$/
  */
 public function iDeleteCoupon(CouponInterface $coupon)
 {
     $this->sharedStorage->set('coupon', $coupon);
     $this->couponRepository->remove($coupon);
 }
Exemplo n.º 8
0
 /**
  * @Given the account of :email was deleted
  */
 public function accountWasDeleted($email)
 {
     $user = $this->userRepository->findOneByEmail($email);
     $this->sharedStorage->set('customer', $user->getCustomer());
     $this->userRepository->remove($user);
 }
Exemplo n.º 9
0
 function it_tries_to_delete_a_product_that_does_not_exist(SharedStorageInterface $sharedStorage, RepositoryInterface $productRepository, ProductInterface $product)
 {
     $product->getId()->willReturn(1);
     $productRepository->find(1)->willReturn(null);
     $sharedStorage->set('deleted_product', $product)->shouldBeCalled();
     $productRepository->remove($product)->willThrow(DBALException::class);
     $sharedStorage->set('last_exception', Argument::type(DBALException::class))->shouldBeCalled();
     $this->iDeleteTheProduct($product);
 }