Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final class CreateCartRequest
- {
- /** @var string|null */
- private $token;
- /** @var string */
- private $cartId;
- public function __construct(Request $request)
- {
- $this->token = $request->query->get('token');
- }
- public static function fromHttpRequest(Request $request): self
- {
- return new self($request);
- }
- public function getCommand(): CreateCart
- {
- return (new CreateCartFactory())->createFromDTO($this);
- }
- public function getToken(): ?string
- {
- return $this->token;
- }
- }
- //**************************************************************
- function it_creates_cart(
- ValidatorInterface $validator,
- ConstraintViolationListInterface $violationList,
- MessageBusInterface $bus,
- GenericSuccessViewFactoryInterface $genericSuccessViewFactory,
- ViewHandlerInterface $viewHandler
- ): void
- {
- $request = new Request([
- 'token' => 'token'
- ]);
- $createCartRequest = new CreateCartRequest($request);
- $validator->validate($createCartRequest)->willReturn($violationList);
- $envelope = new Envelope($createCartRequest->getCommand(), []);
- $bus->dispatch(Argument::any())->willReturn($envelope);
- $genericSuccessViewFactory->create(Argument::any())->willReturn(new GenericSuccessView());
- $viewHandler->handle(Argument::any(), Argument::any())->willReturn(new Response());
- $this->__invoke($request);
- }
- //**************************************************************
- final class CreateCartFactory implements CreateCartFactoryInterface
- {
- public function createFromDTO(CreateCartRequest $createCartRequest): CreateCart
- {
- $cartId = Uuid::uuid4()->toString();
- return new CreateCart($createCartRequest->getToken(), $cartId);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement