Skip to content

Commit

Permalink
[Maintenance] MIgrate to attributes on class definition
Browse files Browse the repository at this point in the history
  • Loading branch information
lchrusciel committed Jul 29, 2024
1 parent fc9bfb0 commit d275a0f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 64 deletions.
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 d275a0f

Please sign in to comment.