From 76a5856c1a38af679286d2201b1dfe48b4270805 Mon Sep 17 00:00:00 2001 From: Viet Vu Date: Sun, 17 May 2026 18:55:36 +0700 Subject: [PATCH] fix: reconcile WordPress DTO field coverage --- src/Data/Comment.php | 2 ++ src/Data/PostType.php | 12 ++++++++ src/Data/Taxonomy.php | 4 +++ tests/Unit/Data/DataModelsTest.php | 48 ++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+) diff --git a/src/Data/Comment.php b/src/Data/Comment.php index f576246..536f4c6 100644 --- a/src/Data/Comment.php +++ b/src/Data/Comment.php @@ -16,6 +16,7 @@ class Comment extends Dto { /** * @param array $author_avatar_urls + * @param array $meta */ public function __construct( public readonly int $id, @@ -31,6 +32,7 @@ public function __construct( public readonly string $status, public readonly string $type, public readonly array $author_avatar_urls = [], + public readonly array $meta = [], ) { } } diff --git a/src/Data/PostType.php b/src/Data/PostType.php index d8aef14..2a4ddd4 100644 --- a/src/Data/PostType.php +++ b/src/Data/PostType.php @@ -9,15 +9,27 @@ /** * @SuppressWarnings("PHPMD.BooleanArgumentFlag") * @SuppressWarnings("PHPMD.CamelCaseParameterName") + * @SuppressWarnings("PHPMD.CamelCasePropertyName") + * @SuppressWarnings("PHPMD.ExcessiveParameterList") */ class PostType extends Dto { + /** + * @param array $labels + * @param array $supports + * @param array $taxonomies + */ public function __construct( public readonly string $slug, public readonly string $name, public readonly string $rest_base = '', public readonly bool $hierarchical = false, public readonly bool $viewable = true, + public readonly string $description = '', + public readonly string $rest_namespace = '', + public readonly array $labels = [], + public readonly array $supports = [], + public readonly array $taxonomies = [], ) { } } diff --git a/src/Data/Taxonomy.php b/src/Data/Taxonomy.php index f5c7dad..ae1727b 100644 --- a/src/Data/Taxonomy.php +++ b/src/Data/Taxonomy.php @@ -15,6 +15,7 @@ class Taxonomy extends Dto { /** * @param array $types + * @param array $labels */ public function __construct( public readonly string $slug, @@ -22,6 +23,9 @@ public function __construct( public readonly array $types = [], public readonly string $rest_base = '', public readonly bool $hierarchical = false, + public readonly string $description = '', + public readonly string $rest_namespace = '', + public readonly array $labels = [], ) { } } diff --git a/tests/Unit/Data/DataModelsTest.php b/tests/Unit/Data/DataModelsTest.php index 3065462..6760194 100644 --- a/tests/Unit/Data/DataModelsTest.php +++ b/tests/Unit/Data/DataModelsTest.php @@ -159,12 +159,15 @@ public function testCommentConstructorPreservesRenderedContentAndAvatarMap(): vo status: 'approved', type: 'comment', author_avatar_urls: ['96' => 'https://example.com/avatar-96.jpg'], + meta: ['source' => 'integration'], ); $this->assertSame(21, $comment->id); $this->assertSame($content, $comment->content); $this->assertSame('SDK Bot', $comment->author_name); $this->assertSame(['96' => 'https://example.com/avatar-96.jpg'], $comment->author_avatar_urls); + $this->assertSame(['source' => 'integration'], $comment->meta); + $this->assertSame(['source' => 'integration'], $comment->toArray()['meta']); } public function testTaxonomyConstructorDefaultsOptionalWordPressSchemaFields(): void @@ -179,6 +182,9 @@ public function testTaxonomyConstructorDefaultsOptionalWordPressSchemaFields(): $this->assertSame([], $taxonomy->types); $this->assertSame('', $taxonomy->rest_base); $this->assertFalse($taxonomy->hierarchical); + $this->assertSame('', $taxonomy->description); + $this->assertSame('', $taxonomy->rest_namespace); + $this->assertSame([], $taxonomy->labels); } public function testPostTypeConstructorPreservesViewabilityFlags(): void @@ -197,6 +203,48 @@ public function testPostTypeConstructorPreservesViewabilityFlags(): void $this->assertFalse($postType->viewable); } + public function testPostTypeConstructorPreservesAdditionalWordPressSchemaFields(): void + { + $postType = new PostType( + slug: 'book', + name: 'Books', + rest_base: 'books', + hierarchical: false, + viewable: true, + description: 'Book content', + rest_namespace: 'wp/v2', + labels: ['singular_name' => 'Book'], + supports: ['title' => true, 'editor' => true], + taxonomies: ['category', 'post_tag'], + ); + + $this->assertSame('Book content', $postType->description); + $this->assertSame('wp/v2', $postType->rest_namespace); + $this->assertSame(['singular_name' => 'Book'], $postType->labels); + $this->assertSame(['title' => true, 'editor' => true], $postType->supports); + $this->assertSame(['category', 'post_tag'], $postType->taxonomies); + $this->assertSame('wp/v2', $postType->toArray()['rest_namespace']); + } + + public function testTaxonomyConstructorPreservesAdditionalWordPressSchemaFields(): void + { + $taxonomy = new Taxonomy( + slug: 'genre', + name: 'Genres', + types: ['book'], + rest_base: 'genres', + hierarchical: true, + description: 'Book genres', + rest_namespace: 'wp/v2', + labels: ['singular_name' => 'Genre'], + ); + + $this->assertSame('Book genres', $taxonomy->description); + $this->assertSame('wp/v2', $taxonomy->rest_namespace); + $this->assertSame(['singular_name' => 'Genre'], $taxonomy->labels); + $this->assertSame('Book genres', $taxonomy->toArray()['description']); + } + public function testSearchResultConstructorStoresWordPressSearchShape(): void { $result = new SearchResult(