From 8f1959833b17452fc28bc44bb9e28d7b3e8562eb Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Mon, 30 Jun 2014 18:16:21 +0200 Subject: [PATCH] Fix the DbBackendFormTest Mock ResourceFactory in form tests fixes #6596 --- .../Authentication/DbBackendFormTest.php | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/test/php/application/forms/Config/Authentication/DbBackendFormTest.php b/test/php/application/forms/Config/Authentication/DbBackendFormTest.php index b5553a896..c504955ad 100644 --- a/test/php/application/forms/Config/Authentication/DbBackendFormTest.php +++ b/test/php/application/forms/Config/Authentication/DbBackendFormTest.php @@ -26,10 +26,10 @@ class DbBackendFormTest 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->setUpUserBackendMock() + ->shouldReceive('count') + ->andReturn(2); + $this->setUpResourceFactoryMock(); $form = new DbBackendForm(); $form->setBackendName('test'); @@ -49,10 +49,10 @@ class DbBackendFormTest 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->setUpUserBackendMock() + ->shouldReceive('count') + ->andReturn(0); + $this->setUpResourceFactoryMock(); $form = new DbBackendForm(); $form->setBackendName('test'); @@ -65,4 +65,19 @@ class DbBackendFormTest extends BaseTestCase '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')); + } }