mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Add test
This commit is contained in:
parent
8c7baac7f9
commit
4d87f7fdae
1 changed files with 15 additions and 2 deletions
|
@ -3,6 +3,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\Webhooks\Status;
|
||||
|
||||
use Exception;
|
||||
use Mockery;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\WebhookEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Webhook;
|
||||
|
@ -17,6 +18,7 @@ class WebhookSimulationTest extends TestCase
|
|||
private $webhook;
|
||||
|
||||
private $event_type = 'CHECKOUT.ORDER.APPROVED';
|
||||
private $event_version = '2.0';
|
||||
|
||||
private $sut;
|
||||
|
||||
|
@ -32,7 +34,7 @@ class WebhookSimulationTest extends TestCase
|
|||
$this->webhook_endpoint = Mockery::mock(WebhookEndpoint::class);
|
||||
$this->webhook = new Webhook('https://example.com', []);
|
||||
|
||||
$this->sut = new WebhookSimulation($this->webhook_endpoint, $this->webhook, $this->event_type);
|
||||
$this->sut = new WebhookSimulation($this->webhook_endpoint, $this->webhook, $this->event_type, $this->event_version);
|
||||
|
||||
when('update_option')->alias(function ($key, $value) {
|
||||
$this->storage[$key] = $value;
|
||||
|
@ -48,7 +50,7 @@ class WebhookSimulationTest extends TestCase
|
|||
{
|
||||
$this->webhook_endpoint
|
||||
->expects('simulate')
|
||||
->with($this->webhook, $this->event_type)
|
||||
->with($this->webhook, $this->event_type, $this->event_version)
|
||||
->andReturn($this->event);
|
||||
|
||||
$this->sut->start();
|
||||
|
@ -69,6 +71,17 @@ class WebhookSimulationTest extends TestCase
|
|||
self::assertFalse($this->sut->is_simulation_event($this->createEvent($this->event_id)));
|
||||
}
|
||||
|
||||
public function testSimulationWhenNoWebhook()
|
||||
{
|
||||
$this->sut = new WebhookSimulation($this->webhook_endpoint, null, $this->event_type, $this->event_version);
|
||||
|
||||
self::assertFalse($this->sut->is_simulation_event($this->createEvent($this->event_id)));
|
||||
|
||||
$this->expectException(Exception::class);
|
||||
|
||||
$this->sut->start();
|
||||
}
|
||||
|
||||
private function createEvent(string $id): WebhookEvent
|
||||
{
|
||||
return new WebhookEvent($id, null, '', '', $this->event_type, '', '', (object) []);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue