Fix the DbBackendFormTest

Mock ResourceFactory in form tests

fixes #6596
This commit is contained in:
Matthias Jentsch 2014-06-30 18:16:21 +02:00
parent fd21ba4e4d
commit 8f1959833b
1 changed files with 23 additions and 8 deletions

View File

@ -26,10 +26,10 @@ class DbBackendFormTest extends BaseTestCase
*/ */
public function testValidBackendIsValid() public function testValidBackendIsValid()
{ {
Mockery::mock('alias:Icinga\Authentication\UserBackend') $this->setUpUserBackendMock()
->shouldReceive('create')->with('test', Mockery::type('\Zend_Config'))->andReturnUsing( ->shouldReceive('count')
function () { return Mockery::mock(array('count' => 1)); } ->andReturn(2);
); $this->setUpResourceFactoryMock();
$form = new DbBackendForm(); $form = new DbBackendForm();
$form->setBackendName('test'); $form->setBackendName('test');
@ -49,10 +49,10 @@ class DbBackendFormTest extends BaseTestCase
*/ */
public function testInvalidBackendIsNotValid() public function testInvalidBackendIsNotValid()
{ {
Mockery::mock('alias:Icinga\Authentication\UserBackend') $this->setUpUserBackendMock()
->shouldReceive('create')->with('test', Mockery::type('\Zend_Config'))->andReturnUsing( ->shouldReceive('count')
function () { return Mockery::mock(array('count' => 0)); } ->andReturn(0);
); $this->setUpResourceFactoryMock();
$form = new DbBackendForm(); $form = new DbBackendForm();
$form->setBackendName('test'); $form->setBackendName('test');
@ -65,4 +65,19 @@ class DbBackendFormTest extends BaseTestCase
'DbBackendForm claims that an invalid authentication backend without users is valid' 'DbBackendForm claims that an invalid authentication backend without users is valid'
); );
} }
protected function setUpUserBackendMock()
{
return Mockery::mock('overload:Icinga\Authentication\Backend\DbUserBackend');
}
protected function setUpResourceFactoryMock()
{
Mockery::mock('alias:Icinga\Data\ResourceFactory')
->shouldReceive('getResourceConfig')
->andReturn(new \Zend_Config(array()))
->shouldReceive('createResource')
->with(Mockery::type('\Zend_Config'))
->andReturn(Mockery::mock('Icinga\Data\Db\DbConnection'));
}
} }