-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor some mapping tests for improved coverage and forward compat #2732
Merged
franmomu
merged 1 commit into
doctrine-extensions:main
from
mbabker:mapping-test-refactoring
Dec 5, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Doctrine Behavioral Extensions package. | ||
* (c) Gediminas Morkevicius <gediminas.morkevicius@gmail.com> http://www.gediminasm.org | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Gedmo\Tests\Mapping\Fixture; | ||
|
||
use Doctrine\DBAL\Types\Types; | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Gedmo\Mapping\Annotation as Gedmo; | ||
|
||
/** | ||
* @ORM\MappedSuperclass | ||
*/ | ||
#[ORM\MappedSuperclass] | ||
class BaseCategory | ||
{ | ||
/** | ||
* @ORM\Column(type="integer") | ||
* | ||
* @Gedmo\TreeLeft | ||
*/ | ||
#[ORM\Column(type: Types::INTEGER)] | ||
#[Gedmo\TreeLeft] | ||
private ?int $left = null; | ||
|
||
/** | ||
* @ORM\Column(type="integer") | ||
* | ||
* @Gedmo\TreeRight | ||
*/ | ||
#[ORM\Column(type: Types::INTEGER)] | ||
#[Gedmo\TreeRight] | ||
private ?int $right = null; | ||
|
||
/** | ||
* @ORM\Column(type="integer") | ||
* | ||
* @Gedmo\TreeLevel | ||
*/ | ||
#[ORM\Column(type: Types::INTEGER)] | ||
#[Gedmo\TreeLevel] | ||
private ?int $level = null; | ||
|
||
/** | ||
* @ORM\Column(type="integer") | ||
* | ||
* @Gedmo\TreeRoot | ||
*/ | ||
#[ORM\Column(type: Types::INTEGER)] | ||
#[Gedmo\TreeRoot] | ||
private ?int $rooted = null; | ||
|
||
/** | ||
* @ORM\Column(type="datetime") | ||
* | ||
* @Gedmo\Timestampable(on="create") | ||
*/ | ||
#[ORM\Column(type: Types::DATETIME_MUTABLE)] | ||
#[Gedmo\Timestampable(on: 'create')] | ||
private ?\DateTime $created = null; | ||
|
||
/** | ||
* @ORM\Column(type="date") | ||
* | ||
* @Gedmo\Timestampable(on="update") | ||
*/ | ||
#[ORM\Column(type: Types::DATE_MUTABLE)] | ||
#[Gedmo\Timestampable(on: 'update')] | ||
private ?\DateTime $updated = null; | ||
|
||
public function setCreated(\DateTime $created): void | ||
{ | ||
$this->created = $created; | ||
} | ||
|
||
/** | ||
* @return \DateTime $created | ||
*/ | ||
public function getCreated(): ?\DateTime | ||
{ | ||
return $this->created; | ||
} | ||
|
||
public function setUpdated(\DateTime $updated): void | ||
{ | ||
$this->updated = $updated; | ||
} | ||
|
||
public function getUpdated(): ?\DateTime | ||
{ | ||
return $this->updated; | ||
} | ||
|
||
public function setLeft(int $left): self | ||
{ | ||
$this->left = $left; | ||
|
||
return $this; | ||
} | ||
|
||
public function getLeft(): int | ||
{ | ||
return $this->left; | ||
} | ||
|
||
public function setRight(int $right): self | ||
{ | ||
$this->right = $right; | ||
|
||
return $this; | ||
} | ||
|
||
public function getRight(): int | ||
{ | ||
return $this->right; | ||
} | ||
|
||
public function setLevel(int $level): self | ||
{ | ||
$this->level = $level; | ||
|
||
return $this; | ||
} | ||
|
||
public function getLevel(): int | ||
{ | ||
return $this->level; | ||
} | ||
|
||
public function setRooted(int $rooted): self | ||
{ | ||
$this->rooted = $rooted; | ||
|
||
return $this; | ||
} | ||
|
||
public function getRooted(): int | ||
{ | ||
return $this->rooted; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Doctrine Behavioral Extensions package. | ||
* (c) Gediminas Morkevicius <gediminas.morkevicius@gmail.com> http://www.gediminasm.org | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Gedmo\Tests\Mapping\Fixture; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\Common\Collections\Collection; | ||
use Doctrine\DBAL\Types\Types; | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Gedmo\Loggable\Entity\LogEntry; | ||
use Gedmo\Mapping\Annotation as Gedmo; | ||
use Gedmo\Sluggable\Handler\RelativeSlugHandler; | ||
use Gedmo\Sluggable\Handler\TreeSlugHandler; | ||
use Gedmo\Tests\Translatable\Fixture\CategoryTranslation; | ||
|
||
/** | ||
* @ORM\Entity | ||
* @ORM\Table(name="categories") | ||
* | ||
* @Gedmo\Loggable(logEntryClass="Gedmo\Loggable\Entity\LogEntry") | ||
* @Gedmo\TranslationEntity(class="Gedmo\Tests\Translatable\Fixture\CategoryTranslation") | ||
* @Gedmo\Tree(type="nested") | ||
*/ | ||
#[ORM\Entity] | ||
#[ORM\Table(name: 'categories')] | ||
#[Gedmo\Loggable(logEntryClass: LogEntry::class)] | ||
#[Gedmo\TranslationEntity(class: CategoryTranslation::class)] | ||
#[Gedmo\Tree(type: 'nested')] | ||
class Category extends BaseCategory | ||
{ | ||
/** | ||
* @var int | ||
* | ||
* @ORM\Id | ||
* @ORM\GeneratedValue | ||
* @ORM\Column(type="integer") | ||
*/ | ||
#[ORM\Id] | ||
#[ORM\GeneratedValue] | ||
#[ORM\Column(type: Types::INTEGER)] | ||
private $id; | ||
|
||
/** | ||
* @ORM\Column(type="string", length=64) | ||
* | ||
* @Gedmo\Translatable | ||
*/ | ||
#[ORM\Column(type: Types::STRING, length: 64)] | ||
#[Gedmo\Translatable] | ||
private ?string $title = null; | ||
|
||
/** | ||
* @ORM\Column(type="string", length=64) | ||
* | ||
* @Gedmo\Slug( | ||
* fields={"title"}, | ||
* style="camel", | ||
* separator="_", | ||
* handlers={ | ||
* @Gedmo\SlugHandler(class="Gedmo\Sluggable\Handler\RelativeSlugHandler", options={ | ||
* @Gedmo\SlugHandlerOption(name="relationField", value="parent"), | ||
* @Gedmo\SlugHandlerOption(name="relationSlugField", value="parent"), | ||
* @Gedmo\SlugHandlerOption(name="separator", value="/") | ||
* }), | ||
* @Gedmo\SlugHandler(class="Gedmo\Sluggable\Handler\TreeSlugHandler", options={ | ||
* @Gedmo\SlugHandlerOption(name="parentRelationField", value="parent"), | ||
* @Gedmo\SlugHandlerOption(name="separator", value="/") | ||
* }) | ||
* } | ||
* ) | ||
*/ | ||
#[ORM\Column(type: Types::STRING, length: 64)] | ||
#[Gedmo\Slug(fields: ['title'], style: 'camel', separator: '_')] | ||
#[Gedmo\SlugHandler(class: RelativeSlugHandler::class, options: ['relationField' => 'parent', 'relationSlugField' => 'slug', 'separator' => '/'])] | ||
#[Gedmo\SlugHandler(class: TreeSlugHandler::class, options: ['parentRelationField' => 'parent', 'separator' => '/'])] | ||
private ?string $slug = null; | ||
|
||
/** | ||
* @var Collection<int, self> | ||
* | ||
* @ORM\OneToMany(targetEntity="Gedmo\Tests\Mapping\Fixture\Category", mappedBy="parent") | ||
*/ | ||
#[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parent')] | ||
private $children; | ||
|
||
/** | ||
* @ORM\ManyToOne(targetEntity="Gedmo\Tests\Mapping\Fixture\Category", inversedBy="children") | ||
* | ||
* @Gedmo\TreeParent | ||
*/ | ||
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')] | ||
#[Gedmo\TreeParent] | ||
private ?Category $parent = null; | ||
|
||
/** | ||
* @var \DateTime | ||
* | ||
* @ORM\Column(type="date") | ||
* | ||
* @Gedmo\Timestampable(on="change", field="title", value="Test") | ||
*/ | ||
#[ORM\Column(type: Types::DATE_MUTABLE)] | ||
#[Gedmo\Timestampable(on: 'change', field: 'title', value: 'Test')] | ||
private $changed; | ||
|
||
public function __construct() | ||
{ | ||
$this->children = new ArrayCollection(); | ||
} | ||
|
||
/** | ||
* @return int $id | ||
*/ | ||
public function getId(): int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function setTitle(string $title): void | ||
{ | ||
$this->title = $title; | ||
} | ||
|
||
public function getTitle(): string | ||
{ | ||
return $this->title; | ||
} | ||
|
||
public function setSlug(string $slug): void | ||
{ | ||
$this->slug = $slug; | ||
} | ||
|
||
/** | ||
* @return string $slug | ||
*/ | ||
public function getSlug(): string | ||
{ | ||
return $this->slug; | ||
} | ||
|
||
public function addChildren(self $children): void | ||
{ | ||
$this->children[] = $children; | ||
} | ||
|
||
/** | ||
* @return Collection<int, self> $children | ||
*/ | ||
public function getChildren() | ||
{ | ||
return $this->children; | ||
} | ||
|
||
public function setParent(self $parent): void | ||
{ | ||
$this->parent = $parent; | ||
} | ||
|
||
/** | ||
* @return self $parent | ||
*/ | ||
public function getParent(): self | ||
{ | ||
return $this->parent; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Baselining this because the YAML mapping that the annotation/attribute mappings were generated from references this non-existing class, and PHPStan now (rightfully) groans about it. The test fixtures should probably use an existing class at some point in the future, but for now, its absence doesn't break anything.