setUpResourceFactoryMock( Mockery::mock()->shouldReceive('testCredentials')->once()->andReturn(true)->getMock() ); // Passing array(null) is required to make Mockery call the constructor... $form = Mockery::mock('Icinga\Forms\Config\Resource\LdapResourceForm[getView]', array(null)); $form->shouldReceive('getView->escape') ->with(Mockery::type('string')) ->andReturnUsing(function ($s) { return $s; }); $form->setTokenDisabled(); $this->assertTrue( LdapResourceForm::isValidResource($form->create()), 'ResourceForm claims that a valid ldap resource is not valid' ); } /** * @runInSeparateProcess * @preserveGlobalState disabled */ public function testInvalidLdapResourceIsNotValid() { $this->setUpResourceFactoryMock( Mockery::mock()->shouldReceive('testCredentials')->once()->andThrow('\Exception')->getMock() ); // Passing array(null) is required to make Mockery call the constructor... $form = Mockery::mock('Icinga\Forms\Config\Resource\LdapResourceForm[getView]', array(null)); $form->shouldReceive('getView->escape') ->with(Mockery::type('string')) ->andReturnUsing(function ($s) { return $s; }); $form->setTokenDisabled(); $this->assertFalse( LdapResourceForm::isValidResource($form->create()), 'ResourceForm claims that an invalid ldap resource is valid' ); } protected function setUpResourceFactoryMock($resourceMock) { Mockery::mock('alias:Icinga\Data\ResourceFactory') ->shouldReceive('createResource') ->with(Mockery::type('Icinga\Data\ConfigObject')) ->andReturn($resourceMock); } }