Skip to content

Commit 30f81bc

Browse files
authored
Add Comment entity #65
2 parents c3c58e3 + 8908374 commit 30f81bc

File tree

8 files changed

+170
-7
lines changed

8 files changed

+170
-7
lines changed

.github/workflows/test.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
fail-fast: true
2929
matrix:
3030
php: ['8.0', '8.1', '8.2', '8.3']
31-
symfony: ['6.0.*', '6.1.*', '6.2.*' , '6.3.*', '6.4.*', '7.0.*']
31+
symfony: ['6.0.*', '6.1.*', '6.2.*' , '6.3.*', '6.4.*', '7.0.*', '7.1.*']
3232
experimental: [false]
3333
exclude:
3434
- php: '8.0'
@@ -41,8 +41,12 @@ jobs:
4141
symfony: '6.4.*' # Requires PHP >= 8.1 for compatibility
4242
- php: '8.0'
4343
symfony: '7.0.*' # Requires PHP >= 8.2 for compatibility
44+
- php: '8.0'
45+
symfony: '7.1.*' # Requires PHP >= 8.2 for compatibility
4446
- php: '8.1'
4547
symfony: '7.0.*' # Requires PHP >= 8.2 for compatibility
48+
- php: '8.1'
49+
symfony: '7.1.*' # Requires PHP >= 8.2 for compatibility
4650
include:
4751
- php: '8.4'
4852
symfony: '6.0.*'
@@ -62,6 +66,9 @@ jobs:
6266
- php: '8.4'
6367
symfony: '7.0.*'
6468
experimental: true
69+
- php: '8.4'
70+
symfony: '7.1.*'
71+
experimental: true
6572

6673
steps:
6774
- uses: actions/checkout@v4

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ reset-install:
2323
--admin_password=admin \
2424
--admin_email=contact@example.com \
2525
--skip-email
26-
@$(CLI) plugin install woocommerce --activate --version=7.9.0
26+
@$(CLI) plugin install woocommerce --activate --version=8.9.3
2727
@$(CLI) plugin install wordpress-importer --activate
2828

2929
reset-posts:
@@ -57,6 +57,10 @@ reset-woocommerce:
5757
@$(CLI) post meta set 22 related_product 18
5858
@$(CLI) post meta set 24 related_product 26
5959
@$(CLI) post meta set 26 related_product 37
60+
@$(CLI) comment create --comment_post_ID=15 --comment_content="I love this hoodie" --comment_author="John" --comment_type="review"
61+
@$(CLI) comment create --comment_post_ID=19 --comment_content="Awesome belt!" --comment_author="Jane" --comment_type="review"
62+
@$(CLI) comment meta set 2 rating "5"
63+
@$(CLI) comment meta set 3 rating "4"
6064

6165
.PHONY: test
6266
test:

docker-compose.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
version: '3.8'
2-
31
services:
42
mysql:
5-
image: mysql:8
3+
image: mysql:8.0.37
64
ports:
75
- '33306:3306'
86
volumes:
@@ -13,7 +11,7 @@ services:
1311
- MYSQL_ROOT_PASSWORD=root
1412
- MYSQL_DATABASE=wp_test
1513
- MYSQL_ROOT_HOST=%
16-
command: --default-authentication-plugin=mysql_native_password --max_connections=10000
14+
command: --max_connections=10000
1715

1816
wordpress:
1917
image: wordpress:fpm-alpine

src/Bridge/Entity/Comment.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Williarin\WordpressInterop\Bridge\Entity;
6+
7+
use AllowDynamicProperties;
8+
use DateTimeInterface;
9+
use Symfony\Component\Serializer\Annotation\Groups;
10+
use Williarin\WordpressInterop\Attributes\Id;
11+
use Williarin\WordpressInterop\Attributes\RepositoryClass;
12+
use Williarin\WordpressInterop\Bridge\Repository\CommentRepository;
13+
14+
#[AllowDynamicProperties]
15+
#[RepositoryClass(CommentRepository::class)]
16+
class Comment
17+
{
18+
use DynamicPropertiesTrait;
19+
20+
#[Id]
21+
#[Groups('base')]
22+
public ?int $commentId = null;
23+
24+
#[Groups('base')]
25+
public ?int $commentPostId = null;
26+
27+
#[Groups('base')]
28+
public ?string $commentAuthor = null;
29+
30+
#[Groups('base')]
31+
public ?string $commentAuthorEmail = null;
32+
33+
#[Groups('base')]
34+
public ?string $commentAuthorUrl = null;
35+
36+
#[Groups('base')]
37+
public ?string $commentAuthorIp = null;
38+
39+
#[Groups('base')]
40+
public ?DateTimeInterface $commentDate = null;
41+
42+
#[Groups('base')]
43+
public ?DateTimeInterface $commentDateGmt = null;
44+
45+
#[Groups('base')]
46+
public ?string $commentContent = null;
47+
48+
#[Groups('base')]
49+
public ?int $commentKarma = null;
50+
51+
#[Groups('base')]
52+
public ?string $commentApproved = null;
53+
54+
#[Groups('base')]
55+
public ?string $commentAgent = null;
56+
57+
#[Groups('base')]
58+
public ?string $commentType = null;
59+
60+
#[Groups('base')]
61+
public ?int $commentParent = null;
62+
63+
#[Groups('base')]
64+
public ?int $userId = null;
65+
}

