Fix unit DB Form unit tests broken by inspection

refs #9641
This commit is contained in:
Matthias Jentsch 2015-07-16 16:15:27 +02:00
parent f4054d575b
commit 31618ce2cf
1 changed files with 19 additions and 2 deletions

View File

@ -26,7 +26,7 @@ class DbResourceFormTest extends BaseTestCase
public function testValidDbResourceIsValid() public function testValidDbResourceIsValid()
{ {
$this->setUpResourceFactoryMock( $this->setUpResourceFactoryMock(
Mockery::mock()->shouldReceive('getConnection')->atMost()->twice()->andReturn(Mockery::self())->getMock() Mockery::mock()->shouldReceive('inspect')->andReturn(self::createInspector(false))->getMock()
); );
$this->assertTrue( $this->assertTrue(
@ -42,7 +42,7 @@ class DbResourceFormTest extends BaseTestCase
public function testInvalidDbResourceIsNotValid() public function testInvalidDbResourceIsNotValid()
{ {
$this->setUpResourceFactoryMock( $this->setUpResourceFactoryMock(
Mockery::mock()->shouldReceive('getConnection')->once()->andThrow('\Exception')->getMock() Mockery::mock()->shouldReceive('inspect')->andReturn(self::createInspector(true))->getMock()
); );
$this->assertFalse( $this->assertFalse(
@ -58,4 +58,21 @@ class DbResourceFormTest extends BaseTestCase
->with(Mockery::type('Icinga\Data\ConfigObject')) ->with(Mockery::type('Icinga\Data\ConfigObject'))
->andReturn($resourceMock); ->andReturn($resourceMock);
} }
public static function createInspector($error = false, $log = array('log'))
{
if (! $error) {
$calls = array(
'hasError' => false,
'toArray' => $log
);
} else {
$calls = array(
'hasError' => true,
'getError' => 'Error',
'toArray' => $log
);
}
return Mockery::mock('Icinga\Data\Inspection', $calls);
}
} }