Skip to content

Commit

Permalink
Add tests for services
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometee committed Sep 19, 2023
1 parent 3c5debb commit cf4e5c3
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 46 deletions.
31 changes: 22 additions & 9 deletions tests/Action/Api/Resource/AllActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@
use Stripe\Price;
use Stripe\Product;
use Stripe\Service\AbstractService;
use Stripe\Service\Checkout\SessionService;
use Stripe\Service\CouponService;
use Stripe\Service\CustomerService;
use Stripe\Service\InvoiceService;
use Stripe\Service\PlanService;
use Stripe\Service\PriceService;
use Stripe\Service\ProductService;
use Stripe\Service\TaxRateService;
use Stripe\StripeClient;
use Stripe\TaxRate;
use Tests\FluxSE\PayumStripe\Action\Api\ApiAwareActionTestTrait;
Expand Down Expand Up @@ -70,9 +78,11 @@ public function testShouldImplements(string $allActionClass): void
public function testShouldAllAPaymentIntent(
string $allActionClass,
string $allRequestClass,
string $allClass
string $allClass,
string $serviceClass
): void {
$apiMock = $this->createApiMock();
$stripeClient = $apiMock->getStripeClient();

/** @var AbstractAllAction $action */
$action = new $allActionClass();
Expand Down Expand Up @@ -115,6 +125,9 @@ public function testShouldAllAPaymentIntent(

$action->execute($request);
$this->assertContainsOnlyInstancesOf($allClass, $request->getApiResources());

$service = $action->getStripeService($stripeClient);
$this->assertInstanceOf($serviceClass, $service);
}

public function testShouldThrowExceptionIfApiResourceClassIsNotCreatable(): void
Expand Down Expand Up @@ -148,14 +161,14 @@ public function getStripeService(StripeClient $stripeClient): AbstractService
public function requestList(): array
{
return [
[AllCouponAction::class, AllCoupon::class, Coupon::class],
[AllCustomerAction::class, AllCustomer::class, Customer::class],
[AllInvoiceAction::class, AllInvoice::class, Invoice::class],
[AllPlanAction::class, AllPlan::class, Plan::class],
[AllPriceAction::class, AllPrice::class, Price::class],
[AllProductAction::class, AllProduct::class, Product::class],
[AllTaxRateAction::class, AllTaxRate::class, TaxRate::class],
[AllSessionAction::class, AllSession::class, Session::class],
[AllCouponAction::class, AllCoupon::class, Coupon::class, CouponService::class],
[AllCustomerAction::class, AllCustomer::class, Customer::class, CustomerService::class],
[AllInvoiceAction::class, AllInvoice::class, Invoice::class, InvoiceService::class],
[AllPlanAction::class, AllPlan::class, Plan::class, PlanService::class],
[AllPriceAction::class, AllPrice::class, Price::class, PriceService::class],
[AllProductAction::class, AllProduct::class, Product::class, ProductService::class],
[AllTaxRateAction::class, AllTaxRate::class, TaxRate::class, TaxRateService::class],
[AllSessionAction::class, AllSession::class, Session::class, SessionService::class],
];
}
}
43 changes: 30 additions & 13 deletions tests/Action/Api/Resource/CreateActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@
use Stripe\Product;
use Stripe\Refund;
use Stripe\Service\AbstractService;
use Stripe\Service\Checkout\SessionService;
use Stripe\Service\CouponService;
use Stripe\Service\CustomerService;
use Stripe\Service\PaymentIntentService;
use Stripe\Service\PaymentMethodService;
use Stripe\Service\PlanService;
use Stripe\Service\PriceService;
use Stripe\Service\ProductService;
use Stripe\Service\RefundService;
use Stripe\Service\SetupIntentService;
use Stripe\Service\SubscriptionService;
use Stripe\Service\TaxRateService;
use Stripe\SetupIntent;
use Stripe\StripeClient;
use Stripe\Subscription;
Expand Down Expand Up @@ -81,11 +93,13 @@ public function testShouldImplements(string $createActionClass): void
public function testShouldCreateAnApiRessource(
string $createActionClass,
string $createRequestClass,
string $createClass
string $createClass,
string $serviceClass
): void {
$model = [];

$apiMock = $this->createApiMock();
$stripeClient = $apiMock->getStripeClient();

/** @var AbstractCreateAction $action */
$action = new $createActionClass();
Expand Down Expand Up @@ -116,6 +130,9 @@ public function testShouldCreateAnApiRessource(

$action->execute($request);
$this->assertInstanceOf($createClass, $request->getApiResource());

$service = $action->getStripeService($stripeClient);
$this->assertInstanceOf($serviceClass, $service);
}

public function testShouldThrowExceptionIfApiResourceClassIsNotCreatable(): void
Expand Down Expand Up @@ -145,18 +162,18 @@ public function getStripeService(StripeClient $stripeClient): AbstractService
public function requestList(): array
{
return [
[CreateCouponAction::class, CreateCoupon::class, Coupon::class],
[CreateCustomerAction::class, CreateCustomer::class, Customer::class],
[CreateSessionAction::class, CreateSession::class, Session::class],
[CreatePaymentIntentAction::class, CreatePaymentIntent::class, PaymentIntent::class],
[CreatePaymentMethodAction::class, CreatePaymentMethod::class, PaymentMethod::class],
[CreatePlanAction::class, CreatePlan::class, Plan::class],
[CreatePriceAction::class, CreatePrice::class, Price::class],
[CreateProductAction::class, CreateProduct::class, Product::class],
[CreateRefundAction::class, CreateRefund::class, Refund::class],
[CreateSetupIntentAction::class, CreateSetupIntent::class, SetupIntent::class],
[CreateSubscriptionAction::class, CreateSubscription::class, Subscription::class],
[CreateTaxRateAction::class, CreateTaxRate::class, TaxRate::class],
[CreateCouponAction::class, CreateCoupon::class, Coupon::class, CouponService::class],
[CreateCustomerAction::class, CreateCustomer::class, Customer::class, CustomerService::class],
[CreateSessionAction::class, CreateSession::class, Session::class, SessionService::class],
[CreatePaymentIntentAction::class, CreatePaymentIntent::class, PaymentIntent::class, PaymentIntentService::class],
[CreatePaymentMethodAction::class, CreatePaymentMethod::class, PaymentMethod::class, PaymentMethodService::class],
[CreatePlanAction::class, CreatePlan::class, Plan::class, PlanService::class],
[CreatePriceAction::class, CreatePrice::class, Price::class, PriceService::class],
[CreateProductAction::class, CreateProduct::class, Product::class, ProductService::class],
[CreateRefundAction::class, CreateRefund::class, Refund::class, RefundService::class],
[CreateSetupIntentAction::class, CreateSetupIntent::class, SetupIntent::class, SetupIntentService::class],
[CreateSubscriptionAction::class, CreateSubscription::class, Subscription::class, SubscriptionService::class],
[CreateTaxRateAction::class, CreateTaxRate::class, TaxRate::class, TaxRateService::class],
];
}
}
16 changes: 12 additions & 4 deletions tests/Action/Api/Resource/DeleteActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
use Stripe\Plan;
use Stripe\Product;
use Stripe\Service\AbstractService;
use Stripe\Service\CouponService;
use Stripe\Service\PlanService;
use Stripe\Service\ProductService;
use Stripe\Stripe;
use Stripe\StripeClient;
use Tests\FluxSE\PayumStripe\Action\Api\ApiAwareActionTestTrait;
Expand Down Expand Up @@ -57,11 +60,13 @@ public function testShouldImplements(string $deleteActionClass): void
public function testShouldBeDeleted(
string $deleteActionClass,
string $deleteRequestClass,
string $deleteClass
string $deleteClass,
string $serviceClass
): void {
$id = 'pi_1';

$apiMock = $this->createApiMock();
$stripeClient = $apiMock->getStripeClient();

/** @var AbstractDeleteAction $action */
$action = new $deleteActionClass();
Expand Down Expand Up @@ -115,6 +120,9 @@ public function testShouldBeDeleted(

$action->execute($request);
$this->assertInstanceOf($deleteClass, $request->getApiResource());

$service = $action->getStripeService($stripeClient);
$this->assertInstanceOf($serviceClass, $service);
}

/**
Expand Down Expand Up @@ -155,9 +163,9 @@ public function faultList(): array
public function requestList(): array
{
return [
[DeleteCouponAction::class, DeleteCoupon::class, Coupon::class],
[DeletePlanAction::class, DeletePlan::class, Plan::class],
[DeleteProductAction::class, DeleteProduct::class, Product::class],
[DeleteCouponAction::class, DeleteCoupon::class, Coupon::class, CouponService::class],
[DeletePlanAction::class, DeletePlan::class, Plan::class, PlanService::class],
[DeleteProductAction::class, DeleteProduct::class, Product::class, ProductService::class],
];
}
}
43 changes: 30 additions & 13 deletions tests/Action/Api/Resource/RetrieveActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@
use Stripe\Price;
use Stripe\Product;
use Stripe\Service\AbstractService;
use Stripe\Service\ChargeService;
use Stripe\Service\Checkout\SessionService;
use Stripe\Service\CouponService;
use Stripe\Service\CustomerService;
use Stripe\Service\InvoiceService;
use Stripe\Service\PaymentIntentService;
use Stripe\Service\PaymentMethodService;
use Stripe\Service\PlanService;
use Stripe\Service\PriceService;
use Stripe\Service\ProductService;
use Stripe\Service\SetupIntentService;
use Stripe\Service\SubscriptionService;
use Stripe\SetupIntent;
use Stripe\StripeClient;
use Stripe\Subscription;
Expand Down Expand Up @@ -81,11 +93,13 @@ public function testShouldImplements(string $retrieveActionClass): void
public function testShouldBeRetrieved(
string $retrieveActionClass,
string $retrieveRequestClass,
string $retrieveClass
string $retrieveClass,
string $serviceClass
): void {
$id = 'pi_1';

$apiMock = $this->createApiMock();
$stripeClient = $apiMock->getStripeClient();

/** @var AbstractRetrieveAction $action */
$action = new $retrieveActionClass();
Expand Down Expand Up @@ -116,6 +130,9 @@ public function testShouldBeRetrieved(

$action->execute($request);
$this->assertInstanceOf($retrieveClass, $request->getApiResource());

$service = $action->getStripeService($stripeClient);
$this->assertInstanceOf($serviceClass, $service);
}

public function testShouldThrowExceptionIfApiResourceClassIsNotCreatable(): void
Expand Down Expand Up @@ -150,18 +167,18 @@ public function getStripeService(StripeClient $stripeClient): AbstractService
public function requestList(): array
{
return [
[RetrieveChargeAction::class, RetrieveCharge::class, Charge::class],
[RetrieveCouponAction::class, RetrieveCoupon::class, Coupon::class],
[RetrieveCustomerAction::class, RetrieveCustomer::class, Customer::class],
[RetrieveInvoiceAction::class, RetrieveInvoice::class, Invoice::class],
[RetrievePaymentIntentAction::class, RetrievePaymentIntent::class, PaymentIntent::class],
[RetrievePaymentMethodAction::class, RetrievePaymentMethod::class, PaymentMethod::class],
[RetrievePlanAction::class, RetrievePlan::class, Plan::class],
[RetrievePriceAction::class, RetrievePrice::class, Price::class],
[RetrieveProductAction::class, RetrieveProduct::class, Product::class],
[RetrieveSessionAction::class, RetrieveSession::class, Session::class],
[RetrieveSetupIntentAction::class, RetrieveSetupIntent::class, SetupIntent::class],
[RetrieveSubscriptionAction::class, RetrieveSubscription::class, Subscription::class],
[RetrieveChargeAction::class, RetrieveCharge::class, Charge::class, ChargeService::class],
[RetrieveCouponAction::class, RetrieveCoupon::class, Coupon::class, CouponService::class],
[RetrieveCustomerAction::class, RetrieveCustomer::class, Customer::class, CustomerService::class],
[RetrieveInvoiceAction::class, RetrieveInvoice::class, Invoice::class, InvoiceService::class],
[RetrievePaymentIntentAction::class, RetrievePaymentIntent::class, PaymentIntent::class, PaymentIntentService::class],
[RetrievePaymentMethodAction::class, RetrievePaymentMethod::class, PaymentMethod::class, PaymentMethodService::class],
[RetrievePlanAction::class, RetrievePlan::class, Plan::class, PlanService::class],
[RetrievePriceAction::class, RetrievePrice::class, Price::class, PriceService::class],
[RetrieveProductAction::class, RetrieveProduct::class, Product::class, ProductService::class],
[RetrieveSessionAction::class, RetrieveSession::class, Session::class, SessionService::class],
[RetrieveSetupIntentAction::class, RetrieveSetupIntent::class, SetupIntent::class, SetupIntentService::class],
[RetrieveSubscriptionAction::class, RetrieveSubscription::class, Subscription::class, SubscriptionService::class],
];
}
}
25 changes: 18 additions & 7 deletions tests/Action/Api/Resource/UpdateActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
use Stripe\Price;
use Stripe\Product;
use Stripe\Service\AbstractService;
use Stripe\Service\CouponService;
use Stripe\Service\PaymentIntentService;
use Stripe\Service\PlanService;
use Stripe\Service\PriceService;
use Stripe\Service\ProductService;
use Stripe\Service\SubscriptionService;
use Stripe\StripeClient;
use Stripe\Subscription;
use Tests\FluxSE\PayumStripe\Action\Api\ApiAwareActionTestTrait;
Expand Down Expand Up @@ -63,12 +69,14 @@ public function testShouldImplements(string $updateActionClass): void
public function testShouldUpdateAPaymentIntent(
string $updateActionClass,
string $updateRequestClass,
string $updateClass
string $updateClass,
string $serviceClass
): void {
$id = 'pi_1';
$parameters = [];

$apiMock = $this->createApiMock();
$stripeClient = $apiMock->getStripeClient();

/** @var AbstractUpdateAction $action */
$action = new $updateActionClass();
Expand Down Expand Up @@ -99,6 +107,9 @@ public function testShouldUpdateAPaymentIntent(

$action->execute($request);
$this->assertInstanceOf($updateClass, $request->getApiResource());

$service = $action->getStripeService($stripeClient);
$this->assertInstanceOf($serviceClass, $service);
}

public function testShouldThrowExceptionIfApiResourceClassIsNotCreatable(): void
Expand Down Expand Up @@ -134,12 +145,12 @@ public function getStripeService(StripeClient $stripeClient): AbstractService
public function requestList(): array
{
return [
[UpdateCouponAction::class, UpdateCoupon::class, Coupon::class],
[UpdatePaymentIntentAction::class, UpdatePaymentIntent::class, PaymentIntent::class],
[UpdatePlanAction::class, UpdatePlan::class, Plan::class],
[UpdatePriceAction::class, UpdatePrice::class, Price::class],
[UpdateProductAction::class, UpdateProduct::class, Product::class],
[UpdateSubscriptionAction::class, UpdateSubscription::class, Subscription::class],
[UpdateCouponAction::class, UpdateCoupon::class, Coupon::class, CouponService::class],
[UpdatePaymentIntentAction::class, UpdatePaymentIntent::class, PaymentIntent::class, PaymentIntentService::class],
[UpdatePlanAction::class, UpdatePlan::class, Plan::class, PlanService::class],
[UpdatePriceAction::class, UpdatePrice::class, Price::class, PriceService::class],
[UpdateProductAction::class, UpdateProduct::class, Product::class, ProductService::class],
[UpdateSubscriptionAction::class, UpdateSubscription::class, Subscription::class, SubscriptionService::class],
];
}
}

0 comments on commit cf4e5c3

Please sign in to comment.