Skip to content

Commit

Permalink
Merge pull request #300 from mikeSimonson/orm-24
Browse files Browse the repository at this point in the history
Making sure that we only require the orm 2.4 for now
  • Loading branch information
mikeSimonson committed Jul 5, 2015
2 parents 70c5801 + 487224e commit 78954cc
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
4 changes: 0 additions & 4 deletions composer.json
Expand Up @@ -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"
},
Expand Down
28 changes: 27 additions & 1 deletion lib/Doctrine/DBAL/Migrations/Provider/OrmSchemaProvider.php
Expand Up @@ -19,6 +19,7 @@

namespace Doctrine\DBAL\Migrations\Provider;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Tools\SchemaTool;

Expand All @@ -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;
}

Expand All @@ -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 function isEntityManager($manager)
{
return $manager instanceof EntityManagerInterface || $manager instanceof EntityManager;
}

}
Expand Up @@ -56,6 +56,26 @@ public function testEntityManagerWithoutMetadataCausesError()
$this->ormProvider->createSchema();
}

public 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();
Expand Down

0 comments on commit 78954cc

Please sign in to comment.