Skip to content

Commit

Permalink
Merge pull request #47 from plug-and-pay/feature/cleanup
Browse files Browse the repository at this point in the history
clean-up: cleanup file names
  • Loading branch information
JoeyDeHaas authored Jul 31, 2024
2 parents 7edd730 + 29d7b76 commit 09a4066
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Tests/Feature/Order/IndexOrdersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
[
Expand Down
2 changes: 1 addition & 1 deletion Tests/Feature/Product/IndexProductsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions Tests/Feature/Rule/IndexRulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -33,17 +33,17 @@ 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();

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());
}
Expand All @@ -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);
Expand All @@ -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 [
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(body: $data);
}

public function get(string $path): Response
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
<?php

/** @noinspection ThrowRawExceptionInspection */

declare(strict_types=1);

namespace PlugAndPay\Sdk\Tests\Feature\Rule\Mock;

use PlugAndPay\Sdk\Tests\Feature\ClientMock;

class RuleShowMockClient extends ClientMock
class ShowRuleMockClient extends ClientMock
{
public const BASIC_RULE = [
'id' => 1,
'action_type' => 'call_webhook',
'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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use PlugAndPay\Sdk\Entity\Response;

class RuleStoreMockClient extends RuleShowMockClient
class StoreRuleMockClient extends ShowRuleMockClient
{
protected array $requestBody;

Expand Down
2 changes: 1 addition & 1 deletion Tests/Feature/Rule/Mock/UpdateRuleMockClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 4 additions & 4 deletions Tests/Feature/Rule/ShowRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -47,17 +47,17 @@ 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);

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());
}
Expand Down
15 changes: 6 additions & 9 deletions Tests/Feature/Rule/StoreRuleTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<?php

/** @noinspection EfferentObjectCouplingInspection */
/* @noinspection PhpUnhandledExceptionInspection */

declare(strict_types=1);

namespace PlugAndPay\Sdk\Tests\Feature\Rule;
Expand All @@ -12,7 +9,7 @@
use PlugAndPay\Sdk\Director\ToBody\RuleToBody;
use PlugAndPay\Sdk\Entity\Rule;
use PlugAndPay\Sdk\Service\RuleService;
use PlugAndPay\Sdk\Tests\Feature\Rule\Mock\RuleStoreMockClient;
use PlugAndPay\Sdk\Tests\Feature\Rule\Mock\StoreRuleMockClient;

class StoreRuleTest extends TestCase
{
Expand All @@ -39,16 +36,16 @@ public function convert_basic_rule(): void

static::assertSame('call_webhook', $body['action_type']);
static::assertSame(['url' => '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();
Expand All @@ -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');
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

/** @noinspection PhpUnhandledExceptionInspection */

declare(strict_types=1);

namespace PlugAndPay\Sdk\Tests\Feature\Rule;
Expand All @@ -11,7 +9,7 @@
use PlugAndPay\Sdk\Service\RuleService;
use PlugAndPay\Sdk\Tests\Feature\Rule\Mock\UpdateRuleMockClient;

class RuleUpdateTest extends TestCase
class UpdateRuleTest extends TestCase
{
/** @test */
public function update_basic_Rule(): void
Expand Down
2 changes: 1 addition & 1 deletion Tests/Feature/Subscription/IndexSubscriptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
[
Expand Down
2 changes: 1 addition & 1 deletion Tests/Feature/TaxRate/IndexTaxRatesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
[
Expand Down
2 changes: 1 addition & 1 deletion src/Filters/RuleFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class RuleFilter
{
public array $parameters = [];
private array $parameters = [];

public function group(RuleGroupType $value): self
{
Expand Down

0 comments on commit 09a4066

Please sign in to comment.