Skip to content

Commit 0e0afb4

Browse files
makedomsmakouz
andauthored
Remove check for docblock when trying to find parent entities (#55)
Co-authored-by: Maxim Smakouz <m.smakouz@gmail.com>
1 parent fa3263e commit 0e0afb4

10 files changed

Lines changed: 151 additions & 4 deletions

File tree

src/Utils/EntityUtils.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ public function findParent(string $class, bool $root = true): ?string
4848
continue;
4949
}
5050

51-
if ($class->getDocComment() === false) {
52-
continue;
53-
}
54-
5551
$ann = $this->reader->firstClassMetadata($class, Entity::class);
5652
if ($ann !== null) {
5753
return $parent;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cycle\Annotated\Tests\Fixtures\Fixtures22\Annotated;
6+
7+
use Cycle\Annotated\Annotation\Entity;
8+
9+
/** @Entity*/
10+
class LocalManager extends LocalSupplier
11+
{
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cycle\Annotated\Tests\Fixtures\Fixtures22\Annotated;
6+
7+
use Cycle\Annotated\Annotation\Entity;
8+
9+
/** @Entity */
10+
class LocalSupplier extends Supplier
11+
{
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cycle\Annotated\Tests\Fixtures\Fixtures22\Annotated;
6+
7+
use Cycle\Annotated\Annotation\Entity;
8+
9+
/** @Entity */
10+
class Person
11+
{
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cycle\Annotated\Tests\Fixtures\Fixtures22\Annotated;
6+
7+
class Supplier extends Person
8+
{
9+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cycle\Annotated\Tests\Fixtures\Fixtures22\Attributed;
6+
7+
use Cycle\Annotated\Annotation\Entity;
8+
9+
#[Entity]
10+
class LocalManager extends LocalSupplier
11+
{
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cycle\Annotated\Tests\Fixtures\Fixtures22\Attributed;
6+
7+
use Cycle\Annotated\Annotation\Entity;
8+
9+
#[Entity]
10+
class LocalSupplier extends Supplier
11+
{
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cycle\Annotated\Tests\Fixtures\Fixtures22\Attributed;
6+
7+
use Cycle\Annotated\Annotation\Entity;
8+
9+
#[Entity]
10+
class Person
11+
{
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cycle\Annotated\Tests\Fixtures\Fixtures22\Attributed;
6+
7+
class Supplier extends Person
8+
{
9+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cycle\Annotated\Tests\Unit\Utils;
6+
7+
use Cycle\Annotated\Utils\EntityUtils;
8+
use PHPUnit\Framework\TestCase;
9+
use Spiral\Attributes\AnnotationReader;
10+
use Spiral\Attributes\AttributeReader;
11+
use Spiral\Attributes\ReaderInterface;
12+
13+
class EntityUtilsTest extends TestCase
14+
{
15+
/**
16+
* @dataProvider findParentDataProvider
17+
*/
18+
public function testFindParent(
19+
ReaderInterface $reader,
20+
string $child,
21+
bool $root,
22+
?string $expectedParent
23+
): void {
24+
$entityUtils = new EntityUtils($reader);
25+
26+
$actualParent = $entityUtils->findParent($child, $root);
27+
28+
$this->assertEquals($expectedParent, $actualParent);
29+
}
30+
31+
public function findParentDataProvider(): iterable
32+
{
33+
$namespace = 'Cycle\Annotated\Tests\Fixtures\Fixtures22';
34+
$readers = [
35+
'Attributed' => new AttributeReader(),
36+
'Annotated' => new AnnotationReader(),
37+
];
38+
39+
foreach ($readers as $readerType => $reader) {
40+
yield "$readerType Child Root"
41+
=> [$reader, "$namespace\\$readerType\\Person", true, null];
42+
yield "$readerType Child Not Root"
43+
=> [$reader, "$namespace\\$readerType\\Person", false, null];
44+
45+
yield "$readerType 1st Level Root"
46+
=> [$reader, "$namespace\\$readerType\\Supplier", true, "$namespace\\$readerType\\Person"];
47+
yield "$readerType 1st Level Not Root"
48+
=> [$reader, "$namespace\\$readerType\\Supplier", false, "$namespace\\$readerType\\Person"];
49+
50+
yield "$readerType 2nd Level Root"
51+
=> [$reader, "$namespace\\$readerType\\LocalSupplier", true, "$namespace\\$readerType\\Person"];
52+
yield "$readerType 2nd Level Root No Entity Attribute"
53+
=> [$reader, "$namespace\\$readerType\\LocalSupplier", false, "$namespace\\$readerType\\Person"];
54+
55+
yield "$readerType 3rd Level Root"
56+
=> [$reader, "$namespace\\$readerType\\LocalManager", true, "$namespace\\$readerType\\Person"];
57+
yield "$readerType 3rd Level Not Root"
58+
=> [$reader, "$namespace\\$readerType\\LocalManager", false, "$namespace\\$readerType\\LocalSupplier"];
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)