From 86ad5f738b9f736ed29d2827d27e99a024e3def3 Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Thu, 3 Jul 2014 16:15:02 +0200 Subject: [PATCH] Fix LdapBackendFormTest Alter class mocks to fit the latest changes in LdapBackendFormTest fixes #6597 --- .../Authentication/LdapBackendFormTest.php | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/test/php/application/forms/Config/Authentication/LdapBackendFormTest.php b/test/php/application/forms/Config/Authentication/LdapBackendFormTest.php index a3a0cfcaa..1255b5957 100644 --- a/test/php/application/forms/Config/Authentication/LdapBackendFormTest.php +++ b/test/php/application/forms/Config/Authentication/LdapBackendFormTest.php @@ -11,6 +11,7 @@ require_once realpath(dirname(__FILE__) . '/../../../../bootstrap.php'); use Mockery; use Icinga\Test\BaseTestCase; use Icinga\Form\Config\Authentication\LdapBackendForm; +use Icinga\Exception\AuthenticationException; class LdapBackendFormTest extends BaseTestCase { @@ -26,10 +27,9 @@ class LdapBackendFormTest extends BaseTestCase */ public function testValidBackendIsValid() { - Mockery::mock('alias:Icinga\Authentication\UserBackend') - ->shouldReceive('create')->with('test', Mockery::type('\Zend_Config'))->andReturnUsing( - function () { return Mockery::mock(array('count' => 1)); } - ); + $this->setUpResourceFactoryMock(); + Mockery::mock('overload:Icinga\Authentication\Backend\LdapUserBackend') + ->shouldReceive('assertAuthenticationPossible')->andReturn(null); $form = new LdapBackendForm(); $form->setBackendName('test'); @@ -49,10 +49,9 @@ class LdapBackendFormTest extends BaseTestCase */ public function testInvalidBackendIsNotValid() { - Mockery::mock('alias:Icinga\Authentication\UserBackend') - ->shouldReceive('create')->with('test', Mockery::type('\Zend_Config'))->andReturnUsing( - function () { return Mockery::mock(array('count' => 0)); } - ); + $this->setUpResourceFactoryMock(); + Mockery::mock('overload:Icinga\Authentication\Backend\LdapUserBackend') + ->shouldReceive('assertAuthenticationPossible')->andThrow(new AuthenticationException); $form = new LdapBackendForm(); $form->setBackendName('test'); @@ -65,4 +64,16 @@ class LdapBackendFormTest extends BaseTestCase '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')); + } }