diff --git a/.github/workflows/simfoni-php.yml b/.github/workflows/simfoni-php.yml index cbb3798..a14ec96 100644 --- a/.github/workflows/simfoni-php.yml +++ b/.github/workflows/simfoni-php.yml @@ -14,13 +14,13 @@ on: - fix/* jobs: simfoni-php-tests: - runs-on: ubuntu-18.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 7.1 + php-version: 8.1 extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite coverage: none - name: Install Dependencies diff --git a/changelog.md b/changelog.md index d2f9464..2a49f5d 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,9 @@ +## v2.5.0 + ++ PHP ^8.0 compatability ++ Add ability to pass id type to cancel and show order methods ++ Add new resend webhook function + ## v2.4.1 + PHP 7.1 compatability diff --git a/composer.json b/composer.json index 148dffb..ede981e 100644 --- a/composer.json +++ b/composer.json @@ -10,13 +10,13 @@ } ], "require": { - "php": ">=7.1", + "php": ">=7.1|^8.0", "ext-json": "*", "ext-openssl": "*", "guzzlehttp/guzzle": "^6.0|^7.0" }, "require-dev": { - "phpunit/phpunit": "^7.0" + "phpunit/phpunit": "^7.0|^9.3" }, "autoload": { "psr-4": { diff --git a/src/Order.php b/src/Order.php index cd20134..87237ff 100644 --- a/src/Order.php +++ b/src/Order.php @@ -26,9 +26,9 @@ public function create(array $params = []): array * @param string $id * @return array */ - public function cancel(string $id): array + public function cancel(string $id, string $type = 'id'): array { - return $this->getApiRequestor()->deleteRequest('/api/order/'.$id); + return $this->getApiRequestor()->deleteRequest('/api/order/'.$id.'?type='.$type); } /** @@ -41,14 +41,15 @@ public function search(array $params = []): array } /** - * Show Product + * Show Order * - * @param string $id + * @param string $id + * @param string $type * @return array */ - public function show(string $id): array + public function show(string $id, string $type = 'id'): array { - return $this->getApiRequestor()->getRequest('/api/order/'.$id); + return $this->getApiRequestor()->getRequest('/api/order/'.$id.'?type='.$type); } /** diff --git a/src/Webhook.php b/src/Webhook.php new file mode 100644 index 0000000..5ece93f --- /dev/null +++ b/src/Webhook.php @@ -0,0 +1,21 @@ +getApiRequestor()->postRequest('/api/webhook/resend/'.$id, $params); + } + +} \ No newline at end of file diff --git a/tests/AccountTest.php b/tests/AccountTest.php index 61ac95d..fe57d98 100644 --- a/tests/AccountTest.php +++ b/tests/AccountTest.php @@ -11,7 +11,7 @@ class AccountTest extends TestCase protected $account; /** {@inheritdoc} **/ - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/AuthenticationTest.php b/tests/AuthenticationTest.php index 14b6329..acd764a 100644 --- a/tests/AuthenticationTest.php +++ b/tests/AuthenticationTest.php @@ -12,7 +12,7 @@ class AuthenticationTest extends TestCase protected $authentication; /** {@inheritdoc} **/ - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 177ad07..c48575e 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -11,7 +11,7 @@ class ClientTest extends TestCase protected $client; /** {@inheritdoc} **/ - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/ContactTest.php b/tests/ContactTest.php index 34b7884..f5c74f0 100644 --- a/tests/ContactTest.php +++ b/tests/ContactTest.php @@ -11,7 +11,7 @@ class ContactTest extends TestCase protected $contact; /** {@inheritdoc} **/ - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/DeliveryMethodTest.php b/tests/DeliveryMethodTest.php index a8c391e..f9e961e 100644 --- a/tests/DeliveryMethodTest.php +++ b/tests/DeliveryMethodTest.php @@ -12,7 +12,7 @@ class DeliveryMethodTest extends TestCase protected $deliveryMethod; /** {@inheritdoc} **/ - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/IssuedInfoTest.php b/tests/IssuedInfoTest.php index 95bb6ca..293c2b9 100644 --- a/tests/IssuedInfoTest.php +++ b/tests/IssuedInfoTest.php @@ -11,7 +11,7 @@ class IssuedInfoTest extends TestCase protected $issuedInfo; /** {@inheritdoc} **/ - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/OrderItemTest.php b/tests/OrderItemTest.php index c40769f..ac547e3 100644 --- a/tests/OrderItemTest.php +++ b/tests/OrderItemTest.php @@ -13,7 +13,7 @@ class OrderItemTest extends TestCase protected $orderItem; /** {@inheritdoc} **/ - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/OrderTest.php b/tests/OrderTest.php index 7f0ac60..decfb7b 100644 --- a/tests/OrderTest.php +++ b/tests/OrderTest.php @@ -11,7 +11,7 @@ class OrderTest extends TestCase protected $order; /** {@inheritdoc} **/ - public function setUp() + public function setUp(): void { parent::setUp(); @@ -53,6 +53,16 @@ public function can_cancel_order(): void self::assertEquals($this->order->cancel(1), $this->getMockedResponseBody()); } + /** @test * */ + public function can_cancel_order_by_ref(): void + { + $this->mockExpectedHttpResponse([ + 'message' => 'Order ref-1111 cancelled.' + ]); + + self::assertEquals($this->order->cancel('ref-1111', 'ref'), $this->getMockedResponseBody()); + } + /** @test * */ public function can_search_orders(): void { @@ -85,6 +95,21 @@ public function can_show_order(): void self::assertEquals($this->order->show(1), $this->getMockedResponseBody()); } + /** @test * */ + public function can_show_order_by_reference(): void + { + $this->mockExpectedHttpResponse([ + 'data' => [ + [ + 'id' => 1, + 'reference' => 'ref-1111', + ], + ] + ]); + + self::assertEquals($this->order->show('ref-1111', 'ref'), $this->getMockedResponseBody()); + } + /** @test * */ public function can_list_all_orders(): void { diff --git a/tests/ProductTest.php b/tests/ProductTest.php index 4d04bae..0cc931b 100644 --- a/tests/ProductTest.php +++ b/tests/ProductTest.php @@ -12,7 +12,7 @@ class ProductTest extends TestCase protected $product; /** {@inheritdoc} **/ - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/WebhookTest.php b/tests/WebhookTest.php new file mode 100644 index 0000000..37f19da --- /dev/null +++ b/tests/WebhookTest.php @@ -0,0 +1,55 @@ +webhook = new Webhook(); + } + + /** @test * */ + public function can_request_webhook_resend() + { + $id = 'test-1111'; + $params = ['event' => 'order.cancelled', 'type' => 'reference']; + + $this->mockExpectedHttpResponse([ + 'message' => 'Webhook order.cancelled for order 123 resent' + ]); + + self::assertEquals($this->webhook->resend($id, $params), $this->getMockedResponseBody()); + } + + /** @test * */ + public function can_request_webhook_resend_with_defaults() + { + $id = '123'; + + $this->mockExpectedHttpResponse([ + 'message' => 'Webhook order.complete for order 123 resent' + ]); + + self::assertEquals($this->webhook->resend($id), $this->getMockedResponseBody()); + } + + /** @test * */ + public function can_not_request_webhook_without_id() + { + self::expectException('ArgumentCountError'); + $this->webhook->resend(); + } +} \ No newline at end of file