Skip to content

Use PHP attributes in tests for PHP8+ #237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ jobs:
env:
SYMFONY_REQUIRE: ${{ matrix.sf-version }}
run: composer install --prefer-dist --no-progress --quiet
- name: "Remove doctrine/annotations"
if: matrix.php-version != '7.4'
run: |
composer remove --dev doctrine/annotations
- name: Meilisearch setup with Docker
run: docker run -d -p 7700:7700 getmeili/meilisearch:latest meilisearch --master-key=masterKey --no-analytics
- name: Run test suite
Expand Down
18 changes: 13 additions & 5 deletions tests/Entity/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Meilisearch\Bundle\Tests\Entity;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;

Expand All @@ -12,6 +13,8 @@
*
* @ORM\Table(name="comments")
*/
#[ORM\Entity]
#[ORM\Table(name: 'comments')]
class Comment
{
/**
Expand All @@ -23,27 +26,30 @@ class Comment
*
* @Groups({"searchable"})
*/
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER, nullable: true)]
#[Groups('searchable')]
private ?int $id = null;

/**
* @ORM\ManyToOne(targetEntity="Post", inversedBy="comments")
*
* @ORM\JoinColumn(nullable=false)
*/
#[ORM\ManyToOne(inversedBy: 'comments')]
#[ORM\JoinColumn(nullable: false)]
private ?Post $post = null;

/**
* @var string
*
* @ORM\Column(type="text")
* min=5,
* minMessage="comment.too_short",
* max=10000,
* maxMessage="comment.too_long"
* )
*
* @Groups({"searchable"})
*/
#[ORM\Column(type: Types::TEXT)]
#[Groups('searchable')]
private $content;

/**
Expand All @@ -53,6 +59,8 @@ class Comment
*
* @Groups({"searchable"})
*/
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
#[Groups('searchable')]
private $publishedAt;

