shouldReceive('assertAuthenticationPossible')->andReturnNull(); $this->setUpUserBackendMock($ldapUserBackendMock); // Passing array(null) is required to make Mockery call the constructor... $form = Mockery::mock('Icinga\Forms\Config\UserBackend\LdapBackendForm[getView]', array(null)); $form->shouldReceive('getView->escape') ->with(Mockery::type('string')) ->andReturnUsing(function ($s) { return $s; }); $form->setTokenDisabled(); $form->setResources(array('test_ldap_backend')); $form->populate(array('resource' => 'test_ldap_backend')); $this->assertTrue( LdapBackendForm::isValidUserBackend($form), 'LdapBackendForm claims that a valid user backend with users is not valid' ); } /** * @runInSeparateProcess * @preserveGlobalState disabled */ public function testInvalidBackendIsNotValid() { $ldapUserBackendMock = Mockery::mock('overload:Icinga\Authentication\User\LdapUserBackend'); $ldapUserBackendMock->shouldReceive('assertAuthenticationPossible')->andThrow(new AuthenticationException); $this->setUpUserBackendMock($ldapUserBackendMock); // Passing array(null) is required to make Mockery call the constructor... $form = Mockery::mock('Icinga\Forms\Config\UserBackend\LdapBackendForm[getView]', array(null)); $form->shouldReceive('getView->escape') ->with(Mockery::type('string')) ->andReturnUsing(function ($s) { return $s; }); $form->setTokenDisabled(); $form->setResources(array('test_ldap_backend')); $form->populate(array('resource' => 'test_ldap_backend')); $this->assertFalse( LdapBackendForm::isValidUserBackend($form), 'LdapBackendForm claims that an invalid user backend without users is valid' ); } protected function setUpUserBackendMock($ldapUserBackendMock) { Mockery::mock('alias:Icinga\Authentication\User\UserBackend') ->shouldReceive('create') ->andReturn($ldapUserBackendMock); } }