Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

DDC-819 - Fix bug with invalid parameter exception because of using i…

…sset instead of array_key_exists()
  • Loading branch information...
commit d2630ff54e25a2b877db7c49e9926acf46db1ca6 1 parent 039293c
@beberlei beberlei authored
View
2  lib/Doctrine/ORM/EntityRepository.php
@@ -185,7 +185,7 @@ public function __call($method, $arguments)
);
}
- if ( ! isset($arguments[0])) {
+ if ( ! array_key_exists(0, $arguments)) {
throw ORMException::findByRequiresParameter($method.$by);
}
View
63 tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php
@@ -19,7 +19,8 @@ protected function setUp() {
parent::setUp();
}
- public function testBasicFinders() {
+ public function loadFixture()
+ {
$user = new CmsUser;
$user->name = 'Roman';
$user->username = 'romanb';
@@ -38,35 +39,58 @@ public function testBasicFinders() {
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 @@ public function testBasicFinders() {
$users = $repos->findAll();
$this->assertEquals(2, count($users));
+ }
+ public function tearDown()
+ {
$this->_em->getConfiguration()->setEntityNamespaces(array());
+ parent::tearDown();
}
/**
@@ -150,5 +178,28 @@ public function testIdentityMappedOptimisticLockUnversionedEntity_ThrowsExceptio
$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();
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.