Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ try {
match ($payload->event) {
WebhookEvent::PRODUCTS_UPDATE => syncProducts($client),
WebhookEvent::CATEGORIES_UPDATE => syncCategories($client),
WebhookEvent::BLOGS_UPDATE => syncBlogs($client),
};

http_response_code(200);
Expand Down
2 changes: 2 additions & 0 deletions src/Enum/WebhookEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ enum WebhookEvent: string
{
case PRODUCTS_UPDATE = 'Products.update';
case CATEGORIES_UPDATE = 'Categories.update';
case BLOGS_UPDATE = 'Blogs.update';

/**
* @return array<string>
Expand All @@ -22,6 +23,7 @@ public static function fromString(string $value): ?self
return match ($value) {
'Products.update' => self::PRODUCTS_UPDATE,
'Categories.update' => self::CATEGORIES_UPDATE,
'Blogs.update' => self::BLOGS_UPDATE,
default => null,
};
}
Expand Down
7 changes: 6 additions & 1 deletion tests/Enum/WebhookEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public function testAllCasesExist(): void
{
$this->assertSame('Products.update', WebhookEvent::PRODUCTS_UPDATE->value);
$this->assertSame('Categories.update', WebhookEvent::CATEGORIES_UPDATE->value);
$this->assertSame('Blogs.update', WebhookEvent::BLOGS_UPDATE->value);
}

public function testValues(): void
Expand All @@ -21,13 +22,15 @@ public function testValues(): void

$this->assertContains('Products.update', $values);
$this->assertContains('Categories.update', $values);
$this->assertCount(2, $values);
$this->assertContains('Blogs.update', $values);
$this->assertCount(3, $values);
}

public function testFromStringReturnsCorrectEnum(): void
{
$this->assertSame(WebhookEvent::PRODUCTS_UPDATE, WebhookEvent::fromString('Products.update'));
$this->assertSame(WebhookEvent::CATEGORIES_UPDATE, WebhookEvent::fromString('Categories.update'));
$this->assertSame(WebhookEvent::BLOGS_UPDATE, WebhookEvent::fromString('Blogs.update'));
}

public function testFromStringReturnsNullForUnknown(): void
Expand All @@ -36,5 +39,7 @@ public function testFromStringReturnsNullForUnknown(): void
$this->assertNull(WebhookEvent::fromString(''));
$this->assertNull(WebhookEvent::fromString('products.update'));
$this->assertNull(WebhookEvent::fromString('PRODUCTS.UPDATE'));
$this->assertNull(WebhookEvent::fromString('blogs.update'));
$this->assertNull(WebhookEvent::fromString('BLOGS.UPDATE'));
}
}