/**
Expand Down
1 change: 1 addition & 0 deletions tests/Entity/ContentAggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/**
* @ORM\Entity
*/
#[ORM\Entity]
class ContentAggregator extends Aggregator
{
public function getIsVisible(): bool
Expand Down
1 change: 1 addition & 0 deletions tests/Entity/EmptyAggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/**
* @ORM\Entity
*/
#[ORM\Entity]
class EmptyAggregator extends Aggregator
{
}
6 changes: 6 additions & 0 deletions tests/Entity/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

namespace Meilisearch\Bundle\Tests\Entity;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
#[ORM\Entity]
class Image
{
/**
Expand All @@ -18,11 +20,15 @@ class Image
*
* @ORM\Column(type="integer")
*/
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
private ?int $id;

/**
* @ORM\Column(type="string")
*/
#[ORM\Column(type: Types::STRING)]
private string $url;

public function __construct()
Expand Down
7 changes: 7 additions & 0 deletions tests/Entity/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Meilisearch\Bundle\Tests\Entity;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Meilisearch\Bundle\Searchable;
use Symfony\Component\Serializer\Normalizer\NormalizableInterface;
Expand All @@ -12,28 +13,34 @@
/**
* @ORM\Entity
*/
#[ORM\Entity]
class Link implements NormalizableInterface
{
/**
* @ORM\Id
*
* @ORM\Column(type="integer")
*/
#[ORM\Id]
#[ORM\Column(type: Types::INTEGER)]
private int $id;

/**
* @ORM\Column(type="string")
*/
#[ORM\Column(type: Types::STRING)]
private string $name = 'Test link';

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

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

public function getId(): int
Expand Down
10 changes: 10 additions & 0 deletions tests/Entity/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Meilisearch\Bundle\Tests\Entity;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;

Expand All @@ -12,6 +13,8 @@
*
* @ORM\Table(name="pages")
*/
#[ORM\Entity]
#[ORM\Table(name: 'pages')]
class Page
{
/**
Expand All @@ -21,20 +24,27 @@ class Page
*
* @ORM\Column(type="object")
*/
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'NONE')]
#[ORM\Column(type: Types::OBJECT)]
private $id = null;

/**
* @ORM\Column(type="string", nullable=true)
*
* @Groups({"searchable"})
*/
#[ORM\Column(type: Types::STRING, nullable: true)]
#[Groups('searchable')]
private ?string $title = null;

/**
* @ORM\Column(type="text", nullable=true)
*
* @Groups({"searchable"})
*/
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups('searchable')]
private ?string $content = null;

public function getId()
Expand Down
18 changes: 17 additions & 1 deletion tests/Entity/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;

Expand All @@ -14,6 +15,8 @@
*
* @ORM\Table(name="posts")
*/
#[ORM\Entity]
#[ORM\Table(name: 'posts')]
class Post
{
/**
Expand All @@ -26,6 +29,10 @@ class Post
* @Groups({"searchable"})
* ^ Note that Groups work on private properties
*/
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
#[Groups('searchable')]
private ?int $id = null;

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

/**
* @ORM\Column(type="text", nullable=true)
*
* @Groups({"searchable"})
*/
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups('searchable')]
private ?string $content = null;

/**
* @ORM\Column(type="datetime")
*
* @Groups({"searchable"})
*/
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
#[Groups('searchable')]
private ?\DateTime $publishedAt = null;

/**
* @var Comment[]|Collection
* @var Collection<int, Comment>
*
* @ORM\OneToMany(
* targetEntity="Comment",
Expand All @@ -63,6 +76,9 @@ class Post
*
* @Groups({"searchable"})
*/
#[ORM\OneToMany(targetEntity: Comment::class, mappedBy: 'post', orphanRemoval: true)]
#[ORM\OrderBy(['publishedAt' => 'DESC'])]
#[Groups('searchable')]
private $comments;

/**
Expand Down
6 changes: 6 additions & 0 deletions tests/Entity/SelfNormalizable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Meilisearch\Bundle\Tests\Entity;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Meilisearch\Bundle\Searchable;
use Symfony\Component\Serializer\Normalizer\NormalizableInterface;
Expand All @@ -12,23 +13,28 @@
/**
* @ORM\Entity
*/
#[ORM\Entity]
class SelfNormalizable implements NormalizableInterface
{
/**
* @ORM\Id
*
* @ORM\Column(type="integer")
*/
#[ORM\Id]
#[ORM\Column(type: Types::INTEGER)]
private int $id;

/**
* @ORM\Column(type="string")
*/
#[ORM\Column(type: Types::STRING)]
private string $name;

/**
* @ORM\Column(type="datetime_immutable")
*/
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
private \DateTimeImmutable $createdAt;

public function __construct(int $id, string $name)
Expand Down
7 changes: 7 additions & 0 deletions tests/Entity/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Meilisearch\Bundle\Tests\Entity;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Meilisearch\Bundle\Searchable;
use Symfony\Component\Serializer\Exception\ExceptionInterface;
Expand All @@ -13,30 +14,36 @@
/**
* @ORM\Entity
*/
#[ORM\Entity]
class Tag implements NormalizableInterface
{
/**
* @ORM\Id
*
* @ORM\Column(type="integer", nullable=true)
*/
#[ORM\Id]
#[ORM\Column(type: Types::INTEGER, nullable: true)]
private ?int $id;

/**
* @ORM\Column(type="string")
*/
#[ORM\Column(type: Types::STRING)]
private string $name = '';

/**
* @ORM\Column(type="smallint")
*/
#[ORM\Column(type: Types::SMALLINT)]
private int $count = 0;

private bool $public = true;

/**
* @ORM\Column(type="datetime")
*/
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private \DateTimeInterface $publishedAt;

public function __construct()
Expand Down
6 changes: 5 additions & 1 deletion tests/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ public function registerBundles(): array

public function registerContainerConfiguration(LoaderInterface $loader): void
{
$loader->load(__DIR__.'/config/config.yaml');
if (PHP_VERSION_ID >= 80000) {
$loader->load(__DIR__.'/config/config.yaml');
} else {
$loader->load(__DIR__.'/config/config_php7.yaml');
}
$loader->load(__DIR__.'/../config/services.xml');
$loader->load(__DIR__.'/config/meilisearch.yaml');
}
Expand Down
5 changes: 1 addition & 4 deletions tests/config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
framework:
test: true
secret: 67d829bf61dc5f87a73fd814e2c9f629
annotations: true
serializer:
enable_annotations: true

doctrine:
dbal:
Expand All @@ -19,7 +16,7 @@ doctrine:
mappings:
App:
is_bundle: false
type: annotation
type: attribute
dir: '%kernel.project_dir%/tests/Entity'
prefix: 'Meilisearch\Bundle\Tests\Entity'
alias: App
Loading