mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
[ApiBundle] Fix ViewEvent mocking in specs
This commit is contained in:
parent
d683ad6d78
commit
1033ef35e9
1 changed files with 25 additions and 20 deletions
|
|
@ -21,6 +21,7 @@ use Sylius\Component\Core\Model\ProductTranslationInterface;
|
|||
use Sylius\Component\Product\Generator\SlugGeneratorInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Event\ViewEvent;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
|
||||
final class ProductSlugEventSubscriberSpec extends ObjectBehavior
|
||||
{
|
||||
|
|
@ -33,11 +34,9 @@ final class ProductSlugEventSubscriberSpec extends ObjectBehavior
|
|||
SlugGeneratorInterface $slugGenerator,
|
||||
ProductInterface $product,
|
||||
ProductTranslationInterface $productTranslation,
|
||||
Request $request,
|
||||
ViewEvent $event
|
||||
HttpKernelInterface $kernel,
|
||||
Request $request
|
||||
): void {
|
||||
$event->getControllerResult()->willReturn($product);
|
||||
$event->getRequest()->willReturn($request);
|
||||
$request->getMethod()->willReturn(Request::METHOD_POST);
|
||||
|
||||
$product->getTranslations()->willReturn(new ArrayCollection([$productTranslation->getWrappedObject()]));
|
||||
|
|
@ -47,20 +46,22 @@ final class ProductSlugEventSubscriberSpec extends ObjectBehavior
|
|||
$slugGenerator->generate('Audi RS7')->willReturn('audi-rs7');
|
||||
|
||||
$productTranslation->setSlug('audi-rs7')->shouldBeCalled();
|
||||
$event->setControllerResult($product)->shouldBeCalled();
|
||||
|
||||
$this->generateSlug($event);
|
||||
$this->generateSlug(new ViewEvent(
|
||||
$kernel->getWrappedObject(),
|
||||
$request->getWrappedObject(),
|
||||
HttpKernelInterface::MASTER_REQUEST,
|
||||
$product->getWrappedObject()
|
||||
));
|
||||
}
|
||||
|
||||
function it_does_nothing_if_the_product_has_slug(
|
||||
SlugGeneratorInterface $slugGenerator,
|
||||
ProductInterface $product,
|
||||
ProductTranslationInterface $productTranslation,
|
||||
Request $request,
|
||||
ViewEvent $event
|
||||
HttpKernelInterface $kernel,
|
||||
Request $request
|
||||
): void {
|
||||
$event->getControllerResult()->willReturn($product);
|
||||
$event->getRequest()->willReturn($request);
|
||||
$request->getMethod()->willReturn(Request::METHOD_POST);
|
||||
|
||||
$product->getTranslations()->willReturn(new ArrayCollection([$productTranslation->getWrappedObject()]));
|
||||
|
|
@ -70,20 +71,21 @@ final class ProductSlugEventSubscriberSpec extends ObjectBehavior
|
|||
$slugGenerator->generate(Argument::any())->shouldNotBeCalled();
|
||||
$productTranslation->setSlug(Argument::any())->shouldNotBeCalled();
|
||||
|
||||
$event->setControllerResult($product)->shouldBeCalled();
|
||||
|
||||
$this->generateSlug($event);
|
||||
$this->generateSlug(new ViewEvent(
|
||||
$kernel->getWrappedObject(),
|
||||
$request->getWrappedObject(),
|
||||
HttpKernelInterface::MASTER_REQUEST,
|
||||
$product->getWrappedObject()
|
||||
));
|
||||
}
|
||||
|
||||
function it_does_nothing_if_the_product_has_no_name(
|
||||
SlugGeneratorInterface $slugGenerator,
|
||||
ProductInterface $product,
|
||||
ProductTranslationInterface $productTranslation,
|
||||
Request $request,
|
||||
ViewEvent $event
|
||||
HttpKernelInterface $kernel,
|
||||
Request $request
|
||||
): void {
|
||||
$event->getControllerResult()->willReturn($product);
|
||||
$event->getRequest()->willReturn($request);
|
||||
$request->getMethod()->willReturn(Request::METHOD_POST);
|
||||
|
||||
$product->getTranslations()->willReturn(new ArrayCollection([$productTranslation->getWrappedObject()]));
|
||||
|
|
@ -93,8 +95,11 @@ final class ProductSlugEventSubscriberSpec extends ObjectBehavior
|
|||
$slugGenerator->generate(Argument::any())->shouldNotBeCalled();
|
||||
$productTranslation->setSlug(Argument::any())->shouldNotBeCalled();
|
||||
|
||||
$event->setControllerResult($product)->shouldBeCalled();
|
||||
|
||||
$this->generateSlug($event);
|
||||
$this->generateSlug(new ViewEvent(
|
||||
$kernel->getWrappedObject(),
|
||||
$request->getWrappedObject(),
|
||||
HttpKernelInterface::MASTER_REQUEST,
|
||||
$product->getWrappedObject()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue