Skip to content

Commit bb21947

Browse files
bors[bot]norkunas
andauthored
Merge #237
237: Use PHP attributes in tests for PHP8+ r=brunoocasali a=norkunas # Pull Request ## Related issue Fixes #<issue_number> ## What does this PR do? - Configures PHP attributes to be used in tests for PHP8+ ## PR checklist Please check if your PR fulfills the following requirements: - [ ] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Co-authored-by: Tomas <[email protected]>
2 parents e224b5b + 89904a2 commit bb21947

File tree

13 files changed

+103
-11
lines changed

13 files changed

+103
-11
lines changed

.github/workflows/tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ jobs:
4646
env:
4747
SYMFONY_REQUIRE: ${{ matrix.sf-version }}
4848
run: composer install --prefer-dist --no-progress --quiet
49+
- name: "Remove doctrine/annotations"
50+
if: matrix.php-version != '7.4'
51+
run: |
52+
composer remove --dev doctrine/annotations
4953
- name: Meilisearch setup with Docker
5054
run: docker run -d -p 7700:7700 getmeili/meilisearch:latest meilisearch --master-key=masterKey --no-analytics
5155
- name: Run test suite

tests/Entity/Comment.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Meilisearch\Bundle\Tests\Entity;
66

7+
use Doctrine\DBAL\Types\Types;
78
use Doctrine\ORM\Mapping as ORM;
89
use Symfony\Component\Serializer\Annotation\Groups;
910

@@ -12,6 +13,8 @@
1213
*
1314
* @ORM\Table(name="comments")
1415
*/
16+
#[ORM\Entity]
17+
#[ORM\Table(name: 'comments')]
1518
class Comment
1619
{
1720
/**
@@ -23,27 +26,30 @@ class Comment
2326
*
2427
* @Groups({"searchable"})
2528
*/
29+
#[ORM\Id]
30+
#[ORM\GeneratedValue]
31+
#[ORM\Column(type: Types::INTEGER, nullable: true)]
32+
#[Groups('searchable')]
2633
private ?int $id = null;
2734

2835
/**
2936
* @ORM\ManyToOne(targetEntity="Post", inversedBy="comments")
3037
*
3138
* @ORM\JoinColumn(nullable=false)
3239
*/
40+
#[ORM\ManyToOne(inversedBy: 'comments')]
41+
#[ORM\JoinColumn(nullable: false)]
3342
private ?Post $post = null;
3443

3544
/**
3645
* @var string
3746
*
3847
* @ORM\Column(type="text")
39-
* min=5,
40-
* minMessage="comment.too_short",
41-
* max=10000,
42-
* maxMessage="comment.too_long"
43-
* )
4448
*
4549
* @Groups({"searchable"})
4650
*/
51+
#[ORM\Column(type: Types::TEXT)]
52+
#[Groups('searchable')]
4753
private $content;
4854

4955
/**
@@ -53,6 +59,8 @@ class Comment
5359
*
5460
* @Groups({"searchable"})
5561
*/
62+
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
63+
#[Groups('searchable')]
5664
private $publishedAt;
5765

5866
/**

tests/Entity/ContentAggregator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
/**
1111
* @ORM\Entity
1212
*/
13+
#[ORM\Entity]
1314
class ContentAggregator extends Aggregator
1415
{
1516
public function getIsVisible(): bool

tests/Entity/EmptyAggregator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
/**
1111
* @ORM\Entity
1212
*/
13+
#[ORM\Entity]
1314
class EmptyAggregator extends Aggregator
1415
{
1516
}

tests/Entity/Image.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
namespace Meilisearch\Bundle\Tests\Entity;
66

7+
use Doctrine\DBAL\Types\Types;
78
use Doctrine\ORM\Mapping as ORM;
89

910
/**
1011
* @ORM\Entity
1112
*/
13+
#[ORM\Entity]
1214
class Image
1315
{
1416
/**
@@ -18,11 +20,15 @@ class Image
1820
*
1921
* @ORM\Column(type="integer")
2022
*/
23+
#[ORM\Id]
24+
#[ORM\GeneratedValue]
25+
#[ORM\Column(type: Types::INTEGER)]
2126
private ?int $id;
2227

2328
/**
2429
* @ORM\Column(type="string")
2530
*/
31+
#[ORM\Column(type: Types::STRING)]
2632
private string $url;
2733

2834
public function __construct()

tests/Entity/Link.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Meilisearch\Bundle\Tests\Entity;
66

7+
use Doctrine\DBAL\Types\Types;
78
use Doctrine\ORM\Mapping as ORM;
89
use Meilisearch\Bundle\Searchable;
910
use Symfony\Component\Serializer\Normalizer\NormalizableInterface;
@@ -12,28 +13,34 @@
1213
/**
1314
* @ORM\Entity
1415
*/
16+
#[ORM\Entity]
1517
class Link implements NormalizableInterface
1618
{
1719
/**
1820
* @ORM\Id
1921
*
2022
* @ORM\Column(type="integer")
2123
*/
24+
#[ORM\Id]
25+
#[ORM\Column(type: Types::INTEGER)]
2226
private int $id;
2327

2428
/**
2529
* @ORM\Column(type="string")
2630
*/
31+
#[ORM\Column(type: Types::STRING)]
2732
private string $name = 'Test link';
2833

2934
/**
3035
* @ORM\Column(type="string")
3136
*/
37+
#[ORM\Column(type: Types::STRING)]
3238
private string $url = 'https://docs.meilisearch.com';
3339

3440
/**
3541
* @ORM\Column(type="boolean", options={"default"=false})
3642
*/
43+
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
3744
private bool $isSponsored = false;
3845

3946
public function getId(): int

tests/Entity/Page.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Meilisearch\Bundle\Tests\Entity;
66

7+
use Doctrine\DBAL\Types\Types;
78
use Doctrine\ORM\Mapping as ORM;
89
use Symfony\Component\Serializer\Annotation\Groups;
910

@@ -12,6 +13,8 @@
1213
*
1314
* @ORM\Table(name="pages")
1415
*/
16+
#[ORM\Entity]
17+
#[ORM\Table(name: 'pages')]
1518
class Page
1619
{
1720
/**
@@ -21,20 +24,27 @@ class Page
2124
*
2225
* @ORM\Column(type="object")
2326
*/
27+
#[ORM\Id]
28+
#[ORM\GeneratedValue(strategy: 'NONE')]
29+
#[ORM\Column(type: Types::OBJECT)]
2430
private $id = null;
2531

2632
/**
2733
* @ORM\Column(type="string", nullable=true)
2834
*
2935
* @Groups({"searchable"})
3036
*/
37+
#[ORM\Column(type: Types::STRING, nullable: true)]
38+
#[Groups('searchable')]
3139
private ?string $title = null;
3240

3341
/**
3442
* @ORM\Column(type="text", nullable=true)
3543
*
3644
* @Groups({"searchable"})
3745
*/
46+
#[ORM\Column(type: Types::TEXT, nullable: true)]
47+
#[Groups('searchable')]
3848
private ?string $content = null;
3949

4050
public function getId()

tests/Entity/Post.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Doctrine\Common\Collections\ArrayCollection;
88
use Doctrine\Common\Collections\Collection;
9+
use Doctrine\DBAL\Types\Types;
910
use Doctrine\ORM\Mapping as ORM;
1011
use Symfony\Component\Serializer\Annotation\Groups;
1112

@@ -14,6 +15,8 @@
1415
*
1516
* @ORM\Table(name="posts")
1617
*/
18+
#[ORM\Entity]
19+
#[ORM\Table(name: 'posts')]
1720
class Post
1821
{
1922
/**
@@ -26,6 +29,10 @@ class Post
2629
* @Groups({"searchable"})
2730
* ^ Note that Groups work on private properties
2831
*/
32+
#[ORM\Id]
33+
#[ORM\GeneratedValue]
34+
#[ORM\Column(type: Types::INTEGER)]
35+
#[Groups('searchable')]
2936
private ?int $id = null;
3037

3138
/**
@@ -34,24 +41,30 @@ class Post
3441
* @Groups({"searchable"})
3542
* ^ Note that Groups work on private properties
3643
*/
44+
#[ORM\Column(type: Types::STRING, nullable: true)]
45+
#[Groups('searchable')]
3746
private ?string $title = null;
3847

3948
/**
4049
* @ORM\Column(type="text", nullable=true)
4150
*
4251
* @Groups({"searchable"})
4352
*/
53+
#[ORM\Column(type: Types::TEXT, nullable: true)]
54+
#[Groups('searchable')]
4455
private ?string $content = null;
4556

4657
/**
4758
* @ORM\Column(type="datetime")
4859
*
4960
* @Groups({"searchable"})
5061
*/
62+
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
63+
#[Groups('searchable')]
5164
private ?\DateTime $publishedAt = null;
5265

5366
/**
54-
* @var Comment[]|Collection
67+
* @var Collection<int, Comment>
5568
*
5669
* @ORM\OneToMany(
5770
* targetEntity="Comment",
@@ -63,6 +76,9 @@ class Post
6376
*
6477
* @Groups({"searchable"})
6578
*/
79+
#[ORM\OneToMany(targetEntity: Comment::class, mappedBy: 'post', orphanRemoval: true)]
80+
#[ORM\OrderBy(['publishedAt' => 'DESC'])]
81+
#[Groups('searchable')]
6682
private $comments;
6783

6884
/**

tests/Entity/SelfNormalizable.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Meilisearch\Bundle\Tests\Entity;
66

7+
use Doctrine\DBAL\Types\Types;
78
use Doctrine\ORM\Mapping as ORM;
89
use Meilisearch\Bundle\Searchable;
910
use Symfony\Component\Serializer\Normalizer\NormalizableInterface;
@@ -12,23 +13,28 @@
1213
/**
1314
* @ORM\Entity
1415
*/
16+
#[ORM\Entity]
1517
class SelfNormalizable implements NormalizableInterface
1618
{
1719
/**
1820
* @ORM\Id
1921
*
2022
* @ORM\Column(type="integer")
2123
*/
24+
#[ORM\Id]
25+
#[ORM\Column(type: Types::INTEGER)]
2226
private int $id;
2327

2428
/**
2529
* @ORM\Column(type="string")
2630
*/
31+
#[ORM\Column(type: Types::STRING)]
2732
private string $name;
2833

2934
/**
3035
* @ORM\Column(type="datetime_immutable")
3136
*/
37+
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
3238
private \DateTimeImmutable $createdAt;
3339

3440
public function __construct(int $id, string $name)

tests/Entity/Tag.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Meilisearch\Bundle\Tests\Entity;
66

7+
use Doctrine\DBAL\Types\Types;
78
use Doctrine\ORM\Mapping as ORM;
89
use Meilisearch\Bundle\Searchable;
910
use Symfony\Component\Serializer\Exception\ExceptionInterface;
@@ -13,30 +14,36 @@
1314
/**
1415
* @ORM\Entity
1516
*/
17+
#[ORM\Entity]
1618
class Tag implements NormalizableInterface
1719
{
1820
/**
1921
* @ORM\Id
2022
*
2123
* @ORM\Column(type="integer", nullable=true)
2224
*/
25+
#[ORM\Id]
26+
#[ORM\Column(type: Types::INTEGER, nullable: true)]
2327
private ?int $id;
2428

2529
/**
2630
* @ORM\Column(type="string")
2731
*/
32+
#[ORM\Column(type: Types::STRING)]
2833
private string $name = '';
2934

3035
/**
3136
* @ORM\Column(type="smallint")
3237
*/
38+
#[ORM\Column(type: Types::SMALLINT)]
3339
private int $count = 0;
3440

3541
private bool $public = true;
3642

3743
/**
3844
* @ORM\Column(type="datetime")
3945
*/
46+
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
4047
private \DateTimeInterface $publishedAt;
4148

4249
public function __construct()

tests/Kernel.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ public function registerBundles(): array
3232

3333
public function registerContainerConfiguration(LoaderInterface $loader): void
3434
{
35-
$loader->load(__DIR__.'/config/config.yaml');
35+
if (PHP_VERSION_ID >= 80000) {
36+
$loader->load(__DIR__.'/config/config.yaml');
37+
} else {
38+
$loader->load(__DIR__.'/config/config_php7.yaml');
39+
}
3640
$loader->load(__DIR__.'/../config/services.xml');
3741
$loader->load(__DIR__.'/config/meilisearch.yaml');
3842
}

tests/config/config.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
framework:
22
test: true
33
secret: 67d829bf61dc5f87a73fd814e2c9f629
4-
annotations: true
5-
serializer:
6-
enable_annotations: true
74

85
doctrine:
96
dbal:
@@ -19,7 +16,7 @@ doctrine:
1916
mappings:
2017
App:
2118
is_bundle: false
22-
type: annotation
19+
type: attribute
2320
dir: '%kernel.project_dir%/tests/Entity'
2421
prefix: 'Meilisearch\Bundle\Tests\Entity'
2522
alias: App

0 commit comments

Comments
 (0)