DDC-819 - Fix bug with invalid parameter exception because of using isset instead of array_key_exists()
This commit is contained in:
parent
039293c27a
commit
d2630ff54e
@ -185,7 +185,7 @@ class EntityRepository
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! isset($arguments[0])) {
|
||||
if ( ! array_key_exists(0, $arguments)) {
|
||||
throw ORMException::findByRequiresParameter($method.$by);
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user