From 8510c46043627b5c51354df889d54ff9f0f1f491 Mon Sep 17 00:00:00 2001 From: mike Date: Thu, 25 Jun 2015 21:33:52 +0200 Subject: [PATCH 1/2] Temporary ugliness to support earlier version of the orm. This will be reverted for 1.1 first thing --- composer.json | 4 --- .../Migrations/Provider/OrmSchemaProvider.php | 28 ++++++++++++++++++- .../Tests/Provider/OrmSchemaProviderTest.php | 20 +++++++++++++ 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index ec0deec15a..b9d85b4684 100644 --- a/composer.json +++ b/composer.json @@ -23,10 +23,6 @@ "mockery/mockery": "^0.9.4", "johnkary/phpunit-speedtrap": "~1.0@dev" }, - "conflict": { - "doctrine/orm": "<2.4" - - }, "suggest": { "symfony/console": "to run the migration from the console" }, diff --git a/lib/Doctrine/DBAL/Migrations/Provider/OrmSchemaProvider.php b/lib/Doctrine/DBAL/Migrations/Provider/OrmSchemaProvider.php index 9226ba2f93..083602218a 100644 --- a/lib/Doctrine/DBAL/Migrations/Provider/OrmSchemaProvider.php +++ b/lib/Doctrine/DBAL/Migrations/Provider/OrmSchemaProvider.php @@ -19,6 +19,7 @@ namespace Doctrine\DBAL\Migrations\Provider; +use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Tools\SchemaTool; @@ -34,8 +35,15 @@ final class OrmSchemaProvider implements SchemaProviderInterface */ private $entityManager; - public function __construct(EntityManagerInterface $em) + public function __construct($em) { + if (!$this->isEntityManager($em)) { + throw new \InvalidArgumentException(sprintf( + '$em is not a valid Doctrine ORM Entity Manager, got "%s"', + is_object($em) ? get_class($em) : gettype($em) + )); + } + $this->entityManager = $em; } @@ -53,4 +61,22 @@ public function createSchema() return $tool->getSchemaFromMetadata($metadata); } + + + /** + * Doctrine's EntityManagerInterface was introduced in version 2.4, since this + * library allows those older version we need to be able to check for those + * old ORM versions. Hence the helper method. + * + * No need to check to see if EntityManagerInterface exists first here, PHP + * doesn't care. + * + * @param mixed $manager Hopefully an entity manager, but it may be anything + * @return boolean + */ + private static function isEntityManager($manager) + { + return $manager instanceof EntityManagerInterface || $manager instanceof EntityManager; + } + } diff --git a/tests/Doctrine/DBAL/Migrations/Tests/Provider/OrmSchemaProviderTest.php b/tests/Doctrine/DBAL/Migrations/Tests/Provider/OrmSchemaProviderTest.php index 732334e89f..e59d7de5a0 100644 --- a/tests/Doctrine/DBAL/Migrations/Tests/Provider/OrmSchemaProviderTest.php +++ b/tests/Doctrine/DBAL/Migrations/Tests/Provider/OrmSchemaProviderTest.php @@ -56,6 +56,26 @@ public function testEntityManagerWithoutMetadataCausesError() $this->ormProvider->createSchema(); } + public static function notEntityManagers() + { + return array( + array(new \stdclass), + array(false), + array(1), + array('oops'), + array(1.0), + ); + } + + /** + * @dataProvider notEntityManagers + * @expectedException InvalidArgumentException + */ + public function testPassingAnInvalidEntityManagerToConstructorCausesError($em) + { + new OrmSchemaProvider($em); + } + protected function setUp() { $this->conn = $this->getSqliteConnection(); From 487224e0f339ff21912147eabebf9c589acf7233 Mon Sep 17 00:00:00 2001 From: mike Date: Tue, 30 Jun 2015 11:59:09 +0200 Subject: [PATCH 2/2] Removing the static keyword that slipt there by mistake --- lib/Doctrine/DBAL/Migrations/Provider/OrmSchemaProvider.php | 2 +- .../DBAL/Migrations/Tests/Provider/OrmSchemaProviderTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/DBAL/Migrations/Provider/OrmSchemaProvider.php b/lib/Doctrine/DBAL/Migrations/Provider/OrmSchemaProvider.php index 083602218a..9ad213e044 100644 --- a/lib/Doctrine/DBAL/Migrations/Provider/OrmSchemaProvider.php +++ b/lib/Doctrine/DBAL/Migrations/Provider/OrmSchemaProvider.php @@ -74,7 +74,7 @@ public function createSchema() * @param mixed $manager Hopefully an entity manager, but it may be anything * @return boolean */ - private static function isEntityManager($manager) + private function isEntityManager($manager) { return $manager instanceof EntityManagerInterface || $manager instanceof EntityManager; } diff --git a/tests/Doctrine/DBAL/Migrations/Tests/Provider/OrmSchemaProviderTest.php b/tests/Doctrine/DBAL/Migrations/Tests/Provider/OrmSchemaProviderTest.php index e59d7de5a0..9fbd6a838a 100644 --- a/tests/Doctrine/DBAL/Migrations/Tests/Provider/OrmSchemaProviderTest.php +++ b/tests/Doctrine/DBAL/Migrations/Tests/Provider/OrmSchemaProviderTest.php @@ -56,7 +56,7 @@ public function testEntityManagerWithoutMetadataCausesError() $this->ormProvider->createSchema(); } - public static function notEntityManagers() + public function notEntityManagers() { return array( array(new \stdclass),