From 00d8723a64ce8e463fabb69a973f85e2b9e7cba1 Mon Sep 17 00:00:00 2001 From: Tomas Smetka Date: Sun, 28 Dec 2025 14:37:01 +0100 Subject: [PATCH 1/2] Fix blog: guid to id string --- src/DTO/Blog.php | 33 +++++++++++---------------------- tests/BlogTest.php | 40 ++++++++++++++++------------------------ 2 files changed, 27 insertions(+), 46 deletions(-) diff --git a/src/DTO/Blog.php b/src/DTO/Blog.php index b82251e..c475859 100644 --- a/src/DTO/Blog.php +++ b/src/DTO/Blog.php @@ -10,12 +10,11 @@ final class Blog * @param array $images */ public function __construct( - public readonly ?int $id = null, - public readonly ?string $guid = null, + public readonly string $id, + public readonly bool $isVisible, + public readonly LocalizedString $name, + public readonly LocalizedString $url, public readonly ?string $category = null, - public readonly bool $isVisible = true, - public readonly ?LocalizedString $name = null, - public readonly ?LocalizedString $url = null, public readonly ?LocalizedString $description = null, public readonly ?LocalizedString $seoTitle = null, public readonly ?LocalizedString $seoDescription = null, @@ -33,25 +32,16 @@ public function __construct( public function toArray(): array { $data = [ + 'id' => $this->id, 'is_visible' => $this->isVisible, + 'name' => $this->name->toArray(), + 'url' => $this->url->toArray(), ]; - if ($this->guid !== null) { - $data['guid'] = $this->guid; - } - if ($this->category !== null) { $data['category'] = $this->category; } - if ($this->name !== null) { - $data['name'] = $this->name->toArray(); - } - - if ($this->url !== null) { - $data['url'] = $this->url->toArray(); - } - if ($this->description !== null) { $data['description'] = $this->description->toArray(); } @@ -77,12 +67,11 @@ public function toArray(): array public static function fromArray(array $data): self { return new self( - id: $data['id'] ?? null, - guid: $data['guid'] ?? null, + id: $data['id'], + isVisible: $data['is_visible'], + name: LocalizedString::fromArray($data['name']), + url: LocalizedString::fromArray($data['url']), category: $data['category'] ?? null, - isVisible: $data['is_visible'] ?? true, - name: isset($data['name']) ? LocalizedString::fromArray($data['name']) : null, - url: isset($data['url']) ? LocalizedString::fromArray($data['url']) : null, description: isset($data['description']) ? LocalizedString::fromArray($data['description']) : null, seoTitle: isset($data['seo_title']) ? LocalizedString::fromArray($data['seo_title']) : null, seoDescription: isset($data['seo_description']) ? LocalizedString::fromArray($data['seo_description']) : null, diff --git a/tests/BlogTest.php b/tests/BlogTest.php index 195abec..3b76b5c 100644 --- a/tests/BlogTest.php +++ b/tests/BlogTest.php @@ -15,22 +15,20 @@ final class BlogTest extends TestCase public function testCreateBlogWithAllFields(): void { $blog = new Blog( - id: 123, - guid: '550e8400-e29b-41d4-a716-446655440000', - category: 'news', + id: 'BLOG-123', isVisible: true, name: LocalizedString::create('Blog Title') ->withTranslation(Language::CS, 'Název blogu'), url: LocalizedString::create('https://example.com/blog') ->withTranslation(Language::CS, 'https://example.com/cs/blog'), + category: 'news', description: LocalizedString::create('

Description

'), seoTitle: LocalizedString::create('SEO Title'), seoDescription: LocalizedString::create('SEO Description'), images: ['https://example.com/image.jpg'], ); - $this->assertSame(123, $blog->id); - $this->assertSame('550e8400-e29b-41d4-a716-446655440000', $blog->guid); + $this->assertSame('BLOG-123', $blog->id); $this->assertSame('news', $blog->category); $this->assertTrue($blog->isVisible); $this->assertSame('Blog Title', $blog->name->getDefault()); @@ -40,18 +38,18 @@ public function testCreateBlogWithAllFields(): void public function testBlogToArray(): void { $blog = new Blog( - guid: '550e8400-e29b-41d4-a716-446655440000', - category: 'tips', + id: 'BLOG-001', isVisible: true, name: LocalizedString::create('Blog Title'), url: LocalizedString::create('https://example.com/blog'), + category: 'tips', description: LocalizedString::create('

Description

'), images: ['https://example.com/image.jpg'], ); $array = $blog->toArray(); - $this->assertSame('550e8400-e29b-41d4-a716-446655440000', $array['guid']); + $this->assertSame('BLOG-001', $array['id']); $this->assertSame('tips', $array['category']); $this->assertTrue($array['is_visible']); $this->assertArrayHasKey('name', $array); @@ -63,6 +61,7 @@ public function testBlogToArray(): void public function testBlogToArrayExcludesNullFields(): void { $blog = new Blog( + id: 'BLOG-001', isVisible: true, name: LocalizedString::create('Blog Title'), url: LocalizedString::create('https://example.com/blog'), @@ -70,7 +69,9 @@ public function testBlogToArrayExcludesNullFields(): void $array = $blog->toArray(); - $this->assertArrayNotHasKey('guid', $array); + $this->assertArrayHasKey('id', $array); + $this->assertArrayHasKey('name', $array); + $this->assertArrayHasKey('url', $array); $this->assertArrayNotHasKey('category', $array); $this->assertArrayNotHasKey('description', $array); $this->assertArrayNotHasKey('seo_title', $array); @@ -81,8 +82,7 @@ public function testBlogToArrayExcludesNullFields(): void public function testBlogFromArray(): void { $data = [ - 'id' => 456, - 'guid' => '550e8400-e29b-41d4-a716-446655440001', + 'id' => 'BLOG-456', 'category' => 'news', 'is_visible' => true, 'name' => ['default' => 'Blog Title', 'cs' => 'Název blogu'], @@ -98,8 +98,7 @@ public function testBlogFromArray(): void $blog = Blog::fromArray($data); - $this->assertSame(456, $blog->id); - $this->assertSame('550e8400-e29b-41d4-a716-446655440001', $blog->guid); + $this->assertSame('BLOG-456', $blog->id); $this->assertSame('news', $blog->category); $this->assertTrue($blog->isVisible); $this->assertSame('Blog Title', $blog->name->getDefault()); @@ -112,7 +111,7 @@ public function testBlogFromArray(): void public function testBlogFromArrayWithContent(): void { $data = [ - 'id' => 789, + 'id' => 'BLOG-789', 'is_visible' => true, 'name' => ['default' => 'Blog'], 'url' => ['default' => 'https://example.com'], @@ -138,7 +137,7 @@ public function testBlogFromArrayWithContent(): void public function testBlogFromArrayWithMinimalData(): void { $data = [ - 'id' => 1, + 'id' => 'BLOG-001', 'is_visible' => false, 'name' => ['default' => 'Minimal Blog'], 'url' => ['default' => 'https://example.com/minimal'], @@ -146,9 +145,8 @@ public function testBlogFromArrayWithMinimalData(): void $blog = Blog::fromArray($data); - $this->assertSame(1, $blog->id); + $this->assertSame('BLOG-001', $blog->id); $this->assertFalse($blog->isVisible); - $this->assertNull($blog->guid); $this->assertNull($blog->category); $this->assertNull($blog->description); $this->assertNull($blog->seoTitle); @@ -157,13 +155,6 @@ public function testBlogFromArrayWithMinimalData(): void $this->assertSame([], $blog->images); } - public function testBlogDefaultIsVisible(): void - { - $blog = new Blog(); - - $this->assertTrue($blog->isVisible); - } - public function testBlogImagesArray(): void { $images = [ @@ -173,6 +164,7 @@ public function testBlogImagesArray(): void ]; $blog = new Blog( + id: 'BLOG-001', isVisible: true, name: LocalizedString::create('Blog'), url: LocalizedString::create('https://example.com'), From 2801c604986385161c0e66b81707e56d41a4eae9 Mon Sep 17 00:00:00 2001 From: Tomas Smetka Date: Sun, 28 Dec 2025 14:40:16 +0100 Subject: [PATCH 2/2] Fix test --- tests/PoboClientTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/PoboClientTest.php b/tests/PoboClientTest.php index 68dae3f..323ea62 100644 --- a/tests/PoboClientTest.php +++ b/tests/PoboClientTest.php @@ -217,7 +217,7 @@ public function testImportBlogsThrowsExceptionForTooManyItems(): void $blogs = []; for ($i = 0; $i < 101; $i++) { $blogs[] = [ - 'guid' => sprintf('550e8400-e29b-41d4-a716-4466554400%02d', $i), + 'id' => sprintf('BLOG-%03d', $i), 'is_visible' => true, 'name' => ['default' => sprintf('Blog %d', $i)], 'url' => ['default' => sprintf('https://example.com/blog/%d', $i)], @@ -233,16 +233,16 @@ public function testImportBlogsThrowsExceptionForTooManyItems(): void public function testBlogDtoIsConvertedToArray(): void { $blog = new Blog( - guid: '550e8400-e29b-41d4-a716-446655440000', - category: 'news', + id: 'BLOG-001', isVisible: true, name: LocalizedString::create('Test Blog'), url: LocalizedString::create('https://example.com/blog'), + category: 'news', ); $array = $blog->toArray(); - $this->assertSame('550e8400-e29b-41d4-a716-446655440000', $array['guid']); + $this->assertSame('BLOG-001', $array['id']); $this->assertSame('news', $array['category']); $this->assertTrue($array['is_visible']); }