Skip to content

Commit

Permalink
refactor: set all fixtures class name unique (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikophil committed Dec 6, 2022
1 parent 892ed14 commit 6bc81b1
Show file tree
Hide file tree
Showing 32 changed files with 300 additions and 518 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* @MongoDB\Document(collection="category")
*/
class Category
class ODMCategory
{
/**
* @MongoDB\Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* @MongoDB\Document(collection="post")
*/
class Post implements \Stringable
class ODMPost implements \Stringable
{
/**
* @MongoDB\Id
Expand Down Expand Up @@ -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;
Expand All @@ -85,7 +85,7 @@ public function getBody(): ?string
return $this->body;
}

public function getUser(): User
public function getUser(): ODMUser
{
return $this->user;
}
Expand Down Expand Up @@ -121,14 +121,14 @@ public function setPublishedAt(\DateTime $timestamp): void
}

/**
* @return Collection<Comment>
* @return Collection<ODMComment>
*/
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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* @MongoDB\Document(collection="tag")
*/
class Tag
class ODMTag
{
/**
* @MongoDB\Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* @MongoDB\EmbeddedDocument
*/
class User
class ODMUser
{
/**
* @MongoDB\Field(type="string")
Expand Down
12 changes: 6 additions & 6 deletions tests/Fixtures/Entity/Cascade/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @ORM\Entity
* @ORM\Table(name="category_cascade")
*/
class Category
class ProductCategory
{
/**
* @ORM\Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @ORM\Entity
* @ORM\Table(name="tag_cascade")
*/
class Tag
class ProductTag
{
/**
* @ORM\Id
Expand Down
4 changes: 2 additions & 2 deletions tests/Fixtures/Factories/ODM/CategoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <kevinbond@gmail.com>
Expand All @@ -12,7 +12,7 @@ final class CategoryFactory extends ModelFactory
{
protected static function getClass(): string
{
return Category::class;
return ODMCategory::class;
}

protected function getDefaults(): array
Expand Down
8 changes: 4 additions & 4 deletions tests/Fixtures/Factories/ODM/CommentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
];
}
Expand Down
14 changes: 7 additions & 7 deletions tests/Fixtures/Factories/ODM/PostFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -19,23 +19,23 @@ 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
{
return [
'title' => self::faker()->sentence(),
'body' => self::faker()->sentence(),
'user' => new User('user'),
'user' => new ODMUser('user'),
];
}
}
4 changes: 2 additions & 2 deletions tests/Fixtures/Factories/ODM/TagFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <kevinbond@gmail.com>
Expand All @@ -12,7 +12,7 @@ final class TagFactory extends ModelFactory
{
protected static function getClass(): string
{
return Tag::class;
return ODMTag::class;
}

protected function getDefaults(): array
Expand Down
4 changes: 2 additions & 2 deletions tests/Fixtures/Factories/ODM/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Post>
* @extends ModelFactory<ODMPost>
*
* @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
Expand Down Expand Up @@ -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;
}
}
Loading

0 comments on commit 6bc81b1

Please sign in to comment.