Skip to content
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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,11 @@ parameters:
count: 3
path: src/Uploadable/UploadableListener.php

-
message: "#^Class Gedmo\\\\Tests\\\\Translatable\\\\Fixture\\\\CategoryTranslation not found\\.$#"
Copy link
Contributor Author

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.

count: 1
path: tests/Gedmo/Mapping/Fixture/Category.php

-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\<T of object\\>\\:\\:mapField\\(\\)\\.$#"
count: 2
Expand Down
148 changes: 148 additions & 0 deletions tests/Gedmo/Mapping/Fixture/BaseCategory.php
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;
}
}
175 changes: 175 additions & 0 deletions tests/Gedmo/Mapping/Fixture/Category.php
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;
}
}
8 changes: 8 additions & 0 deletions tests/Gedmo/Mapping/Fixture/Loggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Gedmo\Tests\Mapping\Fixture;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;

Expand All @@ -17,6 +18,8 @@
*
* @Gedmo\Loggable
*/
#[ORM\Entity]
#[Gedmo\Loggable]
class Loggable
{
/**
Expand All @@ -26,13 +29,18 @@ class Loggable
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
private $id;

/**
* @ORM\Column(name="title", type="string", length=64)
*
* @Gedmo\Versioned
*/
#[ORM\Column(name: 'title', type: Types::STRING, length: 64)]
mbabker marked this conversation as resolved.
Show resolved Hide resolved
#[Gedmo\Versioned]
private ?string $title = null;

public function getId(): int
Expand Down
Loading
Loading