diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7bcd5a6..338c6cb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,7 +15,7 @@ jobs: build: runs-on: "ubuntu-latest" - name: "PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, PHPUnit ${{ matrix.phpunit }}, PHP-Matcher ${{ matrix.php-matcher }}" + name: "PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, PHPUnit ${{ matrix.phpunit }}, PHP-Matcher ${{ matrix.php-matcher }}, Doctrine ORM ${{ matrix.orm }}" strategy: fail-fast: false @@ -24,6 +24,7 @@ jobs: symfony: [6.4.*, 7.0.*] phpunit: [^9.0, ^10.0, ^11.0] php-matcher: [^6.0] + orm: [^2.5, ^3.0] exclude: - php: 8.1 symfony: 7.0.* @@ -51,6 +52,10 @@ jobs: name: "Restrict coduo/php-matcher version" run: "composer require \"coduo/php-matcher:${{ matrix.php-matcher }}\" --no-update --no-scripts" + - + name: "Restrict doctrine/orm version" + run: "composer require \"doctrine/orm:${{ matrix.orm }}\" --no-update --no-scripts" + - name: "Restrict phpunit/phpunit version" run: "composer require \"phpunit/phpunit:${{ matrix.phpunit }}\" --no-update --no-scripts" diff --git a/composer.json b/composer.json index b8fce6d..eee4e8d 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ "openlss/lib-array2xml": "^1.0", "doctrine/data-fixtures": "^1.2", "doctrine/doctrine-bundle": "^2.0", - "doctrine/orm": "^2.5", + "doctrine/orm": "^2.5 || ^3.0", "nelmio/alice": "^3.6", "phpspec/php-diff": "^1.1", "phpunit/phpunit": "^9.0 || ^10.0 || ^11.0", diff --git a/src/ApiTestCase.php b/src/ApiTestCase.php index 6c2d3bb..68bccfe 100644 --- a/src/ApiTestCase.php +++ b/src/ApiTestCase.php @@ -103,7 +103,7 @@ public function setUpDatabase(): void Assert::notNull($entityManager); $this->entityManager = $entityManager; - $this->entityManager->getConnection()->connect(); + $this->entityManager->getConnection()->getNativeConnection(); /** @var LoaderInterface $fixtureLoader */ $fixtureLoader = $container->get('fidry_alice_data_fixtures.loader.doctrine'); diff --git a/test/app/AppKernel.php b/test/app/AppKernel.php index 587b4d5..9b96b51 100644 --- a/test/app/AppKernel.php +++ b/test/app/AppKernel.php @@ -65,11 +65,11 @@ public function registerContainerConfiguration(LoaderInterface $loader) 'auto_mapping' => false, 'mappings' => [ 'ApiTestCase' => [ - 'dir' => '%kernel.project_dir%/app/config/doctrine', + 'dir' => '%kernel.project_dir%/src/Entity', 'prefix' => 'ApiTestCase\Test\Entity', 'alias' => 'ApiTestCase', 'is_bundle' => false, - 'type' => 'yml', + 'type' => 'attribute', ], ], ], diff --git a/test/app/config/doctrine/Category.orm.yml b/test/app/config/doctrine/Category.orm.yml deleted file mode 100644 index 43d206a..0000000 --- a/test/app/config/doctrine/Category.orm.yml +++ /dev/null @@ -1,26 +0,0 @@ -ApiTestCase\Test\Entity\Category: - type: entity - table: test_category - id: - id: - type: integer - id: true - generator: - strategy: AUTO - fields: - name: - type: string - manyToMany: - products: - targetEntity: ApiTestCase\Test\Entity\Product - cascade: ["all"] - joinTable: - name: app_category_products - joinColumns: - category_id: - referencedColumnName: id - onDelete: "cascade" - inverseJoinColumns: - product_id: - referencedColumnName: id - onDelete: "cascade" diff --git a/test/app/config/doctrine/Product.orm.yml b/test/app/config/doctrine/Product.orm.yml deleted file mode 100644 index 01be61e..0000000 --- a/test/app/config/doctrine/Product.orm.yml +++ /dev/null @@ -1,16 +0,0 @@ -ApiTestCase\Test\Entity\Product: - type: entity - table: test_product - id: - id: - type: integer - id: true - generator: - strategy: AUTO - fields: - name: - type: string - price: - type: integer - uuid: - type: string diff --git a/test/src/Entity/Category.php b/test/src/Entity/Category.php index 41c0eb6..ab95405 100644 --- a/test/src/Entity/Category.php +++ b/test/src/Entity/Category.php @@ -15,17 +15,39 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; +use Doctrine\ORM\Mapping as ORM; +#[ORM\Entity] +#[ORM\Table(name: "test_category")] class Category { - /** @var int|null */ - private $id; + #[ORM\Id] + #[ORM\Column(type: "integer")] + #[ORM\GeneratedValue(strategy: "AUTO")] + private ?int $id; - /** @var string */ - private $name; + #[ORM\Column(type: "string")] + private string $name; - /** @var Collection|Product[] */ - private $products; + #[ORM\ManyToMany(targetEntity: Product::class, cascade: ["all"])] + #[ORM\JoinTable( + name: "app_category_products", + joinColumns: [ + new ORM\JoinColumn( + name: "category_id", + referencedColumnName: "id", + onDelete: "cascade" + ) + ], + inverseJoinColumns: [ + new ORM\JoinColumn( + name: "product_id", + referencedColumnName: "id", + onDelete: "cascade" + ) + ] + )] + private Collection $products; public function __construct() { @@ -58,9 +80,9 @@ public function removeProduct(Product $product): void } /** - * @return Collection|Product[] + * @return Product[] */ - public function getProducts() + public function getProducts(): Collection { return $this->products; } diff --git a/test/src/Entity/Product.php b/test/src/Entity/Product.php index 9a25ad8..fda415a 100644 --- a/test/src/Entity/Product.php +++ b/test/src/Entity/Product.php @@ -13,19 +13,25 @@ namespace ApiTestCase\Test\Entity; +use Doctrine\ORM\Mapping as ORM; + +#[ORM\Entity] +#[ORM\Table(name: "test_product")] class Product { - /** @var int|null */ - private $id; + #[ORM\Id] + #[ORM\Column(type: "integer")] + #[ORM\GeneratedValue(strategy: "AUTO")] + private ?int $id; - /** @var string */ - private $name; + #[ORM\Column(type: "string")] + private string $name; - /** @var int */ - private $price; + #[ORM\Column(type: "integer")] + private int $price; - /** @var string */ - private $uuid; + #[ORM\Column(type: "string")] + private string $uuid; public function getId(): ?int { @@ -57,10 +63,7 @@ public function getUuid(): string return $this->uuid; } - /** - * @param string $uuid - */ - public function setUuid($uuid): void + public function setUuid(string $uuid): void { $this->uuid = $uuid; }