setUpResourceFactoryMock( Mockery::mock()->shouldReceive('getConnection')->atMost()->twice()->andReturn(Mockery::self())->getMock() ); $this->assertTrue( DbResourceForm::isValidResource(new DbResourceForm()), 'ResourceForm claims that a valid db resource is not valid' ); } /** * @runInSeparateProcess * @preserveGlobalState disabled */ public function testInvalidDbResourceIsNotValid() { $this->setUpResourceFactoryMock( Mockery::mock()->shouldReceive('getConnection')->once()->andThrow('\Exception')->getMock() ); $this->assertFalse( DbResourceForm::isValidResource(new DbResourceForm()), 'ResourceForm claims that an invalid db resource is valid' ); } protected function setUpResourceFactoryMock($resourceMock) { Mockery::mock('alias:Icinga\Data\ResourceFactory') ->shouldReceive('createResource') ->with(Mockery::type('Icinga\Data\ConfigObject')) ->andReturn($resourceMock); } }