Skip to content

Commit

Permalink
Merge pull request #200 from lchrusciel/support-doctrine-3
Browse files Browse the repository at this point in the history
[Maintenance] Add support for doctrine/orm 3.0
  • Loading branch information
lchrusciel authored Jul 29, 2024
2 parents 10bd0e8 + d275a0f commit 420bfe7
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 67 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.*
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/ApiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions test/app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
],
],
Expand Down
26 changes: 0 additions & 26 deletions test/app/config/doctrine/Category.orm.yml

This file was deleted.

16 changes: 0 additions & 16 deletions test/app/config/doctrine/Product.orm.yml

This file was deleted.

38 changes: 30 additions & 8 deletions test/src/Entity/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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;
}
Expand Down
27 changes: 15 additions & 12 deletions test/src/Entity/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 420bfe7

Please sign in to comment.