diff --git a/lib/Doctrine/ORM/EntityRepository.php b/lib/Doctrine/ORM/EntityRepository.php index 48ba9dc9d..b458a0aeb 100644 --- a/lib/Doctrine/ORM/EntityRepository.php +++ b/lib/Doctrine/ORM/EntityRepository.php @@ -185,7 +185,7 @@ class EntityRepository ); } - if ( ! isset($arguments[0])) { + if ( ! array_key_exists(0, $arguments)) { throw ORMException::findByRequiresParameter($method.$by); } diff --git a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php index 15ad790f9..8916d0a54 100644 --- a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php @@ -19,7 +19,8 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase parent::setUp(); } - public function testBasicFinders() { + public function loadFixture() + { $user = new CmsUser; $user->name = 'Roman'; $user->username = 'romanb'; @@ -38,35 +39,58 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase unset($user2); $this->_em->clear(); + return $user1Id; + } + + public function testBasicFind() + { + $user1Id = $this->loadFixture(); $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); $user = $repos->find($user1Id); $this->assertTrue($user instanceof CmsUser); $this->assertEquals('Roman', $user->name); $this->assertEquals('freak', $user->status); + } - $this->_em->clear(); + public function testFindByField() + { + $user1Id = $this->loadFixture(); + $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); $users = $repos->findBy(array('status' => 'dev')); $this->assertEquals(1, count($users)); $this->assertTrue($users[0] instanceof CmsUser); $this->assertEquals('Guilherme', $users[0]->name); $this->assertEquals('dev', $users[0]->status); + } - $this->_em->clear(); + + public function testFindFieldByMagicCall() + { + $user1Id = $this->loadFixture(); + $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); $users = $repos->findByStatus('dev'); $this->assertEquals(1, count($users)); $this->assertTrue($users[0] instanceof CmsUser); $this->assertEquals('Guilherme', $users[0]->name); $this->assertEquals('dev', $users[0]->status); - - $this->_em->clear(); + } + + public function testFindAll() + { + $user1Id = $this->loadFixture(); + $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); $users = $repos->findAll(); $this->assertEquals(2, count($users)); + } - $this->_em->clear(); + public function testFindByAlias() + { + $user1Id = $this->loadFixture(); + $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); $this->_em->getConfiguration()->addEntityNamespace('CMS', 'Doctrine\Tests\Models\CMS'); @@ -74,8 +98,12 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $users = $repos->findAll(); $this->assertEquals(2, count($users)); + } + public function tearDown() + { $this->_em->getConfiguration()->setEntityNamespaces(array()); + parent::tearDown(); } /** @@ -150,5 +178,28 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->setExpectedException('Doctrine\ORM\OptimisticLockException'); $this->_em->find('Doctrine\Tests\Models\Cms\CmsUser', $userId, \Doctrine\DBAL\LockMode::OPTIMISTIC); } + + /** + * @group DDC-819 + */ + public function testFindMagicCallByNullValue() + { + $this->loadFixture(); + $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + + $users = $repos->findByStatus(null); + $this->assertEquals(0, count($users)); + } + + /** + * @group DDC-819 + */ + public function testInvalidMagicCall() + { + $this->setExpectedException('BadMethodCallException'); + + $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $repos->foo(); + } }