diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c3da837..1ea9ce8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ jobs: strategy: fail-fast: true matrix: - php: [8.2, 8.3, 8.4, 8.5] + php: [8.3, 8.4, 8.5] steps: - uses: actions/checkout@v4 @@ -22,11 +22,14 @@ jobs: - name: Install dependencies run: composer install --prefer-dist --no-progress - # - name: Check code style - # run: composer cs-check + - name: Copy the phpunit.xml + run: cp phpunit.xml.dist phpunit.xml - # - name: Run PHPStan - # run: composer stan + - name: Check code style + run: composer cs-check - # - name: Run tests - # run: composer test + - name: Run PHPStan + run: composer stan + + - name: Run tests + run: composer test diff --git a/composer.json b/composer.json index 0c31811..f1dac97 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "prefer-stable": true, "config": { "platform": { - "php": "8.2.0" + "php": "8.3.0" }, "allow-plugins": { "pestphp/pest-plugin": true @@ -49,4 +49,4 @@ "@test" ] } -} +} \ No newline at end of file diff --git a/composer.lock b/composer.lock index 7ba6a0b..c581aa1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "71798ca3ccf65b3002efd11d920a1b41", + "content-hash": "745775b7253ceb81109cff4a620c2157", "packages": [ { "name": "guzzlehttp/guzzle", @@ -3820,16 +3820,16 @@ }, { "name": "symfony/console", - "version": "v7.4.8", + "version": "v7.4.9", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "1e92e39c51f95b88e3d66fa2d9f06d1fb45dd707" + "reference": "d7d2b64a45a89d607865927b176fa51c33ddbb58" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/1e92e39c51f95b88e3d66fa2d9f06d1fb45dd707", - "reference": "1e92e39c51f95b88e3d66fa2d9f06d1fb45dd707", + "url": "https://api.github.com/repos/symfony/console/zipball/d7d2b64a45a89d607865927b176fa51c33ddbb58", + "reference": "d7d2b64a45a89d607865927b176fa51c33ddbb58", "shasum": "" }, "require": { @@ -3894,7 +3894,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v7.4.8" + "source": "https://github.com/symfony/console/tree/v7.4.9" }, "funding": [ { @@ -3914,7 +3914,7 @@ "type": "tidelift" } ], - "time": "2026-03-30T13:54:39+00:00" + "time": "2026-04-22T15:21:55+00:00" }, { "name": "symfony/finder", @@ -4236,19 +4236,20 @@ }, { "name": "symfony/polyfill-mbstring", - "version": "v1.31.0", + "version": "v1.37.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "85181ba99b2345b0ef10ce42ecac37612d9fd341" + "reference": "6a21eb99c6973357967f6ce3708cd55a6bec6315" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/85181ba99b2345b0ef10ce42ecac37612d9fd341", - "reference": "85181ba99b2345b0ef10ce42ecac37612d9fd341", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/6a21eb99c6973357967f6ce3708cd55a6bec6315", + "reference": "6a21eb99c6973357967f6ce3708cd55a6bec6315", "shasum": "" }, "require": { + "ext-iconv": "*", "php": ">=7.2" }, "provide": { @@ -4296,7 +4297,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.37.0" }, "funding": [ { @@ -4307,12 +4308,16 @@ "url": "https://github.com/fabpot", "type": "github" }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, { "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2024-09-09T11:45:10+00:00" + "time": "2026-04-10T17:25:58+00:00" }, { "name": "symfony/process", @@ -4737,7 +4742,7 @@ "platform": {}, "platform-dev": {}, "platform-overrides": { - "php": "8.2.0" + "php": "8.3.0" }, "plugin-api-version": "2.9.0" } diff --git a/phpstan.neon b/phpstan.neon index 74bf342..79b90ad 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,4 +1,5 @@ parameters: paths: - src - level: 1 + - tests + level: 5 diff --git a/src/Invoice/APIs/CancelInvoiceRequest.php b/src/Invoice/APIs/CancelInvoiceRequest.php index 08fd5c8..12ae829 100644 --- a/src/Invoice/APIs/CancelInvoiceRequest.php +++ b/src/Invoice/APIs/CancelInvoiceRequest.php @@ -13,7 +13,8 @@ class CancelInvoiceRequest extends Request public function __construct( public readonly string $invoiceId, - ) {} + ) { + } public function resolveEndpoint(): string { diff --git a/src/Invoice/APIs/CreateInvoiceRequest.php b/src/Invoice/APIs/CreateInvoiceRequest.php index b0d9148..a475022 100644 --- a/src/Invoice/APIs/CreateInvoiceRequest.php +++ b/src/Invoice/APIs/CreateInvoiceRequest.php @@ -18,7 +18,8 @@ class CreateInvoiceRequest extends Request implements HasBody public function __construct( public readonly CreateInvoiceDTO $createInvoiceDTO, - ) {} + ) { + } public function resolveEndpoint(): string { diff --git a/src/Invoice/APIs/GetInvoiceRequest.php b/src/Invoice/APIs/GetInvoiceRequest.php index 19e46f6..5fe4fbf 100644 --- a/src/Invoice/APIs/GetInvoiceRequest.php +++ b/src/Invoice/APIs/GetInvoiceRequest.php @@ -13,7 +13,8 @@ class GetInvoiceRequest extends Request public function __construct( public readonly string $invoiceId, - ) {} + ) { + } public function resolveEndpoint(): string { diff --git a/src/Invoice/APIs/UpdateInvoiceRequest.php b/src/Invoice/APIs/UpdateInvoiceRequest.php index dfa9434..d06f8a6 100644 --- a/src/Invoice/APIs/UpdateInvoiceRequest.php +++ b/src/Invoice/APIs/UpdateInvoiceRequest.php @@ -19,7 +19,8 @@ class UpdateInvoiceRequest extends Request implements HasBody public function __construct( public readonly string $invoiceId, public readonly UpdateInvoiceDTO $updateInvoiceDTO, - ) {} + ) { + } public function resolveEndpoint(): string { diff --git a/src/Invoice/DTO/CreateInvoiceDTO.php b/src/Invoice/DTO/CreateInvoiceDTO.php index 36dbb52..4555f00 100644 --- a/src/Invoice/DTO/CreateInvoiceDTO.php +++ b/src/Invoice/DTO/CreateInvoiceDTO.php @@ -13,7 +13,8 @@ public function __construct( public ?string $backUrl = null, public ?string $expiredAt = null, public ?array $metadata = null, - ) {} + ) { + } public static function fromArray(array $data): self { diff --git a/src/Invoice/DTO/UpdateInvoiceDTO.php b/src/Invoice/DTO/UpdateInvoiceDTO.php index 5829d89..1c161ba 100644 --- a/src/Invoice/DTO/UpdateInvoiceDTO.php +++ b/src/Invoice/DTO/UpdateInvoiceDTO.php @@ -9,5 +9,6 @@ */ public function __construct( public array $metadata, - ) {} + ) { + } } diff --git a/src/Moyasar.php b/src/Moyasar.php index c0eb367..8f2e249 100644 --- a/src/Moyasar.php +++ b/src/Moyasar.php @@ -12,7 +12,8 @@ class Moyasar extends Connector public function __construct( protected readonly string $baseUrl, protected readonly string $apiKey, - ) {} + ) { + } public function resolveBaseUrl(): string { diff --git a/src/Payment/APIs/CapturePaymentRequest.php b/src/Payment/APIs/CapturePaymentRequest.php index c19875c..b63c306 100644 --- a/src/Payment/APIs/CapturePaymentRequest.php +++ b/src/Payment/APIs/CapturePaymentRequest.php @@ -18,7 +18,8 @@ class CapturePaymentRequest extends Request implements HasBody public function __construct( public readonly string $paymentId, public readonly ?int $amount = null, - ) {} + ) { + } public function resolveEndpoint(): string { diff --git a/src/Payment/APIs/CreatePaymentRequest.php b/src/Payment/APIs/CreatePaymentRequest.php index a68232c..e1478c9 100644 --- a/src/Payment/APIs/CreatePaymentRequest.php +++ b/src/Payment/APIs/CreatePaymentRequest.php @@ -19,7 +19,8 @@ class CreatePaymentRequest extends Request implements HasBody public function __construct( public readonly CreatePaymentDTO $createPaymentDTO, - ) {} + ) { + } public function resolveEndpoint(): string { diff --git a/src/Payment/APIs/GetPaymentRequest.php b/src/Payment/APIs/GetPaymentRequest.php index 68740c2..039b0a2 100644 --- a/src/Payment/APIs/GetPaymentRequest.php +++ b/src/Payment/APIs/GetPaymentRequest.php @@ -13,7 +13,8 @@ class GetPaymentRequest extends Request public function __construct( public readonly string $paymentId, - ) {} + ) { + } public function resolveEndpoint(): string { diff --git a/src/Payment/APIs/RefundPaymentRequest.php b/src/Payment/APIs/RefundPaymentRequest.php index ba0afcd..1be8dc7 100644 --- a/src/Payment/APIs/RefundPaymentRequest.php +++ b/src/Payment/APIs/RefundPaymentRequest.php @@ -18,7 +18,8 @@ class RefundPaymentRequest extends Request implements HasBody public function __construct( public readonly string $paymentId, public readonly ?int $amount = null, - ) {} + ) { + } public function resolveEndpoint(): string { diff --git a/src/Payment/APIs/UpdatePaymentRequest.php b/src/Payment/APIs/UpdatePaymentRequest.php index f760e31..0de1ed0 100644 --- a/src/Payment/APIs/UpdatePaymentRequest.php +++ b/src/Payment/APIs/UpdatePaymentRequest.php @@ -19,7 +19,8 @@ class UpdatePaymentRequest extends Request implements HasBody public function __construct( public readonly string $paymentId, public readonly UpdatePaymentDTO $updatePaymentDTO, - ) {} + ) { + } public function resolveEndpoint(): string { diff --git a/src/Payment/APIs/VoidPaymentRequest.php b/src/Payment/APIs/VoidPaymentRequest.php index fe830c8..26f89fd 100644 --- a/src/Payment/APIs/VoidPaymentRequest.php +++ b/src/Payment/APIs/VoidPaymentRequest.php @@ -13,7 +13,8 @@ class VoidPaymentRequest extends Request public function __construct( public readonly string $paymentId, - ) {} + ) { + } public function resolveEndpoint(): string { diff --git a/src/Payment/DTO/CreatePaymentDTO.php b/src/Payment/DTO/CreatePaymentDTO.php index c4b1d43..9d00180 100644 --- a/src/Payment/DTO/CreatePaymentDTO.php +++ b/src/Payment/DTO/CreatePaymentDTO.php @@ -19,7 +19,8 @@ public function __construct( public ?string $callbackUrl = null, public ?array $metadata = null, public ?bool $applyCoupon = null, - ) {} + ) { + } /** * @param array $data diff --git a/src/Payment/DTO/PaymentDTO.php b/src/Payment/DTO/PaymentDTO.php index 5743d72..db0510d 100644 --- a/src/Payment/DTO/PaymentDTO.php +++ b/src/Payment/DTO/PaymentDTO.php @@ -37,7 +37,8 @@ public function __construct( public array $metadata, public array $source, public ?string $givenId = null, - ) {} + ) { + } public static function fromResponse(Response $response): self { diff --git a/src/Payment/DTO/Source/CreditCardSourceDTO.php b/src/Payment/DTO/Source/CreditCardSourceDTO.php index f8bf318..fe5c91f 100644 --- a/src/Payment/DTO/Source/CreditCardSourceDTO.php +++ b/src/Payment/DTO/Source/CreditCardSourceDTO.php @@ -16,7 +16,8 @@ public function __construct( public ?bool $manual = null, public ?bool $saveCard = null, public ?string $token = null, - ) {} + ) { + } /** * @return array diff --git a/src/Payment/DTO/UpdatePaymentDTO.php b/src/Payment/DTO/UpdatePaymentDTO.php index c8de99e..e486797 100644 --- a/src/Payment/DTO/UpdatePaymentDTO.php +++ b/src/Payment/DTO/UpdatePaymentDTO.php @@ -10,5 +10,6 @@ public function __construct( public ?string $description = null, public ?array $metadata = null, - ) {} + ) { + } } diff --git a/src/Payment/PaymentResource.php b/src/Payment/PaymentResource.php index ee5479b..aab3c06 100644 --- a/src/Payment/PaymentResource.php +++ b/src/Payment/PaymentResource.php @@ -23,7 +23,7 @@ public function get(string $paymentId): PaymentDTO public function list(): ListPaymentsRequest { - return new ListPaymentsRequest; + return new ListPaymentsRequest(); } public function create(CreatePaymentDTO $dto): PaymentDTO diff --git a/tests/Config/ExtraData.php b/tests/Config/ExtraData.php index dad18f7..16f77e3 100644 --- a/tests/Config/ExtraData.php +++ b/tests/Config/ExtraData.php @@ -8,7 +8,8 @@ class ExtraData { public function __construct( private readonly MockClient $client - ) {} + ) { + } public function getClient(): MockClient { diff --git a/tests/Config/MockResponses.php b/tests/Config/MockResponses.php index 748010b..5de949d 100644 --- a/tests/Config/MockResponses.php +++ b/tests/Config/MockResponses.php @@ -4,21 +4,43 @@ use Saloon\Http\Faking\MockResponse; use Tests\Config\Samples\InvoiceSamples; +use HamodaDev\Moyasar\Invoice\APIs\CancelInvoiceRequest; +use HamodaDev\Moyasar\Invoice\APIs\BulkCreateInvoicesRequest; +use HamodaDev\Moyasar\Invoice\APIs\CreateInvoiceRequest; +use HamodaDev\Moyasar\Invoice\APIs\GetInvoiceRequest; +use HamodaDev\Moyasar\Invoice\APIs\ListInvoicesRequest; +use HamodaDev\Moyasar\Invoice\APIs\UpdateInvoiceRequest; -return [ - // invoice - \HamodaDev\Moyasar\Invoice\APIs\CreateInvoiceRequest::class => MockResponse::make(body: InvoiceSamples::TEST_INVOICE), - \HamodaDev\Moyasar\Invoice\APIs\BulkCreateInvoicesRequest::class => MockResponse::make(body: [ - 'invoices' => [InvoiceSamples::TEST_INVOICE, InvoiceSamples::TEST_INVOICE_2] - ]), - \HamodaDev\Moyasar\Invoice\APIs\GetInvoiceRequest::class => MockResponse::make(body: InvoiceSamples::TEST_INVOICE_3), - \HamodaDev\Moyasar\Invoice\APIs\ListInvoicesRequest::class => MockResponse::make(body: [ - 'invoices' => [InvoiceSamples::TEST_INVOICE, InvoiceSamples::TEST_INVOICE_2, InvoiceSamples::TEST_INVOICE_3], - ]), - \HamodaDev\Moyasar\Invoice\APIs\UpdateInvoiceRequest::class => MockResponse::make(body: InvoiceSamples::TEST_INVOICE), - \HamodaDev\Moyasar\Invoice\APIs\CancelInvoiceRequest::class => MockResponse::make(body: InvoiceSamples::CANCELED_TEST_INVOICE), - - // payment - /** TODO */ -]; +class MockResponses +{ + public static function getAll(): array + { + return array_merge( + self::invoiceResponses(), + // self::paymentResponses(), // TODO: add when payment mocks are ready + ); + } + private static function invoiceResponses(): array + { + return [ + CreateInvoiceRequest::class => MockResponse::make(body: InvoiceSamples::TEST_INVOICE), + BulkCreateInvoicesRequest::class => MockResponse::make(body: [ + 'invoices' => [ + InvoiceSamples::TEST_INVOICE, + InvoiceSamples::TEST_INVOICE_2, + ], + ]), + GetInvoiceRequest::class => MockResponse::make(body: InvoiceSamples::TEST_INVOICE_3), + ListInvoicesRequest::class => MockResponse::make(body: [ + 'invoices' => [ + InvoiceSamples::TEST_INVOICE, + InvoiceSamples::TEST_INVOICE_2, + InvoiceSamples::TEST_INVOICE_3, + ], + ]), + UpdateInvoiceRequest::class => MockResponse::make(body: InvoiceSamples::TEST_INVOICE), + CancelInvoiceRequest::class => MockResponse::make(body: InvoiceSamples::CANCELED_TEST_INVOICE), + ]; + } +} diff --git a/tests/Config/MoyasarInitializer.php b/tests/Config/MoyasarInitializer.php index 7cf8cd8..8e6a153 100644 --- a/tests/Config/MoyasarInitializer.php +++ b/tests/Config/MoyasarInitializer.php @@ -29,8 +29,7 @@ public static function getInstance(): self apiKey: "sk_test_AbCd", ); - /** @var array */ - $mockRouter = require_once "MockResponses.php"; + $mockRouter = MockResponses::getAll(); $extra = new ExtraData(new MockClient($mockRouter)); $moyasar->withMockClient($extra->getClient()); diff --git a/tests/Config/Samples/InvoiceSamples.php b/tests/Config/Samples/InvoiceSamples.php index 8466af0..102bb84 100644 --- a/tests/Config/Samples/InvoiceSamples.php +++ b/tests/Config/Samples/InvoiceSamples.php @@ -5,10 +5,10 @@ class InvoiceSamples { /** @var string */ - public const MOCK_URL = "https://example.com"; - + public const string MOCK_URL = "https://example.com"; + /** @var array */ - public const TEST_INVOICE = [ + public const array TEST_INVOICE = [ 'id' => '1234', 'status' => 'initiated', 'amount' => 1000, @@ -20,7 +20,7 @@ class InvoiceSamples 'order_id' => '1234' ], ]; - + /** @var array */ public const array CANCELED_TEST_INVOICE = [ 'id' => '1234', @@ -34,7 +34,7 @@ class InvoiceSamples 'order_id' => '1234' ], ]; - + /** @var array */ public const array TEST_INVOICE_2 = [ 'id' => '5678', @@ -45,7 +45,7 @@ class InvoiceSamples 'amount_format' => '10.00 SAR', 'url' => self::MOCK_URL, ]; - + /** @var array */ public const array TEST_INVOICE_3 = [ 'id' => '91011', diff --git a/tests/ExampleTest.php b/tests/ExampleTest.php deleted file mode 100644 index b193d74..0000000 --- a/tests/ExampleTest.php +++ /dev/null @@ -1,3 +0,0 @@ - expect(true)->toBe(true)); diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php deleted file mode 100644 index 61cd84c..0000000 --- a/tests/Feature/ExampleTest.php +++ /dev/null @@ -1,5 +0,0 @@ -toBeTrue(); -}); diff --git a/tests/Pest.php b/tests/Pest.php index 4c964f8..6a1d083 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -28,12 +28,8 @@ | */ -expect()->extend('toBeOne', function () { - return $this->toBe(1); -}); - uses() - ->beforeEach(fn() => MockClient::destroyGlobal()) + ->beforeEach(fn () => MockClient::destroyGlobal()) ->in(__DIR__); function validateEnvIsSet() diff --git a/tests/Unit/.gitkeep b/tests/Unit/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php deleted file mode 100644 index 61cd84c..0000000 --- a/tests/Unit/ExampleTest.php +++ /dev/null @@ -1,5 +0,0 @@ -toBeTrue(); -});