From 6bc81b174c4c56d853115b141832f2702d0ff3d9 Mon Sep 17 00:00:00 2001 From: Nicolas PHILIPPE Date: Tue, 6 Dec 2022 13:41:55 +0100 Subject: [PATCH] refactor: set all fixtures class name unique (#374) --- .../{Category.php => ODMCategory.php} | 2 +- .../Document/{Comment.php => ODMComment.php} | 10 +- .../Document/{Post.php => ODMPost.php} | 16 ++-- .../Fixtures/Document/{Tag.php => ODMTag.php} | 2 +- .../Document/{User.php => ODMUser.php} | 2 +- tests/Fixtures/Entity/Cascade/Product.php | 12 +-- .../{Category.php => ProductCategory.php} | 2 +- .../Cascade/{Tag.php => ProductTag.php} | 2 +- .../Factories/ODM/CategoryFactory.php | 4 +- .../Fixtures/Factories/ODM/CommentFactory.php | 8 +- tests/Fixtures/Factories/ODM/PostFactory.php | 14 +-- tests/Fixtures/Factories/ODM/TagFactory.php | 4 +- tests/Fixtures/Factories/ODM/UserFactory.php | 4 +- ...factory_for_odm_with_data_set_document.php | 38 ++++---- ...or_odm_with_data_set_embedded_document.php | 38 ++++---- ...tory_with_embeddable_with_data_set_odm.php | 38 ++++---- .../Migrations/Version20210218175742.php | 36 ------- .../Migrations/Version20210318175742.php | 34 ------- .../Migrations/Version20210820131815.php | 46 --------- .../Migrations/Version20220925092226.php | 62 ------------- .../Migrations/Version20220925092634.php | 42 --------- .../Migrations/Version20221010154036.php | 38 -------- .../Migrations/Version20221117081744.php | 54 ----------- .../Migrations/Version20221124123656.php | 38 -------- .../Migrations/Version20221204165429.php | 93 +++++++++++++++++++ .../Migrations/Version20221204165430.php | 65 +++++++++++++ .../Bundle/Maker/MakeFactoryTest.php | 74 +++++---------- .../Functional/FactoryDoctrineCascadeTest.php | 8 +- tests/Functional/ODMAnonymousFactoryTest.php | 4 +- tests/Functional/ODMModelFactoryTest.php | 20 ++-- tests/Functional/ODMProxyTest.php | 4 +- tests/Functional/ODMRepositoryProxyTest.php | 4 +- 32 files changed, 300 insertions(+), 518 deletions(-) rename tests/Fixtures/Document/{Category.php => ODMCategory.php} (97%) rename tests/Fixtures/Document/{Comment.php => ODMComment.php} (87%) rename tests/Fixtures/Document/{Post.php => ODMPost.php} (85%) rename tests/Fixtures/Document/{Tag.php => ODMTag.php} (97%) rename tests/Fixtures/Document/{User.php => ODMUser.php} (96%) rename tests/Fixtures/Entity/Cascade/{Category.php => ProductCategory.php} (97%) rename tests/Fixtures/Entity/Cascade/{Tag.php => ProductTag.php} (98%) delete mode 100644 tests/Fixtures/Migrations/Version20210218175742.php delete mode 100644 tests/Fixtures/Migrations/Version20210318175742.php delete mode 100644 tests/Fixtures/Migrations/Version20210820131815.php delete mode 100644 tests/Fixtures/Migrations/Version20220925092226.php delete mode 100644 tests/Fixtures/Migrations/Version20220925092634.php delete mode 100644 tests/Fixtures/Migrations/Version20221010154036.php delete mode 100644 tests/Fixtures/Migrations/Version20221117081744.php delete mode 100644 tests/Fixtures/Migrations/Version20221124123656.php create mode 100644 tests/Fixtures/Migrations/Version20221204165429.php create mode 100644 tests/Fixtures/Migrations/Version20221204165430.php diff --git a/tests/Fixtures/Document/Category.php b/tests/Fixtures/Document/ODMCategory.php similarity index 97% rename from tests/Fixtures/Document/Category.php rename to tests/Fixtures/Document/ODMCategory.php index b35ac9fe8..2cbbff0af 100644 --- a/tests/Fixtures/Document/Category.php +++ b/tests/Fixtures/Document/ODMCategory.php @@ -7,7 +7,7 @@ /** * @MongoDB\Document(collection="category") */ -class Category +class ODMCategory { /** * @MongoDB\Id diff --git a/tests/Fixtures/Document/Comment.php b/tests/Fixtures/Document/ODMComment.php similarity index 87% rename from tests/Fixtures/Document/Comment.php rename to tests/Fixtures/Document/ODMComment.php index d7b0b5f79..cccc63f30 100644 --- a/tests/Fixtures/Document/Comment.php +++ b/tests/Fixtures/Document/ODMComment.php @@ -7,14 +7,14 @@ /** * @MongoDB\EmbeddedDocument */ -class Comment +class ODMComment { /** * @MongoDB\EmbedOne( - * targetDocument=User::class + * targetDocument=ODMUser::class * ) */ - private User $user; + private ODMUser $user; /** * @MongoDB\Field(type="string") @@ -31,14 +31,14 @@ class Comment */ private $approved = false; - public function __construct(User $user, string $body) + public function __construct(ODMUser $user, string $body) { $this->user = $user; $this->body = $body; $this->createdAt = new \DateTime('now'); } - public function getUser(): User + public function getUser(): ODMUser { return $this->user; } diff --git a/tests/Fixtures/Document/Post.php b/tests/Fixtures/Document/ODMPost.php similarity index 85% rename from tests/Fixtures/Document/Post.php rename to tests/Fixtures/Document/ODMPost.php index 5bd1e5a19..e3220bf78 100644 --- a/tests/Fixtures/Document/Post.php +++ b/tests/Fixtures/Document/ODMPost.php @@ -9,7 +9,7 @@ /** * @MongoDB\Document(collection="post") */ -class Post implements \Stringable +class ODMPost implements \Stringable { /** * @MongoDB\Id @@ -48,19 +48,19 @@ class Post implements \Stringable /** * @MongoDB\EmbedMany( - * targetDocument=Comment::class + * targetDocument=ODMComment::class * ) */ private $comments; /** * @MongoDB\EmbedOne( - * targetDocument=User::class + * targetDocument=ODMUser::class * ) */ private $user; - public function __construct(string $title, string $body, User $user, ?string $shortDescription = null) + public function __construct(string $title, string $body, ODMUser $user, ?string $shortDescription = null) { $this->title = $title; $this->body = $body; @@ -85,7 +85,7 @@ public function getBody(): ?string return $this->body; } - public function getUser(): User + public function getUser(): ODMUser { return $this->user; } @@ -121,14 +121,14 @@ public function setPublishedAt(\DateTime $timestamp): void } /** - * @return Collection + * @return Collection */ public function getComments(): Collection { return $this->comments; } - public function addComment(Comment $comment): self + public function addComment(ODMComment $comment): self { if (!$this->comments->contains($comment)) { $this->comments->add($comment); @@ -137,7 +137,7 @@ public function addComment(Comment $comment): self return $this; } - public function removeComment(Comment $comment): self + public function removeComment(ODMComment $comment): self { if ($this->comments->contains($comment)) { $this->comments->removeElement($comment); diff --git a/tests/Fixtures/Document/Tag.php b/tests/Fixtures/Document/ODMTag.php similarity index 97% rename from tests/Fixtures/Document/Tag.php rename to tests/Fixtures/Document/ODMTag.php index bbdc74cda..f0e605166 100644 --- a/tests/Fixtures/Document/Tag.php +++ b/tests/Fixtures/Document/ODMTag.php @@ -7,7 +7,7 @@ /** * @MongoDB\Document(collection="tag") */ -class Tag +class ODMTag { /** * @MongoDB\Id diff --git a/tests/Fixtures/Document/User.php b/tests/Fixtures/Document/ODMUser.php similarity index 96% rename from tests/Fixtures/Document/User.php rename to tests/Fixtures/Document/ODMUser.php index ea78a6aa4..809ee35b3 100644 --- a/tests/Fixtures/Document/User.php +++ b/tests/Fixtures/Document/ODMUser.php @@ -7,7 +7,7 @@ /** * @MongoDB\EmbeddedDocument */ -class User +class ODMUser { /** * @MongoDB\Field(type="string") diff --git a/tests/Fixtures/Entity/Cascade/Product.php b/tests/Fixtures/Entity/Cascade/Product.php index 1c9da057c..4a1c309c5 100644 --- a/tests/Fixtures/Entity/Cascade/Product.php +++ b/tests/Fixtures/Entity/Cascade/Product.php @@ -35,12 +35,12 @@ class Product private Collection $variants; /** - * @ORM\ManyToMany(targetEntity=Category::class, mappedBy="products", cascade={"persist"}) + * @ORM\ManyToMany(targetEntity=ProductCategory::class, mappedBy="products", cascade={"persist"}) */ private Collection $categories; /** - * @ORM\ManyToMany(targetEntity=Tag::class, inversedBy="products", cascade={"persist"}) + * @ORM\ManyToMany(targetEntity=ProductTag::class, inversedBy="products", cascade={"persist"}) */ private Collection $tags; @@ -116,14 +116,14 @@ public function getCategories(): Collection return $this->categories; } - public function addCategory(Category $category): void + public function addCategory(ProductCategory $category): void { if (!$this->categories->contains($category)) { $this->categories[] = $category; } } - public function removeCategory(Category $category): void + public function removeCategory(ProductCategory $category): void { if ($this->categories->contains($category)) { $this->categories->removeElement($category); @@ -135,14 +135,14 @@ public function getTags(): Collection return $this->tags; } - public function addTag(Tag $tag): void + public function addTag(ProductTag $tag): void { if (!$this->tags->contains($tag)) { $this->tags[] = $tag; } } - public function removeTag(Tag $tag): void + public function removeTag(ProductTag $tag): void { if ($this->tags->contains($tag)) { $this->tags->removeElement($tag); diff --git a/tests/Fixtures/Entity/Cascade/Category.php b/tests/Fixtures/Entity/Cascade/ProductCategory.php similarity index 97% rename from tests/Fixtures/Entity/Cascade/Category.php rename to tests/Fixtures/Entity/Cascade/ProductCategory.php index e2ccc966f..5bb5f94d4 100644 --- a/tests/Fixtures/Entity/Cascade/Category.php +++ b/tests/Fixtures/Entity/Cascade/ProductCategory.php @@ -10,7 +10,7 @@ * @ORM\Entity * @ORM\Table(name="category_cascade") */ -class Category +class ProductCategory { /** * @ORM\Id diff --git a/tests/Fixtures/Entity/Cascade/Tag.php b/tests/Fixtures/Entity/Cascade/ProductTag.php similarity index 98% rename from tests/Fixtures/Entity/Cascade/Tag.php rename to tests/Fixtures/Entity/Cascade/ProductTag.php index c821e366c..5992520c6 100644 --- a/tests/Fixtures/Entity/Cascade/Tag.php +++ b/tests/Fixtures/Entity/Cascade/ProductTag.php @@ -10,7 +10,7 @@ * @ORM\Entity * @ORM\Table(name="tag_cascade") */ -class Tag +class ProductTag { /** * @ORM\Id diff --git a/tests/Fixtures/Factories/ODM/CategoryFactory.php b/tests/Fixtures/Factories/ODM/CategoryFactory.php index 9461d7911..3b96d2b46 100644 --- a/tests/Fixtures/Factories/ODM/CategoryFactory.php +++ b/tests/Fixtures/Factories/ODM/CategoryFactory.php @@ -3,7 +3,7 @@ namespace Zenstruck\Foundry\Tests\Fixtures\Factories\ODM; use Zenstruck\Foundry\ModelFactory; -use Zenstruck\Foundry\Tests\Fixtures\Document\Category; +use Zenstruck\Foundry\Tests\Fixtures\Document\ODMCategory; /** * @author Kevin Bond @@ -12,7 +12,7 @@ final class CategoryFactory extends ModelFactory { protected static function getClass(): string { - return Category::class; + return ODMCategory::class; } protected function getDefaults(): array diff --git a/tests/Fixtures/Factories/ODM/CommentFactory.php b/tests/Fixtures/Factories/ODM/CommentFactory.php index 42ab31eea..446a43aca 100644 --- a/tests/Fixtures/Factories/ODM/CommentFactory.php +++ b/tests/Fixtures/Factories/ODM/CommentFactory.php @@ -3,20 +3,20 @@ namespace Zenstruck\Foundry\Tests\Fixtures\Factories\ODM; use Zenstruck\Foundry\ModelFactory; -use Zenstruck\Foundry\Tests\Fixtures\Document\Comment; -use Zenstruck\Foundry\Tests\Fixtures\Document\User; +use Zenstruck\Foundry\Tests\Fixtures\Document\ODMComment; +use Zenstruck\Foundry\Tests\Fixtures\Document\ODMUser; class CommentFactory extends ModelFactory { protected static function getClass(): string { - return Comment::class; + return ODMComment::class; } protected function getDefaults(): array { return [ - 'user' => new User(self::faker()->userName()), + 'user' => new ODMUser(self::faker()->userName()), 'body' => self::faker()->sentence(), ]; } diff --git a/tests/Fixtures/Factories/ODM/PostFactory.php b/tests/Fixtures/Factories/ODM/PostFactory.php index 71c9606ae..1c381127e 100644 --- a/tests/Fixtures/Factories/ODM/PostFactory.php +++ b/tests/Fixtures/Factories/ODM/PostFactory.php @@ -4,9 +4,9 @@ use Doctrine\Common\Collections\ArrayCollection; use Zenstruck\Foundry\ModelFactory; -use Zenstruck\Foundry\Tests\Fixtures\Document\Comment; -use Zenstruck\Foundry\Tests\Fixtures\Document\Post; -use Zenstruck\Foundry\Tests\Fixtures\Document\User; +use Zenstruck\Foundry\Tests\Fixtures\Document\ODMComment; +use Zenstruck\Foundry\Tests\Fixtures\Document\ODMPost; +use Zenstruck\Foundry\Tests\Fixtures\Document\ODMUser; class PostFactory extends ModelFactory { @@ -19,15 +19,15 @@ public function withComments(): static { return $this->addState(static fn(): array => [ 'comments' => new ArrayCollection([ - new Comment(new User('user'), 'body'), - new Comment(new User('user'), 'body'), + new ODMComment(new ODMUser('user'), 'body'), + new ODMComment(new ODMUser('user'), 'body'), ]), ]); } protected static function getClass(): string { - return Post::class; + return ODMPost::class; } protected function getDefaults(): array @@ -35,7 +35,7 @@ protected function getDefaults(): array return [ 'title' => self::faker()->sentence(), 'body' => self::faker()->sentence(), - 'user' => new User('user'), + 'user' => new ODMUser('user'), ]; } } diff --git a/tests/Fixtures/Factories/ODM/TagFactory.php b/tests/Fixtures/Factories/ODM/TagFactory.php index 2687aedf4..f2f795181 100644 --- a/tests/Fixtures/Factories/ODM/TagFactory.php +++ b/tests/Fixtures/Factories/ODM/TagFactory.php @@ -3,7 +3,7 @@ namespace Zenstruck\Foundry\Tests\Fixtures\Factories\ODM; use Zenstruck\Foundry\ModelFactory; -use Zenstruck\Foundry\Tests\Fixtures\Document\Tag; +use Zenstruck\Foundry\Tests\Fixtures\Document\ODMTag; /** * @author Kevin Bond @@ -12,7 +12,7 @@ final class TagFactory extends ModelFactory { protected static function getClass(): string { - return Tag::class; + return ODMTag::class; } protected function getDefaults(): array diff --git a/tests/Fixtures/Factories/ODM/UserFactory.php b/tests/Fixtures/Factories/ODM/UserFactory.php index 9975dc9eb..ee7868cec 100644 --- a/tests/Fixtures/Factories/ODM/UserFactory.php +++ b/tests/Fixtures/Factories/ODM/UserFactory.php @@ -3,13 +3,13 @@ namespace Zenstruck\Foundry\Tests\Fixtures\Factories\ODM; use Zenstruck\Foundry\ModelFactory; -use Zenstruck\Foundry\Tests\Fixtures\Document\User; +use Zenstruck\Foundry\Tests\Fixtures\Document\ODMUser; final class UserFactory extends ModelFactory { protected static function getClass(): string { - return User::class; + return ODMUser::class; } protected function getDefaults(): array diff --git a/tests/Fixtures/Maker/expected/can_create_factory_for_odm_with_data_set_document.php b/tests/Fixtures/Maker/expected/can_create_factory_for_odm_with_data_set_document.php index b86867f5e..142e51cc5 100644 --- a/tests/Fixtures/Maker/expected/can_create_factory_for_odm_with_data_set_document.php +++ b/tests/Fixtures/Maker/expected/can_create_factory_for_odm_with_data_set_document.php @@ -4,27 +4,27 @@ use Zenstruck\Foundry\ModelFactory; use Zenstruck\Foundry\Proxy; -use Zenstruck\Foundry\Tests\Fixtures\Document\Post; +use Zenstruck\Foundry\Tests\Fixtures\Document\ODMPost; /** - * @extends ModelFactory + * @extends ModelFactory * - * @method Post|Proxy create(array|callable $attributes = []) - * @method static Post|Proxy createOne(array $attributes = []) - * @method static Post|Proxy find(object|array|mixed $criteria) - * @method static Post|Proxy findOrCreate(array $attributes) - * @method static Post|Proxy first(string $sortedField = 'id') - * @method static Post|Proxy last(string $sortedField = 'id') - * @method static Post|Proxy random(array $attributes = []) - * @method static Post|Proxy randomOrCreate(array $attributes = []) - * @method static Post[]|Proxy[] all() - * @method static Post[]|Proxy[] createMany(int $number, array|callable $attributes = []) - * @method static Post[]|Proxy[] createSequence(array|callable $sequence) - * @method static Post[]|Proxy[] findBy(array $attributes) - * @method static Post[]|Proxy[] randomRange(int $min, int $max, array $attributes = []) - * @method static Post[]|Proxy[] randomSet(int $number, array $attributes = []) + * @method ODMPost|Proxy create(array|callable $attributes = []) + * @method static ODMPost|Proxy createOne(array $attributes = []) + * @method static ODMPost|Proxy find(object|array|mixed $criteria) + * @method static ODMPost|Proxy findOrCreate(array $attributes) + * @method static ODMPost|Proxy first(string $sortedField = 'id') + * @method static ODMPost|Proxy last(string $sortedField = 'id') + * @method static ODMPost|Proxy random(array $attributes = []) + * @method static ODMPost|Proxy randomOrCreate(array $attributes = []) + * @method static ODMPost[]|Proxy[] all() + * @method static ODMPost[]|Proxy[] createMany(int $number, array|callable $attributes = []) + * @method static ODMPost[]|Proxy[] createSequence(array|callable $sequence) + * @method static ODMPost[]|Proxy[] findBy(array $attributes) + * @method static ODMPost[]|Proxy[] randomRange(int $min, int $max, array $attributes = []) + * @method static ODMPost[]|Proxy[] randomSet(int $number, array $attributes = []) */ -final class PostFactory extends ModelFactory +final class ODMPostFactory extends ModelFactory { /** * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services @@ -57,12 +57,12 @@ protected function getDefaults(): array protected function initialize(): self { return $this - // ->afterInstantiate(function(Post $post): void {}) + // ->afterInstantiate(function(ODMPost $oDMPost): void {}) ; } protected static function getClass(): string { - return Post::class; + return ODMPost::class; } } diff --git a/tests/Fixtures/Maker/expected/can_create_factory_for_odm_with_data_set_embedded_document.php b/tests/Fixtures/Maker/expected/can_create_factory_for_odm_with_data_set_embedded_document.php index a92c318ee..f00d8b0ad 100644 --- a/tests/Fixtures/Maker/expected/can_create_factory_for_odm_with_data_set_embedded_document.php +++ b/tests/Fixtures/Maker/expected/can_create_factory_for_odm_with_data_set_embedded_document.php @@ -4,28 +4,28 @@ use Zenstruck\Foundry\ModelFactory; use Zenstruck\Foundry\Proxy; -use Zenstruck\Foundry\Tests\Fixtures\Document\Comment; +use Zenstruck\Foundry\Tests\Fixtures\Document\ODMComment; use Zenstruck\Foundry\Tests\Fixtures\Factories\ODM\UserFactory; /** - * @extends ModelFactory + * @extends ModelFactory * - * @method Comment|Proxy create(array|callable $attributes = []) - * @method static Comment|Proxy createOne(array $attributes = []) - * @method static Comment|Proxy find(object|array|mixed $criteria) - * @method static Comment|Proxy findOrCreate(array $attributes) - * @method static Comment|Proxy first(string $sortedField = 'id') - * @method static Comment|Proxy last(string $sortedField = 'id') - * @method static Comment|Proxy random(array $attributes = []) - * @method static Comment|Proxy randomOrCreate(array $attributes = []) - * @method static Comment[]|Proxy[] all() - * @method static Comment[]|Proxy[] createMany(int $number, array|callable $attributes = []) - * @method static Comment[]|Proxy[] createSequence(array|callable $sequence) - * @method static Comment[]|Proxy[] findBy(array $attributes) - * @method static Comment[]|Proxy[] randomRange(int $min, int $max, array $attributes = []) - * @method static Comment[]|Proxy[] randomSet(int $number, array $attributes = []) + * @method ODMComment|Proxy create(array|callable $attributes = []) + * @method static ODMComment|Proxy createOne(array $attributes = []) + * @method static ODMComment|Proxy find(object|array|mixed $criteria) + * @method static ODMComment|Proxy findOrCreate(array $attributes) + * @method static ODMComment|Proxy first(string $sortedField = 'id') + * @method static ODMComment|Proxy last(string $sortedField = 'id') + * @method static ODMComment|Proxy random(array $attributes = []) + * @method static ODMComment|Proxy randomOrCreate(array $attributes = []) + * @method static ODMComment[]|Proxy[] all() + * @method static ODMComment[]|Proxy[] createMany(int $number, array|callable $attributes = []) + * @method static ODMComment[]|Proxy[] createSequence(array|callable $sequence) + * @method static ODMComment[]|Proxy[] findBy(array $attributes) + * @method static ODMComment[]|Proxy[] randomRange(int $min, int $max, array $attributes = []) + * @method static ODMComment[]|Proxy[] randomSet(int $number, array $attributes = []) */ -final class CommentFactory extends ModelFactory +final class ODMCommentFactory extends ModelFactory { /** * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services @@ -58,12 +58,12 @@ protected function getDefaults(): array protected function initialize(): self { return $this - // ->afterInstantiate(function(Comment $comment): void {}) + // ->afterInstantiate(function(ODMComment $oDMComment): void {}) ; } protected static function getClass(): string { - return Comment::class; + return ODMComment::class; } } diff --git a/tests/Fixtures/Maker/expected/can_create_factory_with_embeddable_with_data_set_odm.php b/tests/Fixtures/Maker/expected/can_create_factory_with_embeddable_with_data_set_odm.php index ed9835793..18237c825 100644 --- a/tests/Fixtures/Maker/expected/can_create_factory_with_embeddable_with_data_set_odm.php +++ b/tests/Fixtures/Maker/expected/can_create_factory_with_embeddable_with_data_set_odm.php @@ -4,29 +4,29 @@ use Zenstruck\Foundry\ModelFactory; use Zenstruck\Foundry\Proxy; -use Zenstruck\Foundry\Tests\Fixtures\Document\Post; +use Zenstruck\Foundry\Tests\Fixtures\Document\ODMPost; use Zenstruck\Foundry\Tests\Fixtures\Factories\ODM\CommentFactory; use Zenstruck\Foundry\Tests\Fixtures\Factories\ODM\UserFactory; /** - * @extends ModelFactory + * @extends ModelFactory * - * @method Post|Proxy create(array|callable $attributes = []) - * @method static Post|Proxy createOne(array $attributes = []) - * @method static Post|Proxy find(object|array|mixed $criteria) - * @method static Post|Proxy findOrCreate(array $attributes) - * @method static Post|Proxy first(string $sortedField = 'id') - * @method static Post|Proxy last(string $sortedField = 'id') - * @method static Post|Proxy random(array $attributes = []) - * @method static Post|Proxy randomOrCreate(array $attributes = []) - * @method static Post[]|Proxy[] all() - * @method static Post[]|Proxy[] createMany(int $number, array|callable $attributes = []) - * @method static Post[]|Proxy[] createSequence(array|callable $sequence) - * @method static Post[]|Proxy[] findBy(array $attributes) - * @method static Post[]|Proxy[] randomRange(int $min, int $max, array $attributes = []) - * @method static Post[]|Proxy[] randomSet(int $number, array $attributes = []) + * @method ODMPost|Proxy create(array|callable $attributes = []) + * @method static ODMPost|Proxy createOne(array $attributes = []) + * @method static ODMPost|Proxy find(object|array|mixed $criteria) + * @method static ODMPost|Proxy findOrCreate(array $attributes) + * @method static ODMPost|Proxy first(string $sortedField = 'id') + * @method static ODMPost|Proxy last(string $sortedField = 'id') + * @method static ODMPost|Proxy random(array $attributes = []) + * @method static ODMPost|Proxy randomOrCreate(array $attributes = []) + * @method static ODMPost[]|Proxy[] all() + * @method static ODMPost[]|Proxy[] createMany(int $number, array|callable $attributes = []) + * @method static ODMPost[]|Proxy[] createSequence(array|callable $sequence) + * @method static ODMPost[]|Proxy[] findBy(array $attributes) + * @method static ODMPost[]|Proxy[] randomRange(int $min, int $max, array $attributes = []) + * @method static ODMPost[]|Proxy[] randomSet(int $number, array $attributes = []) */ -final class PostFactory extends ModelFactory +final class ODMPostFactory extends ModelFactory { /** * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services @@ -63,12 +63,12 @@ protected function getDefaults(): array protected function initialize(): self { return $this - // ->afterInstantiate(function(Post $post): void {}) + // ->afterInstantiate(function(ODMPost $oDMPost): void {}) ; } protected static function getClass(): string { - return Post::class; + return ODMPost::class; } } diff --git a/tests/Fixtures/Migrations/Version20210218175742.php b/tests/Fixtures/Migrations/Version20210218175742.php deleted file mode 100644 index a6e2a5566..000000000 --- a/tests/Fixtures/Migrations/Version20210218175742.php +++ /dev/null @@ -1,36 +0,0 @@ -addSql('CREATE TABLE categories (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE comments (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, post_id INT NOT NULL, body LONGTEXT NOT NULL, createdAt DATETIME NOT NULL, approved TINYINT(1) NOT NULL, INDEX IDX_5F9E962AA76ED395 (user_id), INDEX IDX_5F9E962A4B89032C (post_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE contacts (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, address_value VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE posts (id INT AUTO_INCREMENT NOT NULL, category_id INT DEFAULT NULL, title VARCHAR(255) NOT NULL, body LONGTEXT NOT NULL, shortDescription VARCHAR(255) DEFAULT NULL, viewCount INT NOT NULL, createdAt DATETIME NOT NULL, publishedAt DATETIME DEFAULT NULL, INDEX IDX_885DBAFA12469DE2 (category_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE post_tag (post_id INT NOT NULL, tag_id INT NOT NULL, INDEX IDX_5ACE3AF04B89032C (post_id), INDEX IDX_5ACE3AF0BAD26311 (tag_id), PRIMARY KEY(post_id, tag_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE tags (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE users (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - } - - public function down(Schema $schema): void - { - } - - public function isTransactional(): bool - { - return false; - } -} diff --git a/tests/Fixtures/Migrations/Version20210318175742.php b/tests/Fixtures/Migrations/Version20210318175742.php deleted file mode 100644 index 08b5c26d9..000000000 --- a/tests/Fixtures/Migrations/Version20210318175742.php +++ /dev/null @@ -1,34 +0,0 @@ -addSql('ALTER TABLE comments ADD CONSTRAINT FK_5F9E962AA76ED395 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE comments ADD CONSTRAINT FK_5F9E962A4B89032C FOREIGN KEY (post_id) REFERENCES posts (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE posts ADD CONSTRAINT FK_885DBAFA12469DE2 FOREIGN KEY (category_id) REFERENCES categories (id)'); - $this->addSql('ALTER TABLE post_tag ADD CONSTRAINT FK_5ACE3AF04B89032C FOREIGN KEY (post_id) REFERENCES posts (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE post_tag ADD CONSTRAINT FK_5ACE3AF0BAD26311 FOREIGN KEY (tag_id) REFERENCES tags (id) ON DELETE CASCADE'); - } - - public function down(Schema $schema): void - { - } - - public function isTransactional(): bool - { - return false; - } -} diff --git a/tests/Fixtures/Migrations/Version20210820131815.php b/tests/Fixtures/Migrations/Version20210820131815.php deleted file mode 100644 index 72bedc38f..000000000 --- a/tests/Fixtures/Migrations/Version20210820131815.php +++ /dev/null @@ -1,46 +0,0 @@ -addSql('CREATE TABLE brand_cascade (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE category_cascade (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE category_product (category_id INT NOT NULL, product_id INT NOT NULL, INDEX IDX_149244D312469DE2 (category_id), INDEX IDX_149244D34584665A (product_id), PRIMARY KEY(category_id, product_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE image_cascade (id INT AUTO_INCREMENT NOT NULL, path VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE product_cascade (id INT AUTO_INCREMENT NOT NULL, brand_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, INDEX IDX_D7FE16D844F5D008 (brand_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE product_tag (product_id INT NOT NULL, tag_id INT NOT NULL, INDEX IDX_E3A6E39C4584665A (product_id), INDEX IDX_E3A6E39CBAD26311 (tag_id), PRIMARY KEY(product_id, tag_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE review_cascade (id INT AUTO_INCREMENT NOT NULL, product_id INT DEFAULT NULL, `ranking` INT NOT NULL, UNIQUE INDEX UNIQ_9DC9B99F4584665A (product_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE tag_cascade (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE variant_cascade (id INT AUTO_INCREMENT NOT NULL, product_id INT DEFAULT NULL, image_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, INDEX IDX_6982202E4584665A (product_id), UNIQUE INDEX UNIQ_6982202E3DA5256D (image_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('ALTER TABLE category_product ADD CONSTRAINT FK_149244D312469DE2 FOREIGN KEY (category_id) REFERENCES category_cascade (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE category_product ADD CONSTRAINT FK_149244D34584665A FOREIGN KEY (product_id) REFERENCES product_cascade (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE product_cascade ADD CONSTRAINT FK_D7FE16D844F5D008 FOREIGN KEY (brand_id) REFERENCES brand_cascade (id)'); - $this->addSql('ALTER TABLE product_tag ADD CONSTRAINT FK_E3A6E39C4584665A FOREIGN KEY (product_id) REFERENCES product_cascade (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE product_tag ADD CONSTRAINT FK_E3A6E39CBAD26311 FOREIGN KEY (tag_id) REFERENCES tag_cascade (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE review_cascade ADD CONSTRAINT FK_9DC9B99F4584665A FOREIGN KEY (product_id) REFERENCES product_cascade (id)'); - $this->addSql('ALTER TABLE variant_cascade ADD CONSTRAINT FK_6982202E4584665A FOREIGN KEY (product_id) REFERENCES product_cascade (id)'); - $this->addSql('ALTER TABLE variant_cascade ADD CONSTRAINT FK_6982202E3DA5256D FOREIGN KEY (image_id) REFERENCES image_cascade (id)'); - } - - public function down(Schema $schema): void - { - } - - public function isTransactional(): bool - { - return false; - } -} diff --git a/tests/Fixtures/Migrations/Version20220925092226.php b/tests/Fixtures/Migrations/Version20220925092226.php deleted file mode 100644 index 5c3f50bd0..000000000 --- a/tests/Fixtures/Migrations/Version20220925092226.php +++ /dev/null @@ -1,62 +0,0 @@ -addSql('ALTER TABLE posts ADD mostRelevantRelatedPost_id INT DEFAULT NULL'); - $this->addSql('ALTER TABLE posts ADD CONSTRAINT FK_885DBAFAD126F51 FOREIGN KEY (mostRelevantRelatedPost_id) REFERENCES posts (id)'); - $this->addSql('CREATE INDEX IDX_885DBAFAD126F51 ON posts (mostRelevantRelatedPost_id)'); - $this->addSql('ALTER TABLE posts ADD lessRelevantRelatedPost_id INT DEFAULT NULL'); - $this->addSql('ALTER TABLE posts ADD CONSTRAINT FK_985DBAFAD126F52 FOREIGN KEY (lessRelevantRelatedPost_id) REFERENCES posts (id)'); - $this->addSql('CREATE INDEX IDX_985DBAFAD126F52 ON posts (lessRelevantRelatedPost_id)'); - - $this->addSql('CREATE TABLE post_tag_secondary (post_id INT NOT NULL, tag_id INT NOT NULL, INDEX IDX_1515F0214B89032C (post_id), INDEX IDX_1515F021BAD26311 (tag_id), PRIMARY KEY(post_id, tag_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('ALTER TABLE post_tag_secondary ADD CONSTRAINT FK_1515F0214B89032C FOREIGN KEY (post_id) REFERENCES posts (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE post_tag_secondary ADD CONSTRAINT FK_1515F021BAD26311 FOREIGN KEY (tag_id) REFERENCES tags (id) ON DELETE CASCADE'); - - $this->addSql('ALTER TABLE posts ADD secondary_category_id INT DEFAULT NULL'); - $this->addSql('ALTER TABLE posts ADD CONSTRAINT FK_885DBAFAEA0D7566 FOREIGN KEY (secondary_category_id) REFERENCES categories (id)'); - $this->addSql('CREATE INDEX IDX_885DBAFAEA0D7566 ON posts (secondary_category_id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE posts DROP FOREIGN KEY FK_985DBAFAD126F52'); - $this->addSql('DROP INDEX IDX_985DBAFAD126F52 ON posts'); - $this->addSql('ALTER TABLE posts DROP lessRelevantRelatedPost_id'); - $this->addSql('ALTER TABLE posts DROP FOREIGN KEY FK_885DBAFAD126F51'); - $this->addSql('DROP INDEX IDX_885DBAFAD126F51 ON posts'); - $this->addSql('ALTER TABLE posts DROP mostRelevantRelatedPost_id'); - - $this->addSql('ALTER TABLE post_tag_secondary DROP FOREIGN KEY FK_1515F0214B89032C'); - $this->addSql('ALTER TABLE post_tag_secondary DROP FOREIGN KEY FK_1515F021BAD26311'); - $this->addSql('DROP TABLE post_tag_secondary'); - - $this->addSql('ALTER TABLE posts DROP FOREIGN KEY FK_885DBAFAEA0D7566'); - $this->addSql('DROP INDEX IDX_885DBAFAEA0D7566 ON posts'); - $this->addSql('ALTER TABLE posts DROP secondary_category_id'); - } - - public function isTransactional(): bool - { - return false; - } -} diff --git a/tests/Fixtures/Migrations/Version20220925092634.php b/tests/Fixtures/Migrations/Version20220925092634.php deleted file mode 100644 index 216f2dc8b..000000000 --- a/tests/Fixtures/Migrations/Version20220925092634.php +++ /dev/null @@ -1,42 +0,0 @@ -addSql('CREATE TABLE post_post (post_source INT NOT NULL, post_target INT NOT NULL, INDEX IDX_93DF0B866FA89B16 (post_source), INDEX IDX_93DF0B86764DCB99 (post_target), PRIMARY KEY(post_source, post_target)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); - $this->addSql('ALTER TABLE post_post ADD CONSTRAINT FK_93DF0B866FA89B16 FOREIGN KEY (post_source) REFERENCES posts (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE post_post ADD CONSTRAINT FK_93DF0B86764DCB99 FOREIGN KEY (post_target) REFERENCES posts (id) ON DELETE CASCADE'); - $this->addSql("ALTER TABLE posts ADD type VARCHAR(255) NOT NULL DEFAULT 'simple', ADD specificProperty VARCHAR(255) DEFAULT NULL"); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE post_post DROP FOREIGN KEY FK_93DF0B866FA89B16'); - $this->addSql('ALTER TABLE post_post DROP FOREIGN KEY FK_93DF0B86764DCB99'); - $this->addSql('DROP TABLE post_post'); - $this->addSql('ALTER TABLE posts DROP type, DROP specificProperty'); - } - - public function isTransactional(): bool - { - return false; - } -} diff --git a/tests/Fixtures/Migrations/Version20221010154036.php b/tests/Fixtures/Migrations/Version20221010154036.php deleted file mode 100644 index 95a7dc20a..000000000 --- a/tests/Fixtures/Migrations/Version20221010154036.php +++ /dev/null @@ -1,38 +0,0 @@ -addSql('ALTER TABLE posts CHANGE type type VARCHAR(255) NOT NULL'); - $this->addSql('ALTER TABLE posts RENAME INDEX idx_985dbafad126f52 TO IDX_885DBAFA20DBE482'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql("ALTER TABLE posts CHANGE type type VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT 'simple' NOT NULL COLLATE `utf8mb4_unicode_ci`"); - $this->addSql('ALTER TABLE posts RENAME INDEX idx_885dbafa20dbe482 TO IDX_985DBAFAD126F52'); - } - - public function isTransactional(): bool - { - return false; - } -} diff --git a/tests/Fixtures/Migrations/Version20221117081744.php b/tests/Fixtures/Migrations/Version20221117081744.php deleted file mode 100644 index 849c6a115..000000000 --- a/tests/Fixtures/Migrations/Version20221117081744.php +++ /dev/null @@ -1,54 +0,0 @@ -addSql('CREATE TABLE entity_with_relations (id INT AUTO_INCREMENT NOT NULL, oneToOne_id INT NOT NULL, oneToOneNullable_id INT DEFAULT NULL, manyToOne_id INT NOT NULL, manyToOneNullable_id INT DEFAULT NULL, manyToOneNullableDefault_id INT DEFAULT NULL, manyToOneWithNotExistingFactory_id INT NOT NULL, UNIQUE INDEX UNIQ_A9C9EC969017888C (oneToOne_id), UNIQUE INDEX UNIQ_A9C9EC96DA2BFB84 (oneToOneNullable_id), INDEX IDX_A9C9EC962E3A088A (manyToOne_id), INDEX IDX_A9C9EC968097B86C (manyToOneNullable_id), INDEX IDX_A9C9EC968572C13C (manyToOneNullableDefault_id), INDEX IDX_A9C9EC96FF92FDCA (manyToOneWithNotExistingFactory_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); - $this->addSql('CREATE TABLE entitywithrelations_category (entitywithrelations_id INT NOT NULL, category_id INT NOT NULL, INDEX IDX_CD6EBFAB337AA4F7 (entitywithrelations_id), INDEX IDX_CD6EBFAB12469DE2 (category_id), PRIMARY KEY(entitywithrelations_id, category_id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); - $this->addSql('ALTER TABLE entity_with_relations ADD CONSTRAINT FK_A9C9EC969017888C FOREIGN KEY (oneToOne_id) REFERENCES categories (id)'); - $this->addSql('ALTER TABLE entity_with_relations ADD CONSTRAINT FK_A9C9EC96DA2BFB84 FOREIGN KEY (oneToOneNullable_id) REFERENCES categories (id)'); - $this->addSql('ALTER TABLE entity_with_relations ADD CONSTRAINT FK_A9C9EC962E3A088A FOREIGN KEY (manyToOne_id) REFERENCES categories (id)'); - $this->addSql('ALTER TABLE entity_with_relations ADD CONSTRAINT FK_A9C9EC968097B86C FOREIGN KEY (manyToOneNullable_id) REFERENCES categories (id)'); - $this->addSql('ALTER TABLE entity_with_relations ADD CONSTRAINT FK_A9C9EC968572C13C FOREIGN KEY (manyToOneNullableDefault_id) REFERENCES categories (id)'); - $this->addSql('ALTER TABLE entity_with_relations ADD CONSTRAINT FK_A9C9EC96FF92FDCA FOREIGN KEY (manyToOneWithNotExistingFactory_id) REFERENCES brand_cascade (id)'); - $this->addSql('ALTER TABLE entitywithrelations_category ADD CONSTRAINT FK_CD6EBFAB337AA4F7 FOREIGN KEY (entitywithrelations_id) REFERENCES entity_with_relations (id) ON DELETE CASCADE'); - $this->addSql('ALTER TABLE entitywithrelations_category ADD CONSTRAINT FK_CD6EBFAB12469DE2 FOREIGN KEY (category_id) REFERENCES categories (id) ON DELETE CASCADE'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE entity_with_relations DROP FOREIGN KEY FK_A9C9EC969017888C'); - $this->addSql('ALTER TABLE entity_with_relations DROP FOREIGN KEY FK_A9C9EC96DA2BFB84'); - $this->addSql('ALTER TABLE entity_with_relations DROP FOREIGN KEY FK_A9C9EC962E3A088A'); - $this->addSql('ALTER TABLE entity_with_relations DROP FOREIGN KEY FK_A9C9EC968097B86C'); - $this->addSql('ALTER TABLE entity_with_relations DROP FOREIGN KEY FK_A9C9EC968572C13C'); - $this->addSql('ALTER TABLE entity_with_relations DROP FOREIGN KEY FK_A9C9EC96FF92FDCA'); - $this->addSql('ALTER TABLE entitywithrelations_category DROP FOREIGN KEY FK_CD6EBFAB337AA4F7'); - $this->addSql('ALTER TABLE entitywithrelations_category DROP FOREIGN KEY FK_CD6EBFAB12469DE2'); - $this->addSql('DROP TABLE entity_with_relations'); - $this->addSql('DROP TABLE entitywithrelations_category'); - } - - public function isTransactional(): bool - { - return false; - } -} diff --git a/tests/Fixtures/Migrations/Version20221124123656.php b/tests/Fixtures/Migrations/Version20221124123656.php deleted file mode 100644 index f999c445d..000000000 --- a/tests/Fixtures/Migrations/Version20221124123656.php +++ /dev/null @@ -1,38 +0,0 @@ -addSql('CREATE TABLE entity_for_relations (id INT AUTO_INCREMENT NOT NULL, manyToOne_id INT DEFAULT NULL, INDEX IDX_C63B81552E3A088A (manyToOne_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); - $this->addSql('ALTER TABLE entity_for_relations ADD CONSTRAINT FK_C63B81552E3A088A FOREIGN KEY (manyToOne_id) REFERENCES entity_with_relations (id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE entity_for_relations DROP FOREIGN KEY FK_C63B81552E3A088A'); - $this->addSql('DROP TABLE entity_for_relations'); - } - - public function isTransactional(): bool - { - return false; - } -} diff --git a/tests/Fixtures/Migrations/Version20221204165429.php b/tests/Fixtures/Migrations/Version20221204165429.php new file mode 100644 index 000000000..373a5ef5f --- /dev/null +++ b/tests/Fixtures/Migrations/Version20221204165429.php @@ -0,0 +1,93 @@ +addSql('CREATE TABLE categories (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE comments (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, post_id INT NOT NULL, body LONGTEXT NOT NULL, createdAt DATETIME NOT NULL, approved TINYINT(1) NOT NULL, INDEX IDX_5F9E962AA76ED395 (user_id), INDEX IDX_5F9E962A4B89032C (post_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE contacts (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, address_value VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE entity_for_relations (id INT AUTO_INCREMENT NOT NULL, manyToOne_id INT DEFAULT NULL, INDEX IDX_C63B81552E3A088A (manyToOne_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE entity_with_relations (id INT AUTO_INCREMENT NOT NULL, oneToOne_id INT NOT NULL, oneToOneNullable_id INT DEFAULT NULL, manyToOne_id INT NOT NULL, manyToOneNullable_id INT DEFAULT NULL, manyToOneNullableDefault_id INT DEFAULT NULL, manyToOneWithNotExistingFactory_id INT NOT NULL, UNIQUE INDEX UNIQ_A9C9EC969017888C (oneToOne_id), UNIQUE INDEX UNIQ_A9C9EC96DA2BFB84 (oneToOneNullable_id), INDEX IDX_A9C9EC962E3A088A (manyToOne_id), INDEX IDX_A9C9EC968097B86C (manyToOneNullable_id), INDEX IDX_A9C9EC968572C13C (manyToOneNullableDefault_id), INDEX IDX_A9C9EC96FF92FDCA (manyToOneWithNotExistingFactory_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE entitywithrelations_category (entitywithrelations_id INT NOT NULL, category_id INT NOT NULL, INDEX IDX_CD6EBFAB337AA4F7 (entitywithrelations_id), INDEX IDX_CD6EBFAB12469DE2 (category_id), PRIMARY KEY(entitywithrelations_id, category_id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE posts (id INT AUTO_INCREMENT NOT NULL, category_id INT DEFAULT NULL, secondary_category_id INT DEFAULT NULL, title VARCHAR(255) NOT NULL, body LONGTEXT NOT NULL, shortDescription VARCHAR(255) DEFAULT NULL, viewCount INT NOT NULL, createdAt DATETIME NOT NULL, publishedAt DATETIME DEFAULT NULL, mostRelevantRelatedPost_id INT DEFAULT NULL, lessRelevantRelatedPost_id INT DEFAULT NULL, type VARCHAR(255) NOT NULL, specificProperty VARCHAR(255) DEFAULT NULL, INDEX IDX_885DBAFA12469DE2 (category_id), INDEX IDX_885DBAFAEA0D7566 (secondary_category_id), INDEX IDX_885DBAFAD126F51 (mostRelevantRelatedPost_id), INDEX IDX_885DBAFA20DBE482 (lessRelevantRelatedPost_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE post_tag (post_id INT NOT NULL, tag_id INT NOT NULL, INDEX IDX_5ACE3AF04B89032C (post_id), INDEX IDX_5ACE3AF0BAD26311 (tag_id), PRIMARY KEY(post_id, tag_id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE post_tag_secondary (post_id INT NOT NULL, tag_id INT NOT NULL, INDEX IDX_1515F0214B89032C (post_id), INDEX IDX_1515F021BAD26311 (tag_id), PRIMARY KEY(post_id, tag_id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE post_post (post_source INT NOT NULL, post_target INT NOT NULL, INDEX IDX_93DF0B866FA89B16 (post_source), INDEX IDX_93DF0B86764DCB99 (post_target), PRIMARY KEY(post_source, post_target)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE tags (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE users (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); + $this->addSql('ALTER TABLE comments ADD CONSTRAINT FK_5F9E962AA76ED395 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE comments ADD CONSTRAINT FK_5F9E962A4B89032C FOREIGN KEY (post_id) REFERENCES posts (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE entity_for_relations ADD CONSTRAINT FK_C63B81552E3A088A FOREIGN KEY (manyToOne_id) REFERENCES entity_with_relations (id)'); + $this->addSql('ALTER TABLE entity_with_relations ADD CONSTRAINT FK_A9C9EC969017888C FOREIGN KEY (oneToOne_id) REFERENCES categories (id)'); + $this->addSql('ALTER TABLE entity_with_relations ADD CONSTRAINT FK_A9C9EC96DA2BFB84 FOREIGN KEY (oneToOneNullable_id) REFERENCES categories (id)'); + $this->addSql('ALTER TABLE entity_with_relations ADD CONSTRAINT FK_A9C9EC962E3A088A FOREIGN KEY (manyToOne_id) REFERENCES categories (id)'); + $this->addSql('ALTER TABLE entity_with_relations ADD CONSTRAINT FK_A9C9EC968097B86C FOREIGN KEY (manyToOneNullable_id) REFERENCES categories (id)'); + $this->addSql('ALTER TABLE entity_with_relations ADD CONSTRAINT FK_A9C9EC968572C13C FOREIGN KEY (manyToOneNullableDefault_id) REFERENCES categories (id)'); + $this->addSql('ALTER TABLE entitywithrelations_category ADD CONSTRAINT FK_CD6EBFAB337AA4F7 FOREIGN KEY (entitywithrelations_id) REFERENCES entity_with_relations (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE entitywithrelations_category ADD CONSTRAINT FK_CD6EBFAB12469DE2 FOREIGN KEY (category_id) REFERENCES categories (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE posts ADD CONSTRAINT FK_885DBAFA12469DE2 FOREIGN KEY (category_id) REFERENCES categories (id)'); + $this->addSql('ALTER TABLE posts ADD CONSTRAINT FK_885DBAFAEA0D7566 FOREIGN KEY (secondary_category_id) REFERENCES categories (id)'); + $this->addSql('ALTER TABLE posts ADD CONSTRAINT FK_885DBAFAD126F51 FOREIGN KEY (mostRelevantRelatedPost_id) REFERENCES posts (id)'); + $this->addSql('ALTER TABLE posts ADD CONSTRAINT FK_885DBAFA20DBE482 FOREIGN KEY (lessRelevantRelatedPost_id) REFERENCES posts (id)'); + $this->addSql('ALTER TABLE post_tag ADD CONSTRAINT FK_5ACE3AF04B89032C FOREIGN KEY (post_id) REFERENCES posts (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE post_tag ADD CONSTRAINT FK_5ACE3AF0BAD26311 FOREIGN KEY (tag_id) REFERENCES tags (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE post_tag_secondary ADD CONSTRAINT FK_1515F0214B89032C FOREIGN KEY (post_id) REFERENCES posts (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE post_tag_secondary ADD CONSTRAINT FK_1515F021BAD26311 FOREIGN KEY (tag_id) REFERENCES tags (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE post_post ADD CONSTRAINT FK_93DF0B866FA89B16 FOREIGN KEY (post_source) REFERENCES posts (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE post_post ADD CONSTRAINT FK_93DF0B86764DCB99 FOREIGN KEY (post_target) REFERENCES posts (id) ON DELETE CASCADE'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE comments DROP FOREIGN KEY FK_5F9E962AA76ED395'); + $this->addSql('ALTER TABLE comments DROP FOREIGN KEY FK_5F9E962A4B89032C'); + $this->addSql('ALTER TABLE entity_for_relations DROP FOREIGN KEY FK_C63B81552E3A088A'); + $this->addSql('ALTER TABLE entity_with_relations DROP FOREIGN KEY FK_A9C9EC969017888C'); + $this->addSql('ALTER TABLE entity_with_relations DROP FOREIGN KEY FK_A9C9EC96DA2BFB84'); + $this->addSql('ALTER TABLE entity_with_relations DROP FOREIGN KEY FK_A9C9EC962E3A088A'); + $this->addSql('ALTER TABLE entity_with_relations DROP FOREIGN KEY FK_A9C9EC968097B86C'); + $this->addSql('ALTER TABLE entity_with_relations DROP FOREIGN KEY FK_A9C9EC968572C13C'); + $this->addSql('ALTER TABLE entitywithrelations_category DROP FOREIGN KEY FK_CD6EBFAB337AA4F7'); + $this->addSql('ALTER TABLE entitywithrelations_category DROP FOREIGN KEY FK_CD6EBFAB12469DE2'); + $this->addSql('ALTER TABLE posts DROP FOREIGN KEY FK_885DBAFA12469DE2'); + $this->addSql('ALTER TABLE posts DROP FOREIGN KEY FK_885DBAFAEA0D7566'); + $this->addSql('ALTER TABLE posts DROP FOREIGN KEY FK_885DBAFAD126F51'); + $this->addSql('ALTER TABLE posts DROP FOREIGN KEY FK_885DBAFA20DBE482'); + $this->addSql('ALTER TABLE post_tag DROP FOREIGN KEY FK_5ACE3AF04B89032C'); + $this->addSql('ALTER TABLE post_tag DROP FOREIGN KEY FK_5ACE3AF0BAD26311'); + $this->addSql('ALTER TABLE post_tag_secondary DROP FOREIGN KEY FK_1515F0214B89032C'); + $this->addSql('ALTER TABLE post_tag_secondary DROP FOREIGN KEY FK_1515F021BAD26311'); + $this->addSql('ALTER TABLE post_post DROP FOREIGN KEY FK_93DF0B866FA89B16'); + $this->addSql('ALTER TABLE post_post DROP FOREIGN KEY FK_93DF0B86764DCB99'); + $this->addSql('DROP TABLE categories'); + $this->addSql('DROP TABLE comments'); + $this->addSql('DROP TABLE contacts'); + $this->addSql('DROP TABLE entity_for_relations'); + $this->addSql('DROP TABLE entity_with_relations'); + $this->addSql('DROP TABLE entitywithrelations_category'); + $this->addSql('DROP TABLE posts'); + $this->addSql('DROP TABLE post_tag'); + $this->addSql('DROP TABLE post_tag_secondary'); + $this->addSql('DROP TABLE post_post'); + $this->addSql('DROP TABLE tags'); + $this->addSql('DROP TABLE users'); + } + + public function isTransactional(): bool + { + return false; + } +} diff --git a/tests/Fixtures/Migrations/Version20221204165430.php b/tests/Fixtures/Migrations/Version20221204165430.php new file mode 100644 index 000000000..ae3394a60 --- /dev/null +++ b/tests/Fixtures/Migrations/Version20221204165430.php @@ -0,0 +1,65 @@ +addSql('CREATE TABLE brand_cascade (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE category_cascade (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE productcategory_product (productcategory_id INT NOT NULL, product_id INT NOT NULL, INDEX IDX_5BC2A6A2E26A32B1 (productcategory_id), INDEX IDX_5BC2A6A24584665A (product_id), PRIMARY KEY(productcategory_id, product_id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE image_cascade (id INT AUTO_INCREMENT NOT NULL, path VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE product_cascade (id INT AUTO_INCREMENT NOT NULL, brand_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, INDEX IDX_D7FE16D844F5D008 (brand_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE product_producttag (product_id INT NOT NULL, producttag_id INT NOT NULL, INDEX IDX_B32B4BC24584665A (product_id), INDEX IDX_B32B4BC291B6F4D1 (producttag_id), PRIMARY KEY(product_id, producttag_id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE review_cascade (id INT AUTO_INCREMENT NOT NULL, product_id INT DEFAULT NULL, ranking INT NOT NULL, UNIQUE INDEX UNIQ_9DC9B99F4584665A (product_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE tag_cascade (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE variant_cascade (id INT AUTO_INCREMENT NOT NULL, product_id INT DEFAULT NULL, image_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, INDEX IDX_6982202E4584665A (product_id), UNIQUE INDEX UNIQ_6982202E3DA5256D (image_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB'); + $this->addSql('ALTER TABLE productcategory_product ADD CONSTRAINT FK_5BC2A6A2E26A32B1 FOREIGN KEY (productcategory_id) REFERENCES category_cascade (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE productcategory_product ADD CONSTRAINT FK_5BC2A6A24584665A FOREIGN KEY (product_id) REFERENCES product_cascade (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE entity_with_relations ADD CONSTRAINT FK_A9C9EC96FF92FDCA FOREIGN KEY (manyToOneWithNotExistingFactory_id) REFERENCES brand_cascade (id)'); + $this->addSql('ALTER TABLE product_cascade ADD CONSTRAINT FK_D7FE16D844F5D008 FOREIGN KEY (brand_id) REFERENCES brand_cascade (id)'); + $this->addSql('ALTER TABLE product_producttag ADD CONSTRAINT FK_B32B4BC24584665A FOREIGN KEY (product_id) REFERENCES product_cascade (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE product_producttag ADD CONSTRAINT FK_B32B4BC291B6F4D1 FOREIGN KEY (producttag_id) REFERENCES tag_cascade (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE review_cascade ADD CONSTRAINT FK_9DC9B99F4584665A FOREIGN KEY (product_id) REFERENCES product_cascade (id)'); + $this->addSql('ALTER TABLE variant_cascade ADD CONSTRAINT FK_6982202E4584665A FOREIGN KEY (product_id) REFERENCES product_cascade (id)'); + $this->addSql('ALTER TABLE variant_cascade ADD CONSTRAINT FK_6982202E3DA5256D FOREIGN KEY (image_id) REFERENCES image_cascade (id)'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE entity_with_relations DROP FOREIGN KEY FK_A9C9EC96FF92FDCA'); + $this->addSql('ALTER TABLE productcategory_product DROP FOREIGN KEY FK_5BC2A6A2E26A32B1'); + $this->addSql('ALTER TABLE productcategory_product DROP FOREIGN KEY FK_5BC2A6A24584665A'); + $this->addSql('ALTER TABLE product_cascade DROP FOREIGN KEY FK_D7FE16D844F5D008'); + $this->addSql('ALTER TABLE product_producttag DROP FOREIGN KEY FK_B32B4BC24584665A'); + $this->addSql('ALTER TABLE product_producttag DROP FOREIGN KEY FK_B32B4BC291B6F4D1'); + $this->addSql('ALTER TABLE review_cascade DROP FOREIGN KEY FK_9DC9B99F4584665A'); + $this->addSql('ALTER TABLE variant_cascade DROP FOREIGN KEY FK_6982202E4584665A'); + $this->addSql('ALTER TABLE variant_cascade DROP FOREIGN KEY FK_6982202E3DA5256D'); + $this->addSql('DROP TABLE brand_cascade'); + $this->addSql('DROP TABLE category_cascade'); + $this->addSql('DROP TABLE productcategory_product'); + $this->addSql('DROP TABLE image_cascade'); + $this->addSql('DROP TABLE product_cascade'); + $this->addSql('DROP TABLE product_producttag'); + $this->addSql('DROP TABLE review_cascade'); + $this->addSql('DROP TABLE tag_cascade'); + $this->addSql('DROP TABLE variant_cascade'); + } + + public function isTransactional(): bool + { + return false; + } +} diff --git a/tests/Functional/Bundle/Maker/MakeFactoryTest.php b/tests/Functional/Bundle/Maker/MakeFactoryTest.php index 31f97fda4..a167c9785 100644 --- a/tests/Functional/Bundle/Maker/MakeFactoryTest.php +++ b/tests/Functional/Bundle/Maker/MakeFactoryTest.php @@ -5,8 +5,8 @@ use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException; use Symfony\Component\Console\Tester\CommandTester; -use Zenstruck\Foundry\Tests\Fixtures\Document\Comment; -use Zenstruck\Foundry\Tests\Fixtures\Document\Post as ODMPost; +use Zenstruck\Foundry\Tests\Fixtures\Document\ODMComment; +use Zenstruck\Foundry\Tests\Fixtures\Document\ODMPost as ODMPost; use Zenstruck\Foundry\Tests\Fixtures\Entity\Category; use Zenstruck\Foundry\Tests\Fixtures\Entity\Contact; use Zenstruck\Foundry\Tests\Fixtures\Entity\EntityWithRelations; @@ -27,6 +27,11 @@ final class MakeFactoryTest extends MakerTestCase { private const PHPSTAN_PATH = __DIR__.'/../../../../vendor/phpstan/phpstan/phpstan'; + protected function setUp(): void + { + self::assertDirectoryDoesNotExist(self::tempDir()); + } + protected function tearDown(): void { parent::tearDown(); @@ -49,8 +54,6 @@ public function can_create_factory(): void $tester = new CommandTester((new Application(self::bootKernel()))->find('make:factory')); - $this->assertFileDoesNotExist(self::tempFile('src/Factory/CategoryFactory.php')); - $tester->execute(['class' => Category::class]); $this->assertFileFromMakerSameAsExpectedFile(self::tempFile('src/Factory/CategoryFactory.php')); @@ -70,8 +73,6 @@ public function can_create_factory_interactively(): void $tester = new CommandTester((new Application($kernel))->find('make:factory')); - $this->assertFileDoesNotExist(self::tempFile('src/Factory/TagFactory.php')); - $tester->setInputs([Tag::class]); $tester->execute([]); @@ -94,8 +95,6 @@ public function can_create_factory_in_test_dir(): void $tester = new CommandTester((new Application(self::bootKernel()))->find('make:factory')); - $this->assertFileDoesNotExist(self::tempFile('tests/Factory/CategoryFactory.php')); - $tester->execute(['class' => Category::class, '--test' => true]); $this->assertFileFromMakerSameAsExpectedFile(self::tempFile('tests/Factory/CategoryFactory.php')); @@ -112,8 +111,6 @@ public function can_create_factory_in_test_dir_interactively(): void $tester = new CommandTester((new Application(self::bootKernel()))->find('make:factory')); - $this->assertFileDoesNotExist(self::tempFile('tests/Factory/TagFactory.php')); - $tester->setInputs([Tag::class]); $tester->execute(['--test' => true]); @@ -133,8 +130,6 @@ public function can_create_factory_with_phpstan_annotations(): void $tester = new CommandTester((new Application(self::bootKernel()))->find('make:factory')); - $this->assertFileDoesNotExist(self::tempFile('src/Factory/CategoryFactory.php')); - $tester->execute(['class' => Category::class]); $this->assertFileFromMakerSameAsExpectedFile(self::tempFile('src/Factory/CategoryFactory.php')); @@ -153,8 +148,6 @@ public function can_create_factory_for_entity_with_repository(): void $tester = new CommandTester((new Application(self::bootKernel()))->find('make:factory')); - $this->assertFileDoesNotExist(self::tempFile('src/Factory/PostFactory.php')); - $tester->execute(['class' => ORMPost::class]); $this->assertFileFromMakerSameAsExpectedFile(self::tempFile('src/Factory/PostFactory.php')); @@ -167,8 +160,6 @@ public function invalid_entity_throws_exception(): void { $tester = new CommandTester((new Application(self::bootKernel()))->find('make:factory')); - $this->assertFileDoesNotExist(self::tempFile('src/Factory/InvalidFactory.php')); - try { $tester->execute(['class' => 'Invalid']); } catch (RuntimeCommandException $e) { @@ -188,8 +179,6 @@ public function can_create_factory_for_not_persisted_class(): void { $tester = new CommandTester((new Application(self::bootKernel()))->find('make:factory')); - $this->assertFileDoesNotExist(self::tempFile('src/Factory/SomeObjectFactory.php')); - $tester->execute(['class' => SomeObject::class, '--no-persistence' => true, '--all-fields' => true]); $this->assertFileFromMakerSameAsExpectedFile(self::tempFile('src/Factory/SomeObjectFactory.php')); @@ -202,8 +191,6 @@ public function can_create_factory_for_not_persisted_class_interactively(): void { $tester = new CommandTester((new Application(self::bootKernel()))->find('make:factory')); - $this->assertFileDoesNotExist(self::tempFile('src/Factory/SomeObjectFactory.php')); - $tester->setInputs(['Foo', SomeObject::class]); // "Foo" will generate a validation error $tester->execute(['--no-persistence' => true]); @@ -227,8 +214,6 @@ public function can_customize_namespace(): void $tester = new CommandTester((new Application(self::bootKernel()))->find('make:factory')); $expectedFile = self::tempFile('src/My/Namespace/TagFactory.php'); - $this->assertFileDoesNotExist($expectedFile); - $tester->setInputs([Tag::class]); $tester->execute(['--namespace' => 'My\\Namespace']); @@ -248,8 +233,6 @@ public function can_customize_namespace_with_test_flag(): void $tester = new CommandTester((new Application(self::bootKernel()))->find('make:factory')); $expectedFile = self::tempFile('tests/My/Namespace/TagFactory.php'); - $this->assertFileDoesNotExist($expectedFile); - $tester->setInputs([Tag::class]); $tester->execute(['--namespace' => 'My\\Namespace', '--test' => true]); @@ -269,8 +252,6 @@ public function can_customize_namespace_with_root_namespace_prefix(): void $tester = new CommandTester((new Application(self::bootKernel()))->find('make:factory')); $expectedFile = self::tempFile('src/My/Namespace/TagFactory.php'); - $this->assertFileDoesNotExist($expectedFile); - $tester->setInputs([Tag::class]); $tester->execute(['--namespace' => 'App\\My\\Namespace']); @@ -290,8 +271,6 @@ public function can_customize_namespace_with_test_flag_with_root_namespace_prefi $tester = new CommandTester((new Application(self::bootKernel()))->find('make:factory')); $expectedFile = self::tempFile('tests/My/Namespace/TagFactory.php'); - $this->assertFileDoesNotExist($expectedFile); - $tester->setInputs([Tag::class]); $tester->execute(['--namespace' => 'App\\Tests\\My\\Namespace', '--test' => true]); @@ -306,20 +285,24 @@ public function can_create_all_factories_for_doctrine_objects(): void { $tester = new CommandTester((new Application(self::bootKernel()))->find('make:factory')); - $this->assertFileDoesNotExist(self::tempFile('src/Factory/CategoryFactory.php')); - $this->assertFileDoesNotExist(self::tempFile('src/Factory/TagFactory.php')); - $tester->setInputs(['All']); - try { - $tester->execute([]); - } catch (RuntimeCommandException) { - // todo find a better solution - // because we have fixtures with the same name, the maker will fail when creating the duplicate + $tester->execute([]); + + $expectedFactories = []; + + if (\getenv('USE_ORM')) { + $expectedFactories = ['BrandFactory', 'CategoryFactory', 'CommentFactory', 'ContactFactory', 'EntityForRelationsFactory', 'UserFactory']; } - $this->assertFileExists(self::tempFile('src/Factory/CategoryFactory.php')); - $this->assertFileExists(self::tempFile('src/Factory/TagFactory.php')); + if (\getenv('USE_ODM')) { + $expectedFactories = [...$expectedFactories, 'ODMCategoryFactory', 'ODMCommentFactory', 'ODMPostFactory', 'ODMTagFactory', 'ODMUserFactory']; + } + + self::assertGreaterThan(0, \count($expectedFactories)); + foreach ($expectedFactories as $expectedFactory) { + $this->assertFileExists(self::tempFile("src/Factory/{$expectedFactory}.php")); + } } /** @@ -337,8 +320,6 @@ public function can_create_factory_for_odm(string $class, string $file): void $tester = new CommandTester((new Application($kernel))->find('make:factory')); - $this->assertFileDoesNotExist(self::tempFile("src/Factory/{$file}.php")); - $tester->setInputs([$class]); $tester->execute([]); @@ -347,8 +328,8 @@ public function can_create_factory_for_odm(string $class, string $file): void public function documentProvider(): iterable { - yield 'document' => [ODMPost::class, 'PostFactory']; - yield 'embedded document' => [Comment::class, 'CommentFactory']; + yield 'document' => [ODMPost::class, 'ODMPostFactory']; + yield 'embedded document' => [ODMComment::class, 'ODMCommentFactory']; } /** @@ -364,7 +345,6 @@ public function can_create_factory_with_auto_activated_not_persisted_option(): v $kernel->boot(); $tester = new CommandTester((new Application($kernel))->find('make:factory')); - $this->assertFileDoesNotExist(self::tempFile('src/Factory/CategoryFactory.php')); $tester->execute(['class' => Category::class]); @@ -388,8 +368,6 @@ public function can_create_factory_with_relation_defaults(): void $tester = new CommandTester((new Application($kernel))->find('make:factory')); - $this->assertFileDoesNotExist(self::tempFile('src/Factory/EntityWithRelationsFactory.php')); - $tester->execute(['class' => EntityWithRelations::class]); $this->assertFileFromMakerSameAsExpectedFile(self::tempFile('src/Factory/EntityWithRelationsFactory.php')); @@ -409,8 +387,6 @@ public function can_create_factory_with_relation_for_all_fields(): void $tester = new CommandTester((new Application($kernel))->find('make:factory')); - $this->assertFileDoesNotExist(self::tempFile('src/Factory/EntityWithRelationsFactory.php')); - $tester->execute(['class' => EntityWithRelations::class, '--all-fields' => true]); $this->assertFileFromMakerSameAsExpectedFile(self::tempFile('src/Factory/EntityWithRelationsFactory.php')); @@ -427,8 +403,6 @@ public function can_create_factory_with_embeddable(string $objectClass, string $ $tester = new CommandTester((new Application($kernel))->find('make:factory')); - $this->assertFileDoesNotExist(self::tempFile("src/Factory/{$factoryName}.php")); - $tester->execute(['class' => $objectClass, '--all-fields' => true]); $this->assertFileFromMakerSameAsExpectedFile(self::tempFile("src/Factory/{$factoryName}.php")); @@ -441,7 +415,7 @@ public function objectsWithEmbeddableProvider(): iterable } if (\getenv('USE_ODM')) { - yield 'odm' => [ODMPost::class, 'PostFactory', [CommentFactory::class, UserFactory::class]]; + yield 'odm' => [ODMPost::class, 'ODMPostFactory', [CommentFactory::class, UserFactory::class]]; } } diff --git a/tests/Functional/FactoryDoctrineCascadeTest.php b/tests/Functional/FactoryDoctrineCascadeTest.php index 5358015d1..8143221b0 100644 --- a/tests/Functional/FactoryDoctrineCascadeTest.php +++ b/tests/Functional/FactoryDoctrineCascadeTest.php @@ -7,11 +7,11 @@ use Zenstruck\Foundry\Test\Factories; use Zenstruck\Foundry\Test\ResetDatabase; use Zenstruck\Foundry\Tests\Fixtures\Entity\Cascade\Brand; -use Zenstruck\Foundry\Tests\Fixtures\Entity\Cascade\Category; use Zenstruck\Foundry\Tests\Fixtures\Entity\Cascade\Image; use Zenstruck\Foundry\Tests\Fixtures\Entity\Cascade\Product; +use Zenstruck\Foundry\Tests\Fixtures\Entity\Cascade\ProductCategory; +use Zenstruck\Foundry\Tests\Fixtures\Entity\Cascade\ProductTag; use Zenstruck\Foundry\Tests\Fixtures\Entity\Cascade\Review; -use Zenstruck\Foundry\Tests\Fixtures\Entity\Cascade\Tag; use Zenstruck\Foundry\Tests\Fixtures\Entity\Cascade\Variant; use function Zenstruck\Foundry\factory; @@ -73,7 +73,7 @@ public function many_to_many_relationship(): void { $product = factory(Product::class, [ 'name' => 'foo', - 'tags' => [factory(Tag::class, ['name' => 'bar'])], + 'tags' => [factory(ProductTag::class, ['name' => 'bar'])], ])->instantiateWith(function(array $attibutes, string $class): object { $this->assertNull($attibutes['tags'][0]->getId()); @@ -92,7 +92,7 @@ public function many_to_many_reverse_relationship(): void { $product = factory(Product::class, [ 'name' => 'foo', - 'categories' => [factory(Category::class, ['name' => 'bar'])], + 'categories' => [factory(ProductCategory::class, ['name' => 'bar'])], ])->instantiateWith(function(array $attibutes, string $class): object { $this->assertNull($attibutes['categories'][0]->getId()); diff --git a/tests/Functional/ODMAnonymousFactoryTest.php b/tests/Functional/ODMAnonymousFactoryTest.php index eedf03a8b..c02318e01 100644 --- a/tests/Functional/ODMAnonymousFactoryTest.php +++ b/tests/Functional/ODMAnonymousFactoryTest.php @@ -2,7 +2,7 @@ namespace Zenstruck\Foundry\Tests\Functional; -use Zenstruck\Foundry\Tests\Fixtures\Document\Category; +use Zenstruck\Foundry\Tests\Fixtures\Document\ODMCategory; /** * @author Kevin Bond @@ -18,6 +18,6 @@ protected function setUp(): void protected function categoryClass(): string { - return Category::class; + return ODMCategory::class; } } diff --git a/tests/Functional/ODMModelFactoryTest.php b/tests/Functional/ODMModelFactoryTest.php index 7db9bba6e..898c93558 100644 --- a/tests/Functional/ODMModelFactoryTest.php +++ b/tests/Functional/ODMModelFactoryTest.php @@ -3,10 +3,10 @@ namespace Zenstruck\Foundry\Tests\Functional; use Zenstruck\Foundry\Proxy; -use Zenstruck\Foundry\Tests\Fixtures\Document\Category; -use Zenstruck\Foundry\Tests\Fixtures\Document\Comment; -use Zenstruck\Foundry\Tests\Fixtures\Document\Post; -use Zenstruck\Foundry\Tests\Fixtures\Document\User; +use Zenstruck\Foundry\Tests\Fixtures\Document\ODMCategory; +use Zenstruck\Foundry\Tests\Fixtures\Document\ODMComment; +use Zenstruck\Foundry\Tests\Fixtures\Document\ODMPost; +use Zenstruck\Foundry\Tests\Fixtures\Document\ODMUser; use Zenstruck\Foundry\Tests\Fixtures\Factories\ODM\CategoryFactory; use Zenstruck\Foundry\Tests\Fixtures\Factories\ODM\CommentFactory; use Zenstruck\Foundry\Tests\Fixtures\Factories\ODM\PostFactory; @@ -28,13 +28,13 @@ protected function setUp(): void */ public function can_use_factory_for_embedded_object(): void { - $proxyObject = CommentFactory::createOne(['user' => new User('some user'), 'body' => 'some body']); + $proxyObject = CommentFactory::createOne(['user' => new ODMUser('some user'), 'body' => 'some body']); self::assertInstanceOf(Proxy::class, $proxyObject); self::assertFalse($proxyObject->isPersisted()); $comment = $proxyObject->object(); - self::assertInstanceOf(Comment::class, $comment); - self::assertEquals(new User('some user'), $comment->getUser()); + self::assertInstanceOf(ODMComment::class, $comment); + self::assertEquals(new ODMUser('some user'), $comment->getUser()); self::assertSame('some body', $comment->getBody()); } @@ -52,9 +52,9 @@ public function can_hydrate_embed_many_fields(): void self::assertCount(1, $posts); $post = $posts[0]->object(); - self::assertInstanceOf(Post::class, $post); + self::assertInstanceOf(ODMPost::class, $post); self::assertCount(4, $post->getComments()); - self::assertContainsOnlyInstancesOf(Comment::class, $post->getComments()); + self::assertContainsOnlyInstancesOf(ODMComment::class, $post->getComments()); } /** @@ -70,7 +70,7 @@ public function can_create_one_with_nested_embedded(): void protected function categoryClass(): string { - return Category::class; + return ODMCategory::class; } protected function categoryFactoryClass(): string diff --git a/tests/Functional/ODMProxyTest.php b/tests/Functional/ODMProxyTest.php index 78d7c70c1..e826512a8 100644 --- a/tests/Functional/ODMProxyTest.php +++ b/tests/Functional/ODMProxyTest.php @@ -2,7 +2,7 @@ namespace Zenstruck\Foundry\Tests\Functional; -use Zenstruck\Foundry\Tests\Fixtures\Document\Post; +use Zenstruck\Foundry\Tests\Fixtures\Document\ODMPost; use Zenstruck\Foundry\Tests\Fixtures\Factories\ODM\PostFactory; /** @@ -24,7 +24,7 @@ protected function postFactoryClass(): string protected function postClass(): string { - return Post::class; + return ODMPost::class; } protected function registryServiceId(): string diff --git a/tests/Functional/ODMRepositoryProxyTest.php b/tests/Functional/ODMRepositoryProxyTest.php index a8f376c67..70d67316c 100644 --- a/tests/Functional/ODMRepositoryProxyTest.php +++ b/tests/Functional/ODMRepositoryProxyTest.php @@ -2,7 +2,7 @@ namespace Zenstruck\Foundry\Tests\Functional; -use Zenstruck\Foundry\Tests\Fixtures\Document\Category; +use Zenstruck\Foundry\Tests\Fixtures\Document\ODMCategory; use Zenstruck\Foundry\Tests\Fixtures\Factories\ODM\CategoryFactory; /** @@ -19,7 +19,7 @@ protected function setUp(): void protected function categoryClass(): string { - return Category::class; + return ODMCategory::class; } protected function categoryFactoryClass(): string