Fix LdapBackendFormTest

Alter class mocks to fit the latest changes in LdapBackendFormTest

fixes #6597
This commit is contained in:
Matthias Jentsch 2014-07-03 16:15:02 +02:00
parent 298edbe730
commit 86ad5f738b
1 changed files with 19 additions and 8 deletions

View File

@ -11,6 +11,7 @@ require_once realpath(dirname(__FILE__) . '/../../../../bootstrap.php');
use Mockery; use Mockery;
use Icinga\Test\BaseTestCase; use Icinga\Test\BaseTestCase;
use Icinga\Form\Config\Authentication\LdapBackendForm; use Icinga\Form\Config\Authentication\LdapBackendForm;
use Icinga\Exception\AuthenticationException;
class LdapBackendFormTest extends BaseTestCase class LdapBackendFormTest extends BaseTestCase
{ {
@ -26,10 +27,9 @@ class LdapBackendFormTest extends BaseTestCase
*/ */
public function testValidBackendIsValid() public function testValidBackendIsValid()
{ {
Mockery::mock('alias:Icinga\Authentication\UserBackend') $this->setUpResourceFactoryMock();
->shouldReceive('create')->with('test', Mockery::type('\Zend_Config'))->andReturnUsing( Mockery::mock('overload:Icinga\Authentication\Backend\LdapUserBackend')
function () { return Mockery::mock(array('count' => 1)); } ->shouldReceive('assertAuthenticationPossible')->andReturn(null);
);
$form = new LdapBackendForm(); $form = new LdapBackendForm();
$form->setBackendName('test'); $form->setBackendName('test');
@ -49,10 +49,9 @@ class LdapBackendFormTest extends BaseTestCase
*/ */
public function testInvalidBackendIsNotValid() public function testInvalidBackendIsNotValid()
{ {
Mockery::mock('alias:Icinga\Authentication\UserBackend') $this->setUpResourceFactoryMock();
->shouldReceive('create')->with('test', Mockery::type('\Zend_Config'))->andReturnUsing( Mockery::mock('overload:Icinga\Authentication\Backend\LdapUserBackend')
function () { return Mockery::mock(array('count' => 0)); } ->shouldReceive('assertAuthenticationPossible')->andThrow(new AuthenticationException);
);
$form = new LdapBackendForm(); $form = new LdapBackendForm();
$form->setBackendName('test'); $form->setBackendName('test');
@ -65,4 +64,16 @@ class LdapBackendFormTest extends BaseTestCase
'LdapBackendForm claims that an invalid authentication backend without users is valid' 'LdapBackendForm claims that an invalid authentication backend without users is valid'
); );
} }
protected function setUpResourceFactoryMock()
{
Mockery::mock('alias:Icinga\Data\ResourceFactory')
->shouldReceive('ldapAvailable')
->andReturn(true)
->shouldReceive('getResourceConfig')
->andReturn(new \Zend_Config(array()))
->shouldReceive('createResource')
->with(Mockery::type('\Zend_Config'))
->andReturn(Mockery::mock('Icinga\Protocol\Ldap\Connection'));
}
} }