Skip to content

Commit f5224ba

Browse files
committed
Refactor some mapping tests for improved coverage and forward compat
1 parent a4f15df commit f5224ba

11 files changed

+542
-93
lines changed

phpstan-baseline.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,11 @@ parameters:
570570
count: 3
571571
path: src/Uploadable/UploadableListener.php
572572

573+
-
574+
message: "#^Class Gedmo\\\\Tests\\\\Translatable\\\\Fixture\\\\CategoryTranslation not found\\.$#"
575+
count: 1
576+
path: tests/Gedmo/Mapping/Fixture/Category.php
577+
573578
-
574579
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\<T of object\\>\\:\\:mapField\\(\\)\\.$#"
575580
count: 2
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Doctrine Behavioral Extensions package.
7+
* (c) Gediminas Morkevicius <[email protected]> http://www.gediminasm.org
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Gedmo\Tests\Mapping\Fixture;
13+
14+
use Doctrine\DBAL\Types\Types;
15+
use Doctrine\ORM\Mapping as ORM;
16+
use Gedmo\Mapping\Annotation as Gedmo;
17+
18+
/**
19+
* @ORM\MappedSuperclass
20+
*/
21+
#[ORM\MappedSuperclass]
22+
class BaseCategory
23+
{
24+
/**
25+
* @ORM\Column(type="integer")
26+
*
27+
* @Gedmo\TreeLeft
28+
*/
29+
#[ORM\Column(type: Types::INTEGER)]
30+
#[Gedmo\TreeLeft]
31+
private ?int $left = null;
32+
33+
/**
34+
* @ORM\Column(type="integer")
35+
*
36+
* @Gedmo\TreeRight
37+
*/
38+
#[ORM\Column(type: Types::INTEGER)]
39+
#[Gedmo\TreeRight]
40+
private ?int $right = null;
41+
42+
/**
43+
* @ORM\Column(type="integer")
44+
*
45+
* @Gedmo\TreeLevel
46+
*/
47+
#[ORM\Column(type: Types::INTEGER)]
48+
#[Gedmo\TreeLevel]
49+
private ?int $level = null;
50+
51+
/**
52+
* @ORM\Column(type="integer")
53+
*
54+
* @Gedmo\TreeRoot
55+
*/
56+
#[ORM\Column(type: Types::INTEGER)]
57+
#[Gedmo\TreeRoot]
58+
private ?int $rooted = null;
59+
60+
/**
61+
* @ORM\Column(type="datetime")
62+
*
63+
* @Gedmo\Timestampable(on="create")
64+
*/
65+
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
66+
#[Gedmo\Timestampable(on: 'create')]
67+
private ?\DateTime $created = null;
68+
69+
/**
70+
* @ORM\Column(type="date")
71+
*
72+
* @Gedmo\Timestampable(on="update")
73+
*/
74+
#[ORM\Column(type: Types::DATE_MUTABLE)]
75+
#[Gedmo\Timestampable(on: 'update')]
76+
private ?\DateTime $updated = null;
77+
78+
public function setCreated(\DateTime $created): void
79+
{
80+
$this->created = $created;
81+
}
82+
83+
/**
84+
* @return \DateTime $created
85+
*/
86+
public function getCreated(): ?\DateTime
87+
{
88+
return $this->created;
89+
}
90+
91+
public function setUpdated(\DateTime $updated): void
92+
{
93+
$this->updated = $updated;
94+
}
95+
96+
public function getUpdated(): ?\DateTime
97+
{
98+
return $this->updated;
99+
}
100+
101+
public function setLeft(int $left): self
102+
{
103+
$this->left = $left;
104+
105+
return $this;
106+
}
107+
108+
public function getLeft(): int
109+
{
110+
return $this->left;
111+
}
112+
113+
public function setRight(int $right): self
114+
{
115+
$this->right = $right;
116+
117+
return $this;
118+
}
119+
120+
public function getRight(): int
121+
{
122+
return $this->right;
123+
}
124+
125+
public function setLevel(int $level): self
126+
{
127+
$this->level = $level;
128+
129+
return $this;
130+
}
131+
132+
public function getLevel(): int
133+
{
134+
return $this->level;
135+
}
136+
137+
public function setRooted(int $rooted): self
138+
{
139+
$this->rooted = $rooted;
140+
141+
return $this;
142+
}
143+
144+
public function getRooted(): int
145+
{
146+
return $this->rooted;
147+
}
148+
}
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Doctrine Behavioral Extensions package.
7+
* (c) Gediminas Morkevicius <[email protected]> http://www.gediminasm.org
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Gedmo\Tests\Mapping\Fixture;
13+
14+
use Doctrine\Common\Collections\ArrayCollection;
15+
use Doctrine\Common\Collections\Collection;
16+
use Doctrine\DBAL\Types\Types;
17+
use Doctrine\ORM\Mapping as ORM;
18+
use Gedmo\Loggable\Entity\LogEntry;
19+
use Gedmo\Mapping\Annotation as Gedmo;
20+
use Gedmo\Sluggable\Handler\RelativeSlugHandler;
21+
use Gedmo\Sluggable\Handler\TreeSlugHandler;
22+
use Gedmo\Tests\Translatable\Fixture\CategoryTranslation;
23+
24+
/**
25+
* @ORM\Entity
26+
* @ORM\Table(name="categories")
27+
*
28+
* @Gedmo\Loggable(logEntryClass="Gedmo\Loggable\Entity\LogEntry")
29+
* @Gedmo\TranslationEntity(class="Gedmo\Tests\Translatable\Fixture\CategoryTranslation")
30+
* @Gedmo\Tree(type="nested")
31+
*/
32+
#[ORM\Entity]
33+
#[ORM\Table(name: 'categories')]
34+
#[Gedmo\Loggable(logEntryClass: LogEntry::class)]
35+
#[Gedmo\TranslationEntity(class: CategoryTranslation::class)]
36+
#[Gedmo\Tree(type: 'nested')]
37+
class Category extends BaseCategory
38+
{
39+
/**
40+
* @var int
41+
*
42+
* @ORM\Id
43+
* @ORM\GeneratedValue
44+
* @ORM\Column(type="integer")
45+
*/
46+
#[ORM\Id]
47+
#[ORM\GeneratedValue]
48+
#[ORM\Column(type: Types::INTEGER)]
49+
private $id;
50+
51+
/**
52+
* @ORM\Column(type="string", length=64)
53+
*
54+
* @Gedmo\Translatable
55+
*/
56+
#[ORM\Column(type: Types::STRING, length: 64)]
57+
#[Gedmo\Translatable]
58+
private ?string $title = null;
59+
60+
/**
61+
* @ORM\Column(type="string", length=64)
62+
*
63+
* @Gedmo\Slug(
64+
* fields={"title"},
65+
* style="camel",
66+
* separator="_",
67+
* handlers={
68+
* @Gedmo\SlugHandler(class="Gedmo\Sluggable\Handler\RelativeSlugHandler", options={
69+
* @Gedmo\SlugHandlerOption(name="relationField", value="parent"),
70+
* @Gedmo\SlugHandlerOption(name="relationSlugField", value="parent"),
71+
* @Gedmo\SlugHandlerOption(name="separator", value="/")
72+
* }),
73+
* @Gedmo\SlugHandler(class="Gedmo\Sluggable\Handler\TreeSlugHandler", options={
74+
* @Gedmo\SlugHandlerOption(name="parentRelationField", value="parent"),
75+
* @Gedmo\SlugHandlerOption(name="separator", value="/")
76+
* })
77+
* }
78+
* )
79+
*/
80+
#[ORM\Column(type: Types::STRING, length: 64)]
81+
#[Gedmo\Slug(fields: ['title'], style: 'camel', separator: '_')]
82+
#[Gedmo\SlugHandler(class: RelativeSlugHandler::class, options: ['relationField' => 'parent', 'relationSlugField' => 'slug', 'separator' => '/'])]
83+
#[Gedmo\SlugHandler(class: TreeSlugHandler::class, options: ['parentRelationField' => 'parent', 'separator' => '/'])]
84+
private ?string $slug = null;
85+
86+
/**
87+
* @var Collection<int, self>
88+
*
89+
* @ORM\OneToMany(targetEntity="Gedmo\Tests\Mapping\Fixture\Category", mappedBy="parent")
90+
*/
91+
#[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parent')]
92+
private $children;
93+
94+
/**
95+
* @ORM\ManyToOne(targetEntity="Gedmo\Tests\Mapping\Fixture\Category", inversedBy="children")
96+
*
97+
* @Gedmo\TreeParent
98+
*/
99+
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
100+
#[Gedmo\TreeParent]
101+
private ?Category $parent = null;
102+
103+
/**
104+
* @var \DateTime
105+
*
106+
* @ORM\Column(type="date")
107+
*
108+
* @Gedmo\Timestampable(on="change", field="title", value="Test")
109+
*/
110+
#[ORM\Column(type: Types::DATE_MUTABLE)]
111+
#[Gedmo\Timestampable(on: 'change', field: 'title', value: 'Test')]
112+
private $changed;
113+
114+
public function __construct()
115+
{
116+
$this->children = new ArrayCollection();
117+
}
118+
119+
/**
120+
* @return int $id
121+
*/
122+
public function getId(): int
123+
{
124+
return $this->id;
125+
}
126+
127+
public function setTitle(string $title): void
128+
{
129+
$this->title = $title;
130+
}
131+
132+
public function getTitle(): string
133+
{
134+
return $this->title;
135+
}
136+
137+
public function setSlug(string $slug): void
138+
{
139+
$this->slug = $slug;
140+
}
141+
142+
/**
143+
* @return string $slug
144+
*/
145+
public function getSlug(): string
146+
{
147+
return $this->slug;
148+
}
149+
150+
public function addChildren(self $children): void
151+
{
152+
$this->children[] = $children;
153+
}
154+
155+
/**
156+
* @return Collection<int, self> $children
157+
*/
158+
public function getChildren()
159+
{
160+
return $this->children;
161+
}
162+
163+
public function setParent(self $parent): void
164+
{
165+
$this->parent = $parent;
166+
}
167+
168+
/**
169+
* @return self $parent
170+
*/
171+
public function getParent(): self
172+
{
173+
return $this->parent;
174+
}
175+
}

tests/Gedmo/Mapping/Fixture/Loggable.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace Gedmo\Tests\Mapping\Fixture;
1111

12+
use Doctrine\DBAL\Types\Types;
1213
use Doctrine\ORM\Mapping as ORM;
1314
use Gedmo\Mapping\Annotation as Gedmo;
1415

@@ -17,6 +18,8 @@
1718
*
1819
* @Gedmo\Loggable
1920
*/
21+
#[ORM\Entity]
22+
#[Gedmo\Loggable]
2023
class Loggable
2124
{
2225
/**
@@ -26,13 +29,18 @@ class Loggable
2629
* @ORM\GeneratedValue
2730
* @ORM\Column(type="integer")
2831
*/
32+
#[ORM\Id]
33+
#[ORM\GeneratedValue]
34+
#[ORM\Column(type: Types::INTEGER)]
2935
private $id;
3036

3137
/**
3238
* @ORM\Column(name="title", type="string", length=64)
3339
*
3440
* @Gedmo\Versioned
3541
*/
42+
#[ORM\Column(name: 'title', type: Types::STRING, length: 64)]
43+
#[Gedmo\Versioned]
3644
private ?string $title = null;
3745

3846
public function getId(): int

0 commit comments

Comments
 (0)