Skip to content

Commit 3b2d4b6

Browse files
committed
CS maintenance
1 parent 0e2d7d8 commit 3b2d4b6

27 files changed

+481
-632
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"require-dev": {
3434
"doctrine/annotations": "^2.0.0",
3535
"doctrine/orm": "^2.12 || ^3.0",
36+
"matthiasnoback/symfony-config-test": "^4.3 || ^5.2",
3637
"matthiasnoback/symfony-dependency-injection-test": "^4.3 || ^5.0",
3738
"nyholm/psr7": "^1.8.1",
3839
"php-cs-fixer/shim": "^3.58.1",

tests/BaseKernelTestCase.php

Lines changed: 3 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,8 @@
77
use Doctrine\ORM\EntityManagerInterface;
88
use Doctrine\ORM\Tools\SchemaTool;
99
use Meilisearch\Bundle\Collection;
10-
use Meilisearch\Bundle\SearchableEntity;
1110
use Meilisearch\Bundle\SearchService;
12-
use Meilisearch\Bundle\Tests\Entity\Article;
13-
use Meilisearch\Bundle\Tests\Entity\Comment;
14-
use Meilisearch\Bundle\Tests\Entity\Image;
15-
use Meilisearch\Bundle\Tests\Entity\Link;
16-
use Meilisearch\Bundle\Tests\Entity\ObjectId\DummyObjectId;
17-
use Meilisearch\Bundle\Tests\Entity\Page;
18-
use Meilisearch\Bundle\Tests\Entity\Podcast;
1911
use Meilisearch\Bundle\Tests\Entity\Post;
20-
use Meilisearch\Bundle\Tests\Entity\Tag;
2112
use Meilisearch\Client;
2213
use Meilisearch\Exceptions\ApiException;
2314
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
@@ -44,156 +35,16 @@ protected function setUp(): void
4435
$this->cleanUp();
4536
}
4637

47-
protected function createPost(?int $id = null): Post
38+
protected function createPost(): Post
4839
{
49-
$post = new Post();
50-
$post->setTitle('Test Post');
51-
$post->setContent('Test content post');
52-
53-
if (null !== $id) {
54-
$post->setId($id);
55-
}
40+
$post = new Post('Test Post', 'Test content post');
5641

5742
$this->entityManager->persist($post);
5843
$this->entityManager->flush();
5944

6045
return $post;
6146
}
6247

