Skip to content

Commit

Permalink
Inspect columns in embeddables
Browse files Browse the repository at this point in the history
  • Loading branch information
malarzm committed Jan 28, 2020
1 parent 77d3d8e commit b99ae3d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/Rules/Doctrine/ORM/EntityColumnRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ public function processNode(Node $node, Scope $scope): array
}

$className = $class->getName();
if ($objectManager->getMetadataFactory()->isTransient($className)) {
return [];
}

try {
$metadata = $objectManager->getClassMetadata($className);
Expand Down
15 changes: 15 additions & 0 deletions tests/Rules/Doctrine/ORM/EntityColumnRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,21 @@ public function testEmbeddedWithWrongTypeHint(): void
]);
}

public function testEmbeddable(): void
{
$this->analyse([__DIR__ . '/data/Embeddable.php'], []);
}

public function testBrokenEmbeddable(): void
{
$this->analyse([__DIR__ . '/data/BrokenEmbeddable.php'], [
[
'Property PHPStan\Rules\Doctrine\ORM\BrokenEmbeddable::$one type mapping mismatch: database can contain string|null but property expects string.',
16,
],
]);
}

public function testUnknownType(): void
{
$this->analyse([__DIR__ . '/data/EntityWithUnknownType.php'], [
Expand Down
17 changes: 17 additions & 0 deletions tests/Rules/Doctrine/ORM/data/BrokenEmbeddable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php declare(strict_types = 1);

namespace PHPStan\Rules\Doctrine\ORM;

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Embeddable()
*/
class BrokenEmbeddable
{
/**
* @ORM\Column(type="string", nullable=true)
* @var string
*/
private $one;
}

0 comments on commit b99ae3d

Please sign in to comment.