From e83c2086c004357184456449ed2b534454fbba45 Mon Sep 17 00:00:00 2001 From: joeydehaas Date: Wed, 31 Jul 2024 13:16:37 +0200 Subject: [PATCH 1/3] clean-up: cleanup file names --- .../{DeleteRuleTest.php => DestroyRuleTest.php} | 10 +++++----- Tests/Feature/Rule/IndexRulesTest.php | 10 +++++----- ...oyMockClient.php => DestroyRuleMockClient.php} | 2 +- ...dexMockClient.php => IndexRulesMockClient.php} | 9 +++------ ...eShowMockClient.php => ShowRuleMockClient.php} | 8 +++----- ...toreMockClient.php => StoreRuleMockClient.php} | 2 +- Tests/Feature/Rule/Mock/UpdateRuleMockClient.php | 2 +- Tests/Feature/Rule/ShowRuleTest.php | 8 ++++---- Tests/Feature/Rule/StoreRuleTest.php | 15 ++++++--------- .../{RuleUpdateTest.php => UpdateRuleTest.php} | 4 +--- src/Filters/RuleFilter.php | 2 +- 11 files changed, 31 insertions(+), 41 deletions(-) rename Tests/Feature/Rule/{DeleteRuleTest.php => DestroyRuleTest.php} (80%) rename Tests/Feature/Rule/Mock/{RuleDestroyMockClient.php => DestroyRuleMockClient.php} (94%) rename Tests/Feature/Rule/Mock/{RuleIndexMockClient.php => IndexRulesMockClient.php} (61%) rename Tests/Feature/Rule/Mock/{RuleShowMockClient.php => ShowRuleMockClient.php} (80%) rename Tests/Feature/Rule/Mock/{RuleStoreMockClient.php => StoreRuleMockClient.php} (91%) rename Tests/Feature/Rule/{RuleUpdateTest.php => UpdateRuleTest.php} (88%) diff --git a/Tests/Feature/Rule/DeleteRuleTest.php b/Tests/Feature/Rule/DestroyRuleTest.php similarity index 80% rename from Tests/Feature/Rule/DeleteRuleTest.php rename to Tests/Feature/Rule/DestroyRuleTest.php index 1ca5320..91f2707 100644 --- a/Tests/Feature/Rule/DeleteRuleTest.php +++ b/Tests/Feature/Rule/DestroyRuleTest.php @@ -9,14 +9,14 @@ use PlugAndPay\Sdk\Exception\NotFoundException; use PlugAndPay\Sdk\Exception\UnauthenticatedException; use PlugAndPay\Sdk\Service\RuleService; -use PlugAndPay\Sdk\Tests\Feature\Rule\Mock\RuleDestroyMockClient; +use PlugAndPay\Sdk\Tests\Feature\Rule\Mock\DestroyRuleMockClient; -class DeleteRuleTest extends TestCase +class DestroyRuleTest extends TestCase { /** @test */ public function delete_rule_not_fount_test(): void { - $client = new RuleDestroyMockClient(Response::HTTP_NOT_FOUND); + $client = new DestroyRuleMockClient(Response::HTTP_NOT_FOUND); $service = new RuleService($client); $exception = null; @@ -31,7 +31,7 @@ public function delete_rule_not_fount_test(): void /** @test */ public function delete_rule_unauthenticated(): void { - $client = new RuleDestroyMockClient(Response::HTTP_UNAUTHORIZED, []); + $client = new DestroyRuleMockClient(Response::HTTP_UNAUTHORIZED, []); $service = new RuleService($client); $exception = null; @@ -46,7 +46,7 @@ public function delete_rule_unauthenticated(): void /** @test */ public function delete_existing_product(): void { - $client = new RuleDestroyMockClient(Response::HTTP_NO_CONTENT, []); + $client = new DestroyRuleMockClient(Response::HTTP_NO_CONTENT, []); $service = new RuleService($client); $service->delete(1); diff --git a/Tests/Feature/Rule/IndexRulesTest.php b/Tests/Feature/Rule/IndexRulesTest.php index dc2c834..d7001ba 100644 --- a/Tests/Feature/Rule/IndexRulesTest.php +++ b/Tests/Feature/Rule/IndexRulesTest.php @@ -11,7 +11,7 @@ use PlugAndPay\Sdk\Filters\RuleFilter; use PlugAndPay\Sdk\Service\RuleService; use PlugAndPay\Sdk\Tests\Feature\ClientMock; -use PlugAndPay\Sdk\Tests\Feature\Rule\Mock\RuleIndexMockClient; +use PlugAndPay\Sdk\Tests\Feature\Rule\Mock\IndexRulesMockClient; class IndexRulesTest extends TestCase { @@ -33,7 +33,7 @@ public function index_unauthorized_rules(): void /** @test */ public function index_rules(): void { - $client = new RuleIndexMockClient(); + $client = new IndexRulesMockClient(); $service = new RuleService($client); $rules = $service->get(); @@ -41,9 +41,9 @@ public function index_rules(): void static::assertSame(1, $rules[0]->id()); static::assertSame('call_webhook', $rules[0]->actionType()); static::assertSame(['hook_url' => 'https://example.com/webhook'], $rules[0]->actionData()); - static::assertSame('order_created', $rules[0]->triggerType()); + static::assertSame('order_paid', $rules[0]->triggerType()); static::assertSame(['is_first' => true, 'product_id' => [1]], $rules[0]->conditionData()); - static::assertSame('Plug&Pay webhook rule', $rules[0]->name()); + static::assertSame('Plug&Pay Example Rule', $rules[0]->name()); static::assertFalse($rules[0]->readonly()); static::assertSame('webhook', $rules[0]->driver()); } @@ -54,7 +54,7 @@ public function index_rules(): void */ public function index_rules_with_filter(string $method, mixed $value, string $queryKey, string $queryValue): void { - $client = new RuleIndexMockClient(); + $client = new IndexRulesMockClient(); $service = new RuleService($client); $filter = (new RuleFilter())->$method($value); diff --git a/Tests/Feature/Rule/Mock/RuleDestroyMockClient.php b/Tests/Feature/Rule/Mock/DestroyRuleMockClient.php similarity index 94% rename from Tests/Feature/Rule/Mock/RuleDestroyMockClient.php rename to Tests/Feature/Rule/Mock/DestroyRuleMockClient.php index 397de7e..5fa6cf7 100644 --- a/Tests/Feature/Rule/Mock/RuleDestroyMockClient.php +++ b/Tests/Feature/Rule/Mock/DestroyRuleMockClient.php @@ -11,7 +11,7 @@ use PlugAndPay\Sdk\Exception\ValidationException; use PlugAndPay\Sdk\Tests\Feature\ClientMock; -class RuleDestroyMockClient extends ClientMock +class DestroyRuleMockClient extends ClientMock { private string $path; diff --git a/Tests/Feature/Rule/Mock/RuleIndexMockClient.php b/Tests/Feature/Rule/Mock/IndexRulesMockClient.php similarity index 61% rename from Tests/Feature/Rule/Mock/RuleIndexMockClient.php rename to Tests/Feature/Rule/Mock/IndexRulesMockClient.php index 6337810..316e08b 100644 --- a/Tests/Feature/Rule/Mock/RuleIndexMockClient.php +++ b/Tests/Feature/Rule/Mock/IndexRulesMockClient.php @@ -7,16 +7,13 @@ use PlugAndPay\Sdk\Entity\Response; use PlugAndPay\Sdk\Tests\Feature\ClientMock; -class RuleIndexMockClient extends ClientMock +class IndexRulesMockClient extends ClientMock { private string $path; - /** @noinspection PhpMissingParentConstructorInspection */ - public function __construct(array $data = [[]]) + public function __construct(array $data = [ShowRuleMockClient::BASIC_RULE]) { - foreach ($data as $ruleData) { - $this->responseBody[] = $ruleData + RuleShowMockClient::BASIC_RULE; - } + parent::__construct(data: $data); } public function get(string $path): Response diff --git a/Tests/Feature/Rule/Mock/RuleShowMockClient.php b/Tests/Feature/Rule/Mock/ShowRuleMockClient.php similarity index 80% rename from Tests/Feature/Rule/Mock/RuleShowMockClient.php rename to Tests/Feature/Rule/Mock/ShowRuleMockClient.php index e430003..486e7df 100644 --- a/Tests/Feature/Rule/Mock/RuleShowMockClient.php +++ b/Tests/Feature/Rule/Mock/ShowRuleMockClient.php @@ -1,14 +1,12 @@ 1, @@ -16,9 +14,9 @@ class RuleShowMockClient extends ClientMock 'action_data' => [ 'hook_url' => 'https://example.com/webhook', ], - 'trigger_type' => 'order_created', + 'trigger_type' => 'order_paid', 'condition_data' => ['is_first' => true, 'product_id' => [1]], - 'name' => 'Plug&Pay webhook rule', + 'name' => 'Plug&Pay Example Rule', 'readonly' => false, 'created_at' => null, 'updated_at' => null, diff --git a/Tests/Feature/Rule/Mock/RuleStoreMockClient.php b/Tests/Feature/Rule/Mock/StoreRuleMockClient.php similarity index 91% rename from Tests/Feature/Rule/Mock/RuleStoreMockClient.php rename to Tests/Feature/Rule/Mock/StoreRuleMockClient.php index 5fa1656..0ed3924 100644 --- a/Tests/Feature/Rule/Mock/RuleStoreMockClient.php +++ b/Tests/Feature/Rule/Mock/StoreRuleMockClient.php @@ -6,7 +6,7 @@ use PlugAndPay\Sdk\Entity\Response; -class RuleStoreMockClient extends RuleShowMockClient +class StoreRuleMockClient extends ShowRuleMockClient { protected array $requestBody; diff --git a/Tests/Feature/Rule/Mock/UpdateRuleMockClient.php b/Tests/Feature/Rule/Mock/UpdateRuleMockClient.php index 5d05c5d..573708b 100644 --- a/Tests/Feature/Rule/Mock/UpdateRuleMockClient.php +++ b/Tests/Feature/Rule/Mock/UpdateRuleMockClient.php @@ -7,7 +7,7 @@ use PlugAndPay\Sdk\Entity\Response; use PlugAndPay\Sdk\Support\Arr; -class UpdateRuleMockClient extends RuleShowMockClient +class UpdateRuleMockClient extends ShowRuleMockClient { protected array $requestBody; diff --git a/Tests/Feature/Rule/ShowRuleTest.php b/Tests/Feature/Rule/ShowRuleTest.php index 50c564a..35db324 100644 --- a/Tests/Feature/Rule/ShowRuleTest.php +++ b/Tests/Feature/Rule/ShowRuleTest.php @@ -10,7 +10,7 @@ use PlugAndPay\Sdk\Exception\UnauthenticatedException; use PlugAndPay\Sdk\Service\RuleService; use PlugAndPay\Sdk\Tests\Feature\ClientMock; -use PlugAndPay\Sdk\Tests\Feature\Rule\Mock\RuleShowMockClient; +use PlugAndPay\Sdk\Tests\Feature\Rule\Mock\ShowRuleMockClient; class ShowRuleTest extends TestCase { @@ -47,7 +47,7 @@ public function show_non_existing_rule(): void /** @test */ public function show_rule(): void { - $client = new RuleShowMockClient(data: ['id' => 1]); + $client = new ShowRuleMockClient(data: ['id' => 1]); $service = new RuleService($client); $rule = $service->find(1); @@ -55,9 +55,9 @@ public function show_rule(): void static::assertSame(1, $rule->id()); static::assertSame('call_webhook', $rule->actionType()); static::assertSame(['hook_url' => 'https://example.com/webhook'], $rule->actionData()); - static::assertSame('order_created', $rule->triggerType()); + static::assertSame('order_paid', $rule->triggerType()); static::assertSame(['is_first' => true, 'product_id' => [1]], $rule->conditionData()); - static::assertSame('Plug&Pay webhook rule', $rule->name()); + static::assertSame('Plug&Pay Example Rule', $rule->name()); static::assertFalse($rule->readonly()); static::assertSame('webhook', $rule->driver()); } diff --git a/Tests/Feature/Rule/StoreRuleTest.php b/Tests/Feature/Rule/StoreRuleTest.php index 3c312d5..29f48b9 100644 --- a/Tests/Feature/Rule/StoreRuleTest.php +++ b/Tests/Feature/Rule/StoreRuleTest.php @@ -1,8 +1,5 @@ 'https://example.com/webhook'], $body['action_data']); - static::assertSame('order_created', $body['trigger_type']); + static::assertSame('order_paid', $body['trigger_type']); static::assertSame(['product_id' => [1]], $body['condition_data']); - static::assertSame('Plug&Pay example rule', $body['name']); + static::assertSame('Plug&Pay Example Rule', $body['name']); static::assertSame('webhook', $body['driver']); } /** @test */ public function store_basic_rule(): void { - $client = new RuleStoreMockClient(); + $client = new StoreRuleMockClient(); $service = new RuleService($client); $rule = $this->makeBasicRule(); @@ -64,9 +61,9 @@ private function makeBasicRule(): Rule return (new Rule) ->setActionType('call_webhook') ->setActionData(['url' => 'https://example.com/webhook']) - ->setTriggerType('order_created') + ->setTriggerType('order_paid') ->setConditionData(['product_id' => [1]]) - ->setName('Plug&Pay example rule') + ->setName('Plug&Pay Example Rule') ->setDriver('webhook'); } } diff --git a/Tests/Feature/Rule/RuleUpdateTest.php b/Tests/Feature/Rule/UpdateRuleTest.php similarity index 88% rename from Tests/Feature/Rule/RuleUpdateTest.php rename to Tests/Feature/Rule/UpdateRuleTest.php index 3ff29d4..5deec16 100644 --- a/Tests/Feature/Rule/RuleUpdateTest.php +++ b/Tests/Feature/Rule/UpdateRuleTest.php @@ -1,7 +1,5 @@ Date: Wed, 31 Jul 2024 13:41:28 +0200 Subject: [PATCH 2/3] clean-up: make data providers static --- Tests/Feature/Order/IndexOrdersTest.php | 2 +- Tests/Feature/Product/IndexProductsTest.php | 2 +- Tests/Feature/Rule/IndexRulesTest.php | 2 +- Tests/Feature/Subscription/IndexSubscriptionsTest.php | 2 +- Tests/Feature/TaxRate/IndexTaxRatesTest.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/Feature/Order/IndexOrdersTest.php b/Tests/Feature/Order/IndexOrdersTest.php index 8a45b00..893155e 100644 --- a/Tests/Feature/Order/IndexOrdersTest.php +++ b/Tests/Feature/Order/IndexOrdersTest.php @@ -52,7 +52,7 @@ public function index_orders_with_filter(string $method, mixed $value, string $q /** * Data provider for index_orders_with_filter. */ - public function orderFilterDataProvider(): array + public static function orderFilterDataProvider(): array { return [ [ diff --git a/Tests/Feature/Product/IndexProductsTest.php b/Tests/Feature/Product/IndexProductsTest.php index 806dd64..8f02d1a 100644 --- a/Tests/Feature/Product/IndexProductsTest.php +++ b/Tests/Feature/Product/IndexProductsTest.php @@ -46,7 +46,7 @@ public function index_products_with_filter(string $method, mixed $value, string /** * Data provider for index_products_with_filter. */ - public function productFilterDataProvider(): array + public static function productFilterDataProvider(): array { return [ [ diff --git a/Tests/Feature/Rule/IndexRulesTest.php b/Tests/Feature/Rule/IndexRulesTest.php index d7001ba..9f84f67 100644 --- a/Tests/Feature/Rule/IndexRulesTest.php +++ b/Tests/Feature/Rule/IndexRulesTest.php @@ -63,7 +63,7 @@ public function index_rules_with_filter(string $method, mixed $value, string $qu static::assertSame("/v2/rules?$queryKey=$queryValue", $client->path()); } - public function ruleFilterDataProvider(): array + public static function ruleFilterDataProvider(): array { return [ [ diff --git a/Tests/Feature/Subscription/IndexSubscriptionsTest.php b/Tests/Feature/Subscription/IndexSubscriptionsTest.php index 938f292..0efe07c 100644 --- a/Tests/Feature/Subscription/IndexSubscriptionsTest.php +++ b/Tests/Feature/Subscription/IndexSubscriptionsTest.php @@ -47,7 +47,7 @@ public function index_subscriptions_with_filter(string $method, mixed $value, st /** * Data provider for index_subscriptions_with_filter. */ - public function subscriptionFilterDataProvider(): array + public static function subscriptionFilterDataProvider(): array { return [ [ diff --git a/Tests/Feature/TaxRate/IndexTaxRatesTest.php b/Tests/Feature/TaxRate/IndexTaxRatesTest.php index 5464e60..a7dc6ff 100644 --- a/Tests/Feature/TaxRate/IndexTaxRatesTest.php +++ b/Tests/Feature/TaxRate/IndexTaxRatesTest.php @@ -42,7 +42,7 @@ public function index_tax_rate_with_filter(string $method, mixed $value, string /** * Data provider for index_tax_rate_with_filter. */ - public function taxRateFilterDataProvider(): array + public static function taxRateFilterDataProvider(): array { return [ [ From 29d7b76235364c545f4bdd847a3d20c01f2f5208 Mon Sep 17 00:00:00 2001 From: joeydehaas Date: Wed, 31 Jul 2024 13:42:53 +0200 Subject: [PATCH 3/3] fix: changed named parameter --- Tests/Feature/Rule/Mock/IndexRulesMockClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Feature/Rule/Mock/IndexRulesMockClient.php b/Tests/Feature/Rule/Mock/IndexRulesMockClient.php index 316e08b..73ed30d 100644 --- a/Tests/Feature/Rule/Mock/IndexRulesMockClient.php +++ b/Tests/Feature/Rule/Mock/IndexRulesMockClient.php @@ -13,7 +13,7 @@ class IndexRulesMockClient extends ClientMock public function __construct(array $data = [ShowRuleMockClient::BASIC_RULE]) { - parent::__construct(data: $data); + parent::__construct(body: $data); } public function get(string $path): Response