Skip to content
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
4 changes: 0 additions & 4 deletions src/Utils/EntityUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ public function findParent(string $class, bool $root = true): ?string
continue;
}

if ($class->getDocComment() === false) {
continue;
}

$ann = $this->reader->firstClassMetadata($class, Entity::class);
if ($ann !== null) {
return $parent;
Expand Down
12 changes: 12 additions & 0 deletions tests/Annotated/Fixtures/Fixtures22/Annotated/LocalManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Cycle\Annotated\Tests\Fixtures\Fixtures22\Annotated;

use Cycle\Annotated\Annotation\Entity;

/** @Entity*/
class LocalManager extends LocalSupplier
{
}
12 changes: 12 additions & 0 deletions tests/Annotated/Fixtures/Fixtures22/Annotated/LocalSupplier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Cycle\Annotated\Tests\Fixtures\Fixtures22\Annotated;

use Cycle\Annotated\Annotation\Entity;

/** @Entity */
class LocalSupplier extends Supplier
{
}
12 changes: 12 additions & 0 deletions tests/Annotated/Fixtures/Fixtures22/Annotated/Person.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Cycle\Annotated\Tests\Fixtures\Fixtures22\Annotated;

use Cycle\Annotated\Annotation\Entity;

/** @Entity */
class Person
{
}
9 changes: 9 additions & 0 deletions tests/Annotated/Fixtures/Fixtures22/Annotated/Supplier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Cycle\Annotated\Tests\Fixtures\Fixtures22\Annotated;

class Supplier extends Person
{
}
12 changes: 12 additions & 0 deletions tests/Annotated/Fixtures/Fixtures22/Attributed/LocalManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Cycle\Annotated\Tests\Fixtures\Fixtures22\Attributed;

use Cycle\Annotated\Annotation\Entity;

#[Entity]
class LocalManager extends LocalSupplier
{
}
12 changes: 12 additions & 0 deletions tests/Annotated/Fixtures/Fixtures22/Attributed/LocalSupplier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Cycle\Annotated\Tests\Fixtures\Fixtures22\Attributed;

use Cycle\Annotated\Annotation\Entity;

#[Entity]
class LocalSupplier extends Supplier
{
}
12 changes: 12 additions & 0 deletions tests/Annotated/Fixtures/Fixtures22/Attributed/Person.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Cycle\Annotated\Tests\Fixtures\Fixtures22\Attributed;

use Cycle\Annotated\Annotation\Entity;

#[Entity]
class Person
{
}
9 changes: 9 additions & 0 deletions tests/Annotated/Fixtures/Fixtures22/Attributed/Supplier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Cycle\Annotated\Tests\Fixtures\Fixtures22\Attributed;

class Supplier extends Person
{
}
61 changes: 61 additions & 0 deletions tests/Annotated/Unit/Utils/EntityUtilsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

namespace Cycle\Annotated\Tests\Unit\Utils;

use Cycle\Annotated\Utils\EntityUtils;
use PHPUnit\Framework\TestCase;
use Spiral\Attributes\AnnotationReader;
use Spiral\Attributes\AttributeReader;
use Spiral\Attributes\ReaderInterface;

class EntityUtilsTest extends TestCase
{
/**
* @dataProvider findParentDataProvider
*/
public function testFindParent(
ReaderInterface $reader,
string $child,
bool $root,
?string $expectedParent
): void {
$entityUtils = new EntityUtils($reader);

$actualParent = $entityUtils->findParent($child, $root);

$this->assertEquals($expectedParent, $actualParent);
}

public function findParentDataProvider(): iterable
{
$namespace = 'Cycle\Annotated\Tests\Fixtures\Fixtures22';
$readers = [
'Attributed' => new AttributeReader(),
'Annotated' => new AnnotationReader(),
];

foreach ($readers as $readerType => $reader) {
yield "$readerType Child Root"
=> [$reader, "$namespace\\$readerType\\Person", true, null];
yield "$readerType Child Not Root"
=> [$reader, "$namespace\\$readerType\\Person", false, null];

yield "$readerType 1st Level Root"
=> [$reader, "$namespace\\$readerType\\Supplier", true, "$namespace\\$readerType\\Person"];
yield "$readerType 1st Level Not Root"
=> [$reader, "$namespace\\$readerType\\Supplier", false, "$namespace\\$readerType\\Person"];

yield "$readerType 2nd Level Root"
=> [$reader, "$namespace\\$readerType\\LocalSupplier", true, "$namespace\\$readerType\\Person"];
yield "$readerType 2nd Level Root No Entity Attribute"
=> [$reader, "$namespace\\$readerType\\LocalSupplier", false, "$namespace\\$readerType\\Person"];

yield "$readerType 3rd Level Root"
=> [$reader, "$namespace\\$readerType\\LocalManager", true, "$namespace\\$readerType\\Person"];
yield "$readerType 3rd Level Not Root"
=> [$reader, "$namespace\\$readerType\\LocalManager", false, "$namespace\\$readerType\\LocalSupplier"];
}
}
}