src/Bridge/Repository/AbstractEntityRepository.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,7 @@ private function selectColumns(QueryBuilder $queryBuilder, array $extraFields, S
827827
} elseif (str_starts_with($column, 'MAX(')) {
828828
$selects[] = $column;
829829
$hasExtraFields = true;
830+
$this->joinSelfMetaTable($queryBuilder);
830831
} else {
831832
foreach ($this->tableAliases as $alias => $fields) {
832833
if (in_array($column, $fields, true)) {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Williarin\WordpressInterop\Bridge\Repository;
6+
7+
use Williarin\WordpressInterop\Bridge\Entity\Comment;
8+
9+
class CommentRepository extends AbstractEntityRepository
10+
{
11+
protected const TABLE_NAME = 'comments';
12+
protected const TABLE_META_NAME = 'commentmeta';
13+
protected const TABLE_IDENTIFIER = 'comment_id';
14+
protected const TABLE_META_IDENTIFIER = 'comment_id';
15+
protected const FALLBACK_ENTITY = Comment::class;
16+
17+
public function __construct()
18+
{
19+
parent::__construct(Comment::class);
20+
}
21+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Test\Bridge\Repository;
6+
7+
use Williarin\WordpressInterop\Bridge\Entity\Comment;
8+
use Williarin\WordpressInterop\Bridge\Repository\RepositoryInterface;
9+
use Williarin\WordpressInterop\Bridge\Repository\CommentRepository;
10+
use Williarin\WordpressInterop\Criteria\SelectColumns;
11+
use Williarin\WordpressInterop\Test\TestCase;
12+
13+
use function Williarin\WordpressInterop\Util\String\select_from_eav;
14+
15+
class CommentRepositoryTest extends TestCase
16+
{
17+
/** @var CommentRepository */
18+
private RepositoryInterface $repository;
19+
20+
protected function setUp(): void
21+
{
22+
parent::setUp();
23+
$this->repository = $this->manager->getRepository(Comment::class);
24+
}
25+
26+
public function testFind(): void
27+
{
28+
$term = $this->repository->find(1);
29+
30+
self::assertInstanceOf(Comment::class, $term);
31+
}
32+
33+
public function testFindByAttribute(): void
34+
{
35+
$comments = $this->repository
36+
->setOptions([
37+
'allow_extra_properties' => true,
38+
])
39+
->findBy([
40+
new SelectColumns(['comment_id', 'comment_post_id', select_from_eav('rating', 'rating')]),
41+
'rating' => '5',
42+
]);
43+
44+
self::assertContainsOnlyInstancesOf(Comment::class, $comments);
45+
self::assertCount(1, $comments);
46+
self::assertSame(2, $comments[0]->commentId);
47+
self::assertSame('5', $comments[0]->rating);
48+
self::assertSame(15, $comments[0]->commentPostId);
49+
}
50+
51+
public function testFindOneByWithSelectedAttribute(): void
52+
{
53+
$comments = $this->repository
54+
->setOptions([
55+
'allow_extra_properties' => true,
56+
])
57+
->findBy([
58+
new SelectColumns(['comment_id', 'comment_post_id', select_from_eav('rating', 'rating')]),
59+
]);
60+
61+
self::assertContainsOnlyInstancesOf(Comment::class, $comments);
62+
self::assertCount(3, $comments);
63+
self::assertNull($comments[0]->rating);
64+
self::assertSame('5', $comments[1]->rating);
65+
self::assertSame('4', $comments[2]->rating);
66+
}
67+
}

test/Test/Bridge/Repository/ProductRepositoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public function testFindByCriteriaOr(): void
168168
'stock_status' => 'instock',
169169
]);
170170

171-
self::assertEquals([15, 16, 21, 22, 23, 26], array_column($products, 'id'));
171+
self::assertEquals([16, 21, 22, 23, 26], array_column($products, 'id'));
172172
}
173173

174174
public function testFindOneByWithLooseOperatorDoesNotThrowException(): void

0 commit comments

Comments
 (0)