Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
janklan committed Sep 24, 2024
1 parent b91830b commit 95e9d33
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Tools/SchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use ReflectionEnum;
use ReflectionNamedType;

use function array_column;
use function array_diff;
use function array_filter;
use function array_key_exists;
Expand Down Expand Up @@ -276,6 +277,22 @@ public function validateClass(ClassMetadata $class): array
}
}
}

if ($assoc->isIndexed()) {
$joinColumns = array_column($targetMetadata->getAssociationMappings(), 'joinColumns');
$joinColumns = array_column($joinColumns, 0);
$joinColumns = array_column($joinColumns, 'name');

$allAvailableIndexNames = [
...$joinColumns,
...$targetMetadata->getColumnNames(),
];

if (! in_array($assoc->indexBy(), $allAvailableIndexNames, true)) {
$ce[] = 'The association ' . $class->name . '#' . $fieldName . ' is indexed by a field ' .
$assoc->indexBy() . ' on ' . $targetMetadata->name . ', but the field doesn\'t exist.';
}
}
}

if (
Expand Down
13 changes: 13 additions & 0 deletions tests/Tests/ORM/Functional/SchemaValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Doctrine\Tests\DbalTypes\CustomIdObjectType;
use Doctrine\Tests\DbalTypes\NegativeToPositiveType;
use Doctrine\Tests\DbalTypes\UpperCaseStringType;
use Doctrine\Tests\ORM\Functional\Ticket\GH11608\GH11608Test;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
Expand Down Expand Up @@ -52,6 +53,18 @@ public static function dataValidateModelSets(): array
$modelSets = [];

foreach (array_keys(self::$modelSets) as $modelSet) {

/**
* GH11608 Tests whether the Schema validator picks up on invalid mapping. The entities are intentionally
* invalid, and so for the purpose of this test case, those entities should be ignored.
*
* @see GH11608Test
* @see https://github.com/doctrine/orm/issues/11608
*/
if ($modelSet === GH11608Test::class) {
continue;
}

$modelSets[$modelSet] = [$modelSet];
}

Expand Down

0 comments on commit 95e9d33

Please sign in to comment.