63-
protected function createPage(int $id): Page
64-
{
65-
$page = new Page();
66-
$page->setTitle('Test Page');
67-
$page->setContent('Test content page');
68-
$page->setId(new DummyObjectId($id));
69-
70-
$this->entityManager->persist($page);
71-
$this->entityManager->flush();
72-
73-
return $page;
74-
}
75-
76-
protected function createSearchablePost(): SearchableEntity
77-
{
78-
$post = $this->createPost(random_int(100, 300));
79-
80-
return new SearchableEntity(
81-
$this->getPrefix().'posts',
82-
$post,
83-
$this->get('doctrine')->getManager()->getClassMetadata(Post::class),
84-
$this->get('serializer')
85-
);
86-
}
87-
88-
protected function createComment(?int $id = null): Comment
89-
{
90-
$post = new Post(['title' => 'What a post!']);
91-
$comment = new Comment();
92-
$comment->setContent('Comment content');
93-
$comment->setPost($post);
94-
95-
if (null !== $id) {
96-
$comment->setId($id);
97-
}
98-
99-
$this->entityManager->persist($post);
100-
$this->entityManager->persist($comment);
101-
$this->entityManager->flush();
102-
103-
return $comment;
104-
}
105-
106-
protected function createImage(?int $id = null): Image
107-
{
108-
$image = new Image();
109-
$image->setUrl('https://docs.meilisearch.com/logo.png');
110-
111-
if (null !== $id) {
112-
$image->setId($id);
113-
}
114-
115-
$this->entityManager->persist($image);
116-
$this->entityManager->flush();
117-
118-
return $image;
119-
}
120-
121-
protected function createArticle(?int $id = null): Article
122-
{
123-
$article = new Article();
124-
$article->setTitle('Test Article');
125-
if (null !== $id) {
126-
$article->setId($id);
127-
}
128-
129-
$this->entityManager->persist($article);
130-
$this->entityManager->flush();
131-
132-
return $article;
133-
}
134-
135-
protected function createPodcast(?int $id = null): Podcast
136-
{
137-
$podcast = new Podcast();
138-
$podcast->setTitle('Test Podcast');
139-
if (null !== $id) {
140-
$podcast->setId($id);
141-
}
142-
143-
$this->entityManager->persist($podcast);
144-
$this->entityManager->flush();
145-
146-
return $podcast;
147-
}
148-
149-
protected function createSearchableImage(): SearchableEntity
150-
{
151-
$image = $this->createImage(random_int(100, 300));
152-
153-
return new SearchableEntity(
154-
$this->getPrefix().'image',
155-
$image,
156-
$this->get('doctrine')->getManager()->getClassMetadata(Image::class),
157-
null
158-
);
159-
}
160-
161-
protected function createTag(array $properties = []): Tag
162-
{
163-
$tag = new Tag();
164-
$tag->setName('Meilisearch Test Tag');
165-
166-
if (\count($properties) > 0) {
167-
foreach ($properties as $key => $value) {
168-
$method = 'set'.ucfirst($key);
169-
$tag->$method($value);
170-
}
171-
}
172-
173-
$this->entityManager->persist($tag);
174-
$this->entityManager->flush();
175-
176-
return $tag;
177-
}
178-
179-
protected function createLink(array $properties = []): Link
180-
{
181-
$link = new Link();
182-
$link->setName('Meilisearch Test Link');
183-
184-
if (\count($properties) > 0) {
185-
foreach ($properties as $key => $value) {
186-
$method = 'set'.ucfirst($key);
187-
$link->$method($value);
188-
}
189-
}
190-
191-
$this->entityManager->persist($link);
192-
$this->entityManager->flush();
193-
194-
return $link;
195-
}
196-
19748
protected function getPrefix(): string
19849
{
19950
return $this->searchService->getConfiguration()->get('prefix');
@@ -204,11 +55,6 @@ protected function get(string $id): ?object
20455
return self::getContainer()->get($id);
20556
}
20657

207-
protected function getFileName(string $indexName, string $type): string
208-
{
209-
return \sprintf('%s/%s.json', $indexName, $type);
210-
}
211-
21258
protected function waitForAllTasks(): void
21359
{
21460
$firstTask = $this->client->getTasks()->getResults()[0];
@@ -219,13 +65,10 @@ private function cleanUp(): void
21965
{
22066
(new Collection($this->searchService->getConfiguration()->get('indices')))
22167
->each(function ($item): bool {
222-
$this->cleanupIndex($this->getPrefix().$item['name']);
68+
$this->cleanupIndex($item['prefixed_name']);
22369

22470
return true;
22571
});
226-
227-
$this->cleanupIndex($this->getPrefix().'indexA');
228-
$this->cleanupIndex($this->getPrefix().'indexB');
22972
}
23073

23174
private function cleanupIndex(string $indexName): void

tests/Entity/Comment.php

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Comment
2828
*/
2929
#[ORM\Id]
3030
#[ORM\GeneratedValue]
31-
#[ORM\Column(type: Types::INTEGER, nullable: true)]
31+
#[ORM\Column(type: Types::INTEGER)]
3232
#[Groups('searchable')]
3333
private ?int $id = null;
3434

@@ -39,88 +39,57 @@ class Comment
3939
*/
4040
#[ORM\ManyToOne(inversedBy: 'comments')]
4141
#[ORM\JoinColumn(nullable: false)]
42-
private ?Post $post = null;
42+
private Post $post;
4343

4444
/**
45-
* @var string
46-
*
4745
* @ORM\Column(type="text")
4846
*
4947
* @Groups({"searchable"})
5048
*/
5149
#[ORM\Column(type: Types::TEXT)]
5250
#[Groups('searchable')]
53-
private $content;
51+
private string $content;
5452

5553
/**
56-
* @var \DateTime
57-
*
58-
* @ORM\Column(type="datetime")
54+
* @ORM\Column(type="datetime_immutable")
5955
*
6056
* @Groups({"searchable"})
6157
*/
62-
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
58+
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
6359
#[Groups('searchable')]
64-
private $publishedAt;
60+
private \DateTimeImmutable $publishedAt;
6561

66-
/**
67-
* Comment constructor.
68-
*
69-
* @param array<string, mixed> $attributes
70-
*/
71-
public function __construct(array $attributes = [])
62+
public function __construct(Post $post, string $content, ?\DateTimeImmutable $publishedAt = null)
7263
{
73-
$this->id = $attributes['id'] ?? null;
74-
$this->content = $attributes['content'] ?? null;
75-
$this->publishedAt = $attributes['publishedAt'] ?? new \DateTime();
76-
$this->post = $attributes['post'] ?? null;
64+
$this->post = $post;
65+
$this->content = $content;
66+
$this->publishedAt = $publishedAt ?? new \DateTimeImmutable();
7767
}
7868

7969
public function getId(): ?int
8070
{
8171
return $this->id;
8272
}
8373

84-
public function setId(?int $id): Comment
85-
{
86-
$this->id = $id;
87-
88-
return $this;
89-
}
90-
91-
public function getContent(): ?string
74+
public function getContent(): string
9275
{
9376
return $this->content;
9477
}
9578

96-
public function setContent(?string $content): Comment
79+
public function setContent(string $content): Comment
9780
{
9881
$this->content = $content;
9982

10083
return $this;
10184
}
10285

103-
public function getPublishedAt(): \DateTime
86+
public function getPublishedAt(): \DateTimeImmutable
10487
{
10588
return $this->publishedAt;
10689
}
10790

108-
public function setPublishedAt(\DateTime $publishedAt): Comment
109-
{
110-
$this->publishedAt = $publishedAt;
111-
112-
return $this;
113-
}
114-
11591
public function getPost(): ?Post
11692
{
11793
return $this->post;
11894
}
119-
120-
public function setPost(Post $post): Comment
121-
{
122-
$this->post = $post;
123-
124-
return $this;
125-
}
12695
}

tests/Entity/ContentItem.php

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,35 +32,26 @@ abstract class ContentItem
3232
#[ORM\Id]
3333
#[ORM\GeneratedValue]
3434
#[ORM\Column(type: Types::INTEGER)]
35-
private int $id;
35+
private ?int $id = null;
3636

3737
/**
3838
* @ORM\Column(type="string")
3939
*/
4040
#[ORM\Column(type: Types::STRING)]
41-
private string $title = 'Title';
41+
private string $title;
4242

43-
public function getId(): int
43+
public function __construct(string $title = 'Title')
4444
{
45-
return $this->id;
45+
$this->title = $title;
4646
}
4747

48-
public function setId(int $id): self
48+
public function getId(): ?int
4949
{
50-
$this->id = $id;
51-
52-
return $this;
50+
return $this->id;
5351
}
5452

5553
public function getTitle(): string
5654
{
5755
return $this->title;
5856
}
59-
60-
public function setTitle(string $title): self
61-
{
62-
$this->title = $title;
63-
64-
return $this;
65-
}
6657
}

tests/Entity/DummyCustomGroups.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class DummyCustomGroups
1919
*
2020
* @ORM\Column(type="integer")
2121
*
22+
* @ORM\GeneratedValue("NONE")
23+
*
2224
* @Groups("public")
2325
*/
2426
#[ORM\Id]

tests/Entity/DynamicSettings.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class DynamicSettings
1717
* @ORM\Id
1818
*
1919
* @ORM\Column(type="integer")
20+
*
21+
* @ORM\GeneratedValue("NONE")
2022
*/
2123
#[ORM\Id]
2224
#[ORM\Column(type: Types::INTEGER)]

0 commit comments

Comments
 (0)