Skip to content

Commit

Permalink
Merge pull request doctrine#1285 from nicolas-grekas/allow-no-mapping
Browse files Browse the repository at this point in the history
Don't throw NoMappingFound from OrmSchemaProvider
  • Loading branch information
stof authored Dec 23, 2022
2 parents 4eeb796 + 378cf4b commit 995158d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
9 changes: 0 additions & 9 deletions lib/Doctrine/Migrations/Provider/OrmSchemaProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
namespace Doctrine\Migrations\Provider;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\Provider\Exception\NoMappingFound;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Tools\SchemaTool;

use function count;
use function usort;

/**
Expand All @@ -29,18 +27,11 @@ public function __construct(EntityManagerInterface $em)
$this->entityManager = $em;
}

/**
* @throws NoMappingFound
*/
public function createSchema(): Schema
{
/** @var array<int, ClassMetadata<object>> $metadata */
$metadata = $this->entityManager->getMetadataFactory()->getAllMetadata();

if (count($metadata) === 0) {
throw NoMappingFound::new();
}

usort($metadata, static function (ClassMetadata $a, ClassMetadata $b): int {
return $a->getTableName() <=> $b->getTableName();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\Driver\XmlDriver;
use Doctrine\ORM\ORMSetup;
use UnexpectedValueException;

/**
* Tests the OrmSchemaProvider using a real entity manager.
Expand All @@ -37,10 +36,14 @@ public function testCreateSchemaFetchesMetadataFromEntityManager(): void
}
}

public function testEntityManagerWithoutMetadataCausesError(): void
/**
* It should be OK to use migrations to manage tables not managed by
* the ORM.
*
* @doesNotPerformAssertions
*/
public function testEntityManagerWithoutMetadata(): void
{
$this->expectException(UnexpectedValueException::class);

$this->config->setMetadataDriverImpl(new XmlDriver([]));

$this->ormProvider->createSchema();
Expand Down

0 comments on commit 995158d

Please sign in to comment.