Fix the DbBackendFormTest
Mock ResourceFactory in form tests fixes #6596
This commit is contained in:
parent
fd21ba4e4d
commit
8f1959833b
|
@ -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'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue