setUpResourceFactoryMock(); Mockery::mock('overload:Icinga\Authentication\Backend\LdapUserBackend') ->shouldReceive('assertAuthenticationPossible')->andReturnNull(); $form = new LdapBackendForm(); $form->setTokenDisabled(); $form->setResources(array('test_ldap_backend')); $form->populate(array('resource' => 'test_ldap_backend')); $this->assertTrue( LdapBackendForm::isValidAuthenticationBackend($form), 'LdapBackendForm claims that a valid authentication backend with users is not valid' ); } /** * @runInSeparateProcess * @preserveGlobalState disabled */ public function testInvalidBackendIsNotValid() { $this->setUpResourceFactoryMock(); Mockery::mock('overload:Icinga\Authentication\Backend\LdapUserBackend') ->shouldReceive('assertAuthenticationPossible')->andThrow(new AuthenticationException); $form = new LdapBackendForm(); $form->setTokenDisabled(); $form->setResources(array('test_ldap_backend')); $form->populate(array('resource' => 'test_ldap_backend')); $this->assertFalse( LdapBackendForm::isValidAuthenticationBackend($form), 'LdapBackendForm claims that an invalid authentication backend without users is valid' ); } protected function setUpResourceFactoryMock() { Mockery::mock('alias:Icinga\Data\ResourceFactory') ->shouldReceive('createResource') ->andReturn(Mockery::mock('Icinga\Protocol\Ldap\Connection')) ->shouldReceive('getResourceConfig') ->andReturn(new ConfigObject()); } }