diff --git a/composer.json b/composer.json index 5c873cd0..83dbc1c8 100644 --- a/composer.json +++ b/composer.json @@ -51,11 +51,11 @@ "require": { "php": "~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0", "ext-json": "*", - "doctrine/dbal": "^2.13.7 || ^3.3.2", + "doctrine/dbal": "^2.13.7 || ^3.3.2 || ~4.0.0", "doctrine/doctrine-laminas-hydrator": "^3.0.0", "doctrine/doctrine-module": "^5.3.0 || ^6.0.2", - "doctrine/event-manager": "^1.1.1", - "doctrine/orm": "^2.11.1", + "doctrine/event-manager": "^1.1.1 || ^2.0.0", + "doctrine/orm": "^3.0.0", "doctrine/persistence": "^2.3.0 || ^3.0.0", "laminas/laminas-eventmanager": "^3.4.0", "laminas/laminas-modulemanager": "^2.11.0", @@ -63,12 +63,12 @@ "laminas/laminas-paginator": "^2.12.2", "laminas/laminas-servicemanager": "^3.17.0", "laminas/laminas-stdlib": "^3.7.1", - "psr/container": "^1.1.2", - "symfony/console": "^5.4.3 || ^6.0.3" + "psr/container": "^1.1.2 || ^2.0.0", + "symfony/console": "^5.4.3 || ^6.0.3 || ^7.0.0" }, "require-dev": { - "doctrine/annotations": "^1.13.2", - "doctrine/coding-standard": "^9.0.0", + "doctrine/annotations": "^2.0", + "doctrine/coding-standard": "^12.0.0", "doctrine/data-fixtures": "^1.5.2", "doctrine/migrations": "^3.4.1", "laminas/laminas-cache-storage-adapter-filesystem": "^2.0", @@ -80,7 +80,7 @@ "ocramius/proxy-manager": "^2.2.0", "phpstan/phpstan": "^1.4.6", "phpstan/phpstan-phpunit": "^1.0.0", - "phpunit/phpunit": "^9.5.13", + "phpunit/phpunit": "^10.0.0", "squizlabs/php_codesniffer": "^3.6.2", "vimeo/psalm": "^5.4.0" }, diff --git a/tests/Assets/Entity/Auth.php b/tests/Assets/Entity/Auth.php new file mode 100644 index 00000000..62b09e7d --- /dev/null +++ b/tests/Assets/Entity/Auth.php @@ -0,0 +1,60 @@ +id; + } + + public function setPassword(string $password): self + { + $this->password = $password; + + return $this; + } + + public function getPassword(): string|null + { + return $this->password; + } + + public function setUsername(string $username): self + { + $this->username = $username; + + return $this; + } + + public function getUsername(): string|null + { + return $this->username; + } + + /** + * Used for testing DoctrineEntity form element + */ + public function __toString(): string + { + return (string) $this->username; + } +} diff --git a/tests/Assets/Entity/Category.php b/tests/Assets/Entity/Category.php index 1a16f573..49eb1045 100644 --- a/tests/Assets/Entity/Category.php +++ b/tests/Assets/Entity/Category.php @@ -4,25 +4,30 @@ namespace DoctrineORMModuleTest\Assets\Entity; +use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - * @ORM\Table(name="doctrine_orm_module_category") - */ +#[ORM\Entity] +#[ORM\Table(name: 'doctrine_orm_module_category')] class Category { - /** - * @ORM\Id - * @ORM\Column(type="integer"); - * @ORM\GeneratedValue(strategy="AUTO") - */ + #[ORM\Id] + #[ORM\Column(type: 'integer')] + #[ORM\GeneratedValue(strategy: 'AUTO')] protected int $id; - /** @ORM\Column(type="string", nullable=true) */ + #[ORM\Column(type: 'string', nullable: true)] protected string $name; - public function getId(): ?int + #[ORM\ManyToMany(targetEntity: Product::class, mappedBy: 'categories')] + private ArrayCollection $products; + + public function __construct() + { + $this->products = new ArrayCollection(); + } + + public function getId(): int|null { return $this->id; } diff --git a/tests/Assets/Entity/City.php b/tests/Assets/Entity/City.php index 7dc8684f..1fb8682b 100644 --- a/tests/Assets/Entity/City.php +++ b/tests/Assets/Entity/City.php @@ -6,26 +6,23 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - * @ORM\Table(name="doctrine_orm_module_city") - */ +#[ORM\Entity] +#[ORM\Table(name: 'doctrine_orm_module_city')] class City { - /** - * @ORM\Id - * @ORM\Column(type="integer"); - * @ORM\GeneratedValue(strategy="AUTO") - */ + #[ORM\Id] + #[ORM\Column(type: 'integer')] + #[ORM\GeneratedValue(strategy: 'AUTO')] protected int $id; - /** @ORM\Column(type="string", nullable=true) */ + #[ORM\Column(type: 'string', nullable: true)] protected string $name; - /** @ORM\OneToOne(targetEntity="Country") */ + #[ORM\OneToOne(targetEntity: Country::class, inversedBy: 'city')] + #[ORM\JoinColumn(name: 'country_id', referencedColumnName: 'id', unique: true)] protected Country $country; - public function getId(): ?int + public function getId(): int|null { return $this->id; } diff --git a/tests/Assets/Entity/Country.php b/tests/Assets/Entity/Country.php index 882ad81b..45d35b20 100644 --- a/tests/Assets/Entity/Country.php +++ b/tests/Assets/Entity/Country.php @@ -6,23 +6,22 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - * @ORM\Table(name="doctrine_orm_module_country") - */ +#[ORM\Entity] +#[ORM\Table(name: 'doctrine_orm_module_country')] class Country { - /** - * @ORM\Id - * @ORM\Column(type="integer"); - * @ORM\GeneratedValue(strategy="AUTO") - */ + #[ORM\Id] + #[ORM\Column(type: 'integer')] + #[ORM\GeneratedValue(strategy: 'AUTO')] protected int $id; - /** @ORM\Column(type="string", nullable=true) */ + #[ORM\Column(type: 'string', nullable: true)] protected string $name; - public function getId(): ?int + #[ORM\OneToOne(targetEntity: City::class, mappedBy: 'country')] + private City $city; + + public function getId(): int|null { return $this->id; } diff --git a/tests/Assets/Entity/Date.php b/tests/Assets/Entity/Date.php index b7a09a3f..e0b99f85 100644 --- a/tests/Assets/Entity/Date.php +++ b/tests/Assets/Entity/Date.php @@ -7,30 +7,28 @@ use DateTime; use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - * @ORM\Table(name="doctrine_orm_module_date") - */ +#[ORM\Entity] +#[ORM\Table(name: 'doctrine_orm_module_date')] class Date { - /** - * @ORM\Id - * @ORM\Column(type="integer"); - * @ORM\GeneratedValue(strategy="AUTO") - */ + #[ORM\Id] + #[ORM\Column(type: 'integer')] + #[ORM\GeneratedValue(strategy: 'AUTO')] protected int $id; - /** @ORM\Column(type="date", nullable=true) */ + #[ORM\Column(type: 'date', nullable: true)] protected DateTime $date; - public function getId(): ?int + public function getId(): int|null { return $this->id; } - public function setDate(DateTime $date): void + public function setDate(DateTime $date): self { $this->date = $date; + + return $this; } public function getDate(): DateTime diff --git a/tests/Assets/Entity/Entity.skipper b/tests/Assets/Entity/Entity.skipper new file mode 100644 index 00000000..7e07d9cd --- /dev/null +++ b/tests/Assets/Entity/Entity.skipper @@ -0,0 +1,275 @@ + + + + + + + + AUTO + + + + + + + doctrine_orm_module_auth + Auth.php + + + + + + + AUTO + + + + + + doctrine_orm_module_date + Date.php + + + + + + + AUTO + + + + + EntityWithoutRepository.php + + + + + + + IDENTITY + + + + + doctrine_orm_module_form_entity_issue237 + Issue237.php + + + + + + + + + AUTO + + + + + + + doctrine_orm_module_city + City.php + + + + + + + AUTO + + + + + + doctrine_orm_module_country + Country.php + + + + + + + + + + + + + + + + + + + + + AUTO + + + + + + doctrine_orm_module_category + Category.php + + + + + + + AUTO + + + + + + doctrine_orm_module_product + Product.php + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + doctrine_orm_module_form_entity + FormEntity.php + + + + + + + AUTO + + + + + FormEntityTarget.php + + + + + + + AUTO + + + + + + ResolveTarget.php + + + + + + + AUTO + + + + + TargetEntity.php + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/Assets/Entity/EntityWithoutRepository.php b/tests/Assets/Entity/EntityWithoutRepository.php index 2a902425..a378230d 100644 --- a/tests/Assets/Entity/EntityWithoutRepository.php +++ b/tests/Assets/Entity/EntityWithoutRepository.php @@ -6,25 +6,23 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - */ +#[ORM\Entity] class EntityWithoutRepository { - /** - * @ORM\Id - * @ORM\Column(type="integer") - * @ORM\GeneratedValue(strategy="AUTO") - */ - private ?int $id = null; + #[ORM\Id] + #[ORM\Column(type: 'integer')] + #[ORM\GeneratedValue(strategy: 'AUTO')] + private int|null $id = null; - public function getId(): ?int + public function getId(): int|null { return $this->id; } - public function setId(int $id): void + public function setId(int $id): self { $this->id = $id; + + return $this; } } diff --git a/tests/Assets/Entity/FormEntity.php b/tests/Assets/Entity/FormEntity.php index 0e082771..209cde0d 100644 --- a/tests/Assets/Entity/FormEntity.php +++ b/tests/Assets/Entity/FormEntity.php @@ -9,119 +9,113 @@ use Doctrine\ORM\Mapping as ORM; use Laminas\Form\Annotation as Form; -/** - * @ORM\Entity - * @ORM\Table(name="doctrine_orm_module_form_entity") - */ +#[ORM\Entity] +#[ORM\Table(name: 'doctrine_orm_module_form_entity')] class FormEntity { - /** - * @ORM\Id - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\Column(type: 'integer')] protected int $id; - /** @ORM\Column(type="boolean") */ + #[ORM\Column(type: 'boolean', nullable: false)] protected bool $bool; - /** @ORM\Column(type="boolean") */ + #[ORM\Column(type: 'boolean', nullable: false)] protected bool $boolean; - /** @ORM\Column(type="float") */ + #[ORM\Column(type: 'float', nullable: false)] protected float $float; - /** @ORM\Column(type="bigint") */ - protected int $bigint; + #[ORM\Column(type: 'bigint', nullable: false)] + protected string $bigint; - /** @ORM\Column(type="integer") */ + #[ORM\Column(type: 'integer', nullable: false)] protected int $integer; - /** @ORM\Column(type="smallint") */ + #[ORM\Column(type: 'smallint', nullable: false)] protected int $smallint; - /** @ORM\Column(type="datetime") */ + #[ORM\Column(type: 'datetime', nullable: false)] protected DateTime $datetime; - /** @ORM\Column(type="datetime_immutable") */ - protected DateTime $datetimeImmutable; + #[ORM\Column(type: 'datetime_immutable', nullable: false)] + protected DateTimeImmutable $datetimeImmutable; - /** @ORM\Column(type="datetimetz") */ - protected DateTimeImmutable $datetimetz; + #[ORM\Column(type: 'datetimetz', nullable: false)] + protected DateTime $datetimetz; - /** @ORM\Column(type="datetimetz_immutable") */ + #[ORM\Column(type: 'datetimetz_immutable', nullable: false)] protected DateTimeImmutable $datetimetzImmutable; - /** @ORM\Column(type="date") */ + #[ORM\Column(type: 'date', nullable: false)] protected DateTime $date; - /** @ORM\Column(type="time") */ + #[ORM\Column(type: 'time', nullable: false)] protected DateTime $time; - /** @ORM\Column(type="text") */ + #[ORM\Column(type: 'text', nullable: false)] protected string $text; - /** @ORM\Column(type="string", nullable=false, length=20) */ + #[ORM\Column(type: 'string', length: 20, nullable: false)] protected string $string; - /** @ORM\Column(type="string", nullable=true) */ - protected ?string $stringNullable = null; + #[ORM\Column(type: 'string', nullable: true)] + protected string|null $stringNullable = null; - /** @ORM\OneToOne(targetEntity="Target") */ + /** + * This join is odd because the targetEntity exists only as an interface + **/ + #[ORM\OneToOne(targetEntity: Target::class)] protected Target $targetOne; /** - * @ORM\OneToOne(targetEntity="Target") - * @ORM\JoinColumn(nullable=true) + * This join is odd because the targetEntity exists only as an interface */ - protected ?Target $targetOneNullable = null; - - /** - * @ORM\OneToOne(targetEntity="Target") - * @ORM\JoinColumn(nullable=true) - * - * @Form\Type("DoctrineModule\Form\Element\ObjectSelect") - * @Form\Options({"empty_option":null}) - */ - protected ?Target $noDisplayEmptyOption = null; + #[ORM\OneToOne(targetEntity: Target::class)] + #[ORM\JoinColumn(nullable: true)] + protected Target|null $targetOneNullable = null; /** - * @ORM\OneToMany(targetEntity="FormEntityTarget", mappedBy="formEntity") - * - * @var Target[] + * @Form\Type("File") + * @Form\Options({"label":"Image"}) */ - protected array $targetMany; + #[ORM\Column(type: 'string', length: 256, nullable: true)] + #[ORM\JoinColumn(nullable: true)] + protected string $image; /** - * @ORM\Column(type="integer") - * * @Form\Options({"label":"Please Choose", "value_options":{"f":"false","t":"true"}}) * @Form\Type("Radio") */ + #[ORM\Column(type: 'integer')] protected int $specificType; /** - * @ORM\OneToMany(targetEntity="FormEntityTarget", mappedBy="formEntityMulti") - * + * @Form\Options({"label":"Please Choose", "value_options":{"f":"false","t":"true"}}) + * @Form\Attributes({"type":"textarea"}) + */ + #[ORM\Column(type: 'integer')] + protected int $specificAttributeType; + + /** * @Form\Type("DoctrineORMModule\Form\Element\EntityMultiCheckbox") * * @var FormEntityTarget[] */ + #[ORM\OneToMany(targetEntity: FormEntityTarget::class, mappedBy: 'formEntityMulti')] protected array $specificMultiType; - /** - * @ORM\Column(type="integer") - * - * @Form\Options({"label":"Please Choose", "value_options":{"f":"false","t":"true"}}) - * @Form\Attributes({"type":"textarea"}) - */ - protected int $specificAttributeType; + /** @var Target[] */ + #[ORM\OneToMany(targetEntity: FormEntityTarget::class, mappedBy: 'formEntity')] + protected array $targetMany; /** - * @ORM\Column(type="string", length=256) - * @ORM\JoinColumn(nullable=true) + * This join is odd because the targetEntity exists only as an interface * - * @Form\Type("File") - * @Form\Options({"label":"Image"}) + * @Form\Type("DoctrineModule\Form\Element\ObjectSelect") + * @Form\Options({"empty_option":null}) */ - protected string $image; + #[ORM\OneToOne(targetEntity: Target::class)] + #[ORM\JoinColumn(nullable: true)] + protected Target|null $noDisplayEmptyOption = null; } diff --git a/tests/Assets/Entity/FormEntityTarget.php b/tests/Assets/Entity/FormEntityTarget.php index 08676bf7..f25eb9b5 100644 --- a/tests/Assets/Entity/FormEntityTarget.php +++ b/tests/Assets/Entity/FormEntityTarget.php @@ -6,15 +6,11 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - */ +#[ORM\Entity] class FormEntityTarget { - /** - * @ORM\Id - * @ORM\Column(type="integer") - * @ORM\GeneratedValue(strategy="AUTO") - */ + #[ORM\Id] + #[ORM\Column(type: 'integer')] + #[ORM\GeneratedValue(strategy: 'AUTO')] protected int $id; } diff --git a/tests/Assets/Entity/Issue237.php b/tests/Assets/Entity/Issue237.php index 4e8008df..b2fc7e69 100644 --- a/tests/Assets/Entity/Issue237.php +++ b/tests/Assets/Entity/Issue237.php @@ -6,16 +6,12 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - * @ORM\Table(name="doctrine_orm_module_form_entity_issue237") - */ +#[ORM\Entity] +#[ORM\Table(name: 'doctrine_orm_module_form_entity_issue237')] class Issue237 { - /** - * @ORM\Id - * @ORM\Column(type="integer") - * @ORM\GeneratedValue(strategy="IDENTITY") - */ + #[ORM\Id] + #[ORM\Column(type: 'integer')] + #[ORM\GeneratedValue(strategy: 'IDENTITY')] protected int $id; } diff --git a/tests/Assets/Entity/Product.php b/tests/Assets/Entity/Product.php index a8cdba17..1a17ac60 100644 --- a/tests/Assets/Entity/Product.php +++ b/tests/Assets/Entity/Product.php @@ -4,32 +4,34 @@ namespace DoctrineORMModuleTest\Assets\Entity; +use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - * @ORM\Table(name="doctrine_orm_module_product") - */ +#[ORM\Entity] +#[ORM\Table(name: 'doctrine_orm_module_product')] class Product { - /** - * @ORM\Id - * @ORM\Column(type="integer"); - * @ORM\GeneratedValue(strategy="AUTO") - */ + #[ORM\Id] + #[ORM\Column(type: 'integer')] + #[ORM\GeneratedValue(strategy: 'AUTO')] protected int $id; - /** @ORM\Column(type="string", nullable=true) */ + #[ORM\Column(type: 'string', nullable: true)] protected string $name; - /** - * @ORM\ManyToMany(targetEntity="Category") - * - * @var Category[] - */ - protected array $categories; + /** @var Category[] */ + #[ORM\ManyToMany(targetEntity: Category::class, inversedBy: 'products')] + #[ORM\JoinTable(name: 'ProductCategory')] + #[ORM\JoinColumn(name: 'Product_id', referencedColumnName: 'id')] + #[ORM\InverseJoinColumn(name: 'Category_id', referencedColumnName: 'id')] + private ArrayCollection $categories; - public function getId(): ?int + public function __construct() + { + $this->categories = new ArrayCollection(); + } + + public function getId(): int|null { return $this->id; } @@ -46,20 +48,16 @@ public function getName(): string return $this->name; } - /** - * @param Category[] $categories - */ - public function setCategories(array $categories): self + /** @param Category[] $categories */ + public function setCategories(ArrayCollection $categories): self { $this->categories = $categories; return $this; } - /** - * @return Category[] - */ - public function getCategories(): array + /** @return Category[] */ + public function getCategories(): ArrayCollection { return $this->categories; } diff --git a/tests/Assets/Entity/ResolveTarget.php b/tests/Assets/Entity/ResolveTarget.php index 1c2a43f6..11012445 100644 --- a/tests/Assets/Entity/ResolveTarget.php +++ b/tests/Assets/Entity/ResolveTarget.php @@ -6,18 +6,15 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - */ +#[ORM\Entity] class ResolveTarget { - /** - * @ORM\Id - * @ORM\Column(type="integer") - * @ORM\GeneratedValue(strategy="AUTO") - */ + #[ORM\Id] + #[ORM\Column(type: 'integer')] + #[ORM\GeneratedValue(strategy: 'AUTO')] protected int $id; - /** @ORM\OneToOne(targetEntity="Target") */ + #[ORM\ManyToOne(targetEntity: Target::class)] + #[ORM\JoinColumn(name: 'target_id', referencedColumnName: 'id', unique: true)] protected Target $target; } diff --git a/tests/Assets/Entity/TargetEntity.php b/tests/Assets/Entity/TargetEntity.php index d252c78a..0cdc8c1f 100644 --- a/tests/Assets/Entity/TargetEntity.php +++ b/tests/Assets/Entity/TargetEntity.php @@ -6,16 +6,12 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - */ +#[ORM\Entity] class TargetEntity implements Target { - /** - * @ORM\Id - * @ORM\Column(type="integer") - * @ORM\GeneratedValue(strategy="AUTO") - */ + #[ORM\Id] + #[ORM\Column(type: 'integer')] + #[ORM\GeneratedValue(strategy: 'AUTO')] private int $id; public function getId(): int @@ -23,8 +19,10 @@ public function getId(): int return $this->id; } - public function setId(int $id): void + public function setId(int $id): self { $this->id = $id; + + return $this; } } diff --git a/tests/Assets/Entity/Test.php b/tests/Assets/Entity/Test.php deleted file mode 100644 index 93a2274c..00000000 --- a/tests/Assets/Entity/Test.php +++ /dev/null @@ -1,60 +0,0 @@ -id; - } - - public function setPassword(string $password): void - { - $this->password = (string) $password; - } - - public function getPassword(): ?string - { - return $this->password; - } - - public function setUsername(string $username): void - { - $this->username = (string) $username; - } - - public function getUsername(): ?string - { - return $this->username; - } - - /** - * Used for testing DoctrineEntity form element - */ - public function __toString(): string - { - return (string) $this->username; - } -}