2013-06-03 15:34:57 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Icinga\Protocol\Statusdat;
|
2013-06-03 16:14:46 +02:00
|
|
|
require_once("../../library/Icinga/Protocol/Statusdat/IReader.php");
|
|
|
|
require_once("../../library/Icinga/Protocol/Statusdat/Reader.php");
|
|
|
|
require_once("../../library/Icinga/Exception/ConfigurationError.php");
|
2013-06-03 15:34:57 +02:00
|
|
|
|
|
|
|
use Icinga\Protocol\Statusdat\Reader as Reader;
|
2013-06-11 13:53:42 +02:00
|
|
|
|
|
|
|
if (!defined('APPLICATION_PATH')) {
|
|
|
|
define("APPLICATION_PATH","./"); // TODO: test boostrap
|
|
|
|
}
|
2013-06-03 15:34:57 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Test class for Reader
|
|
|
|
* Created Wed, 16 Jan 2013 15:15:16 +0000
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
class ConfigMock {
|
|
|
|
function __construct($data) {
|
|
|
|
foreach($data as $key=>$val)
|
|
|
|
$this->$key = $val;
|
|
|
|
}
|
|
|
|
function get($attr) {
|
|
|
|
return $this->$attr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ParserMock {
|
|
|
|
|
|
|
|
public $runtime = array();
|
|
|
|
public $objects = array();
|
|
|
|
public function parseObjectsFile() {
|
|
|
|
return $this->objects;
|
|
|
|
}
|
|
|
|
public function parseRuntimeState() {
|
|
|
|
return $this->runtime;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getRuntimeState() {
|
|
|
|
return $this->runtime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
require("Zend/Cache.php");
|
|
|
|
class ReaderTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2013-06-11 14:20:32 +02:00
|
|
|
protected function tearDown()
|
|
|
|
{
|
|
|
|
if (file_exists('./tmp')) {
|
|
|
|
@system("rm -rf ./tmp");
|
|
|
|
}
|
|
|
|
}
|
2013-06-03 15:34:57 +02:00
|
|
|
|
|
|
|
public function testFileCaching() {
|
2013-06-11 14:20:32 +02:00
|
|
|
if (!file_exists('./tmp')) {
|
|
|
|
mkdir('./tmp');
|
|
|
|
}
|
2013-06-03 15:34:57 +02:00
|
|
|
$parser = new ParserMock();
|
|
|
|
$parser->runtime = array("host"=>array(
|
|
|
|
"test" => (object) array(
|
|
|
|
"host_name" => "test"
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$object_file = tempnam("./dir","object");
|
|
|
|
$status_file = tempnam("./dir","status");
|
|
|
|
$reader = new Reader(new ConfigMock(array(
|
2013-06-10 16:44:58 +02:00
|
|
|
"cache_path" => "/tmp",
|
2013-06-03 15:34:57 +02:00
|
|
|
"objects_file" => $object_file,
|
|
|
|
"status_file" => $status_file
|
|
|
|
)),$parser);
|
|
|
|
unlink($object_file);
|
|
|
|
unlink($status_file);
|
2013-06-10 16:44:58 +02:00
|
|
|
$this->assertTrue(file_exists("/tmp/zend_cache---objects".md5($object_file)));
|
|
|
|
$this->assertTrue(file_exists("/tmp/zend_cache---state".md5($object_file)));
|
|
|
|
system("rm /tmp/zend_cache*");
|
2013-06-03 15:34:57 +02:00
|
|
|
}
|
|
|
|
public function testEmptyFileException() {
|
2013-06-11 14:20:32 +02:00
|
|
|
|
2013-06-03 15:34:57 +02:00
|
|
|
$this->setExpectedException("Icinga\Exception\ConfigurationError");
|
|
|
|
$parser = new ParserMock();
|
|
|
|
$reader = new Reader(new ConfigMock(array(
|
2013-06-10 16:44:58 +02:00
|
|
|
"cache_path" => "/tmp",
|
2013-06-03 15:34:57 +02:00
|
|
|
"objects_file" => "",
|
|
|
|
"status_file" => "",
|
|
|
|
)),$parser);
|
|
|
|
}
|
|
|
|
}
|