2014-09-09 13:06:30 +02:00
|
|
|
<?php
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
2014-11-14 10:57:14 +01:00
|
|
|
namespace Tests\Icinga\Forms\Config\Resource;
|
2014-09-09 13:06:30 +02:00
|
|
|
|
|
|
|
// Necessary as some of these tests disable phpunit's preservation
|
|
|
|
// of the global state (e.g. autoloaders are in the global state)
|
|
|
|
require_once realpath(dirname(__FILE__) . '/../../../../bootstrap.php');
|
|
|
|
|
|
|
|
use Mockery;
|
|
|
|
use Icinga\Test\BaseTestCase;
|
2014-11-14 10:57:14 +01:00
|
|
|
use Icinga\Forms\Config\Resource\LivestatusResourceForm;
|
2014-09-09 13:06:30 +02:00
|
|
|
|
|
|
|
class LivestatusResourceFormTest extends BaseTestCase
|
|
|
|
{
|
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
parent::tearDown();
|
|
|
|
Mockery::close(); // Necessary because some tests run in a separate process
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
* @preserveGlobalState disabled
|
|
|
|
*/
|
|
|
|
public function testValidLivestatusResourceIsValid()
|
|
|
|
{
|
|
|
|
$this->setUpResourceFactoryMock(
|
|
|
|
Mockery::mock()->shouldReceive('connect')->andReturn(Mockery::self())
|
|
|
|
->shouldReceive('disconnect')->getMock()
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertTrue(
|
2014-09-29 11:02:45 +02:00
|
|
|
LivestatusResourceForm::isValidResource(new LivestatusResourceForm()),
|
2014-09-09 13:06:30 +02:00
|
|
|
'ResourceForm claims that a valid livestatus resource is not valid'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
|
|
|
* @preserveGlobalState disabled
|
|
|
|
*/
|
|
|
|
public function testInvalidLivestatusResourceIsNotValid()
|
|
|
|
{
|
|
|
|
$this->setUpResourceFactoryMock(
|
|
|
|
Mockery::mock()->shouldReceive('connect')->once()->andThrow('\Exception')->getMock()
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertFalse(
|
2014-09-29 11:02:45 +02:00
|
|
|
LivestatusResourceForm::isValidResource(new LivestatusResourceForm()),
|
2014-09-09 13:06:30 +02:00
|
|
|
'ResourceForm claims that an invalid livestatus resource is valid'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function setUpResourceFactoryMock($resourceMock)
|
|
|
|
{
|
|
|
|
Mockery::mock('alias:Icinga\Data\ResourceFactory')
|
|
|
|
->shouldReceive('createResource')
|
2014-11-18 13:11:52 +01:00
|
|
|
->with(Mockery::type('Icinga\Data\ConfigObject'))
|
2014-09-09 13:06:30 +02:00
|
|
|
->andReturn($resourceMock);
|
|
|
|
}
|
|
|
|
}
|