<?php use Codeception\Scenario; use CubicMushroom\Payments\Stripe\Command\Payment\TakePaymentCommand; use CubicMushroom\Payments\Stripe\Step\Integration\CommandValidationWizard; use Money\Currency; use Money\Money; use ValueObjects\Web\EmailAddress; /** @var Scenario $scenario */ $I = new CommandValidationWizard($scenario); $I->wantTo('check that a command with incorrect property types fails validation'); // Setup test subjects $amount = 699; $currency = 'GBP'; $cost = new Money($amount, new Currency($currency)); $token = 'iAmAToken'; $description = 'Instead of enameling slobbery rum with tuna, use six teaspoons whipped cream and one package oregano ' . 'casserole.'; $userEmail = new EmailAddress('*****@*****.**'); $command = TakePaymentCommand::create($cost, $token, $description, $userEmail); $reflectionObject = new \ReflectionObject($command); $costProperty = $reflectionObject->getProperty('cost'); $costProperty->setAccessible(true); $costProperty->setValue($command, $amount); $emailProperty = $reflectionObject->getProperty('userEmail'); $emailProperty->setAccessible(true); $emailProperty->setValue($command, (string) $userEmail); // Perform test $I->validateCommand($command); $I->expectTheFollowingValidationErrors(['cost' => ['Please provide the cost details'], 'userEmail' => ['Please provide the user\'s email address']]);
/** * @param TakePaymentCommand $command * * @return Payment */ protected function convertCommandToPayment(TakePaymentCommand $command) { $payment = Payment::createUnpaid($command->getCost(), $command->getToken(), $command->getDescription(), $command->getUserEmail(), $command->getMetaData()); return $payment; }
/** * @uses TakePaymentCommandHandler::__construct() */ function let(ValidatorInterface $validator, EmitterInterface $emitter, TakePaymentCommand $command, Gateway $gateway, PurchaseRequest $purchaseRequest, Response $response, PaymentRepositoryInterface $repository) { // Command /** @noinspection PhpUndefinedMethodInspection */ $command->getCost()->willReturn($this->cost); /** @noinspection PhpUndefinedMethodInspection */ $command->getToken()->willReturn(self::TOKEN); /** @noinspection PhpUndefinedMethodInspection */ $command->getDescription()->willReturn(self::DESCRIPTION); /** @noinspection PhpUndefinedMethodInspection */ $command->getUserEmail()->willReturn($this->userEmail); /** @noinspection PhpUndefinedMethodInspection */ $command->getMetaData()->willReturn($this->metadata); // Gateway request/response /** @noinspection PhpUndefinedMethodInspection */ $gateway->purchase(Argument::any())->willReturn($purchaseRequest); /** @noinspection PhpUndefinedMethodInspection */ $purchaseRequest->send()->willReturn($response); /** @noinspection PhpUndefinedMethodInspection */ $response->isSuccessful()->willReturn(true); /** @noinspection PhpUndefinedMethodInspection */ $response->getTransactionReference()->willReturn(self::STRIPE_PAYMENT_ID); /** @see TakePaymentCommandHandler::create() */ /** @noinspection PhpMethodParametersCountMismatchInspection */ $this->beConstructedThrough('create', [$validator, $emitter, $gateway, $repository]); }