Files
librenms-librenms/tests/unit/ResultSetTest.php

70 lines
1.8 KiB
PHP
Raw Normal View History

2015-06-17 15:35:42 +02:00
<?php
namespace Leaseweb\InfluxDB\Test;
2015-06-17 16:03:21 +02:00
use Leaseweb\InfluxDB\ResultSet;
2015-06-17 15:35:42 +02:00
class ResultSetTest extends \PHPUnit_Framework_TestCase
{
2015-06-17 16:03:21 +02:00
/** @var ResultSet $resultSet*/
protected $resultSet;
public function setUp()
2015-06-17 15:35:42 +02:00
{
2015-06-17 16:03:21 +02:00
$resultJsonExample = file_get_contents(dirname(__FILE__) . '/result.example.json');
$this->resultSet = new ResultSet($resultJsonExample);
}
2015-06-18 10:11:19 +02:00
/**
* @expectedException \InvalidArgumentException
*/
public function testThrowsExceptionIfJSONisNotValid()
{
$invalidJSON = 'foo';
new ResultSet($invalidJSON);
}
/**
2015-06-18 13:40:16 +02:00
* We can get points from measurement
2015-06-18 10:11:19 +02:00
*/
2015-06-17 16:03:21 +02:00
public function testGetPointsFromMeasurementName()
{
$measurementName = 'cpu_load_short';
2015-06-18 10:11:19 +02:00
$expectedNumberOfPoints = 2;
$expectedValueFromFirstPoint = 0.64;
2015-06-17 16:03:21 +02:00
$points = $this->resultSet->getPoints($measurementName);
2015-06-17 15:35:42 +02:00
$this->assertTrue(
2015-06-17 16:03:21 +02:00
is_array($points)
2015-06-17 15:35:42 +02:00
);
2015-06-18 10:11:19 +02:00
$this->assertCount($expectedNumberOfPoints, $points);
$somePoint = array_shift($points);
$this->assertEquals($expectedValueFromFirstPoint, $somePoint['value']);
}
public function testGetPointsFromTags()
{
$tags = array("host" => "server01");
2015-06-18 13:40:16 +02:00
$expectedNumberOfPoints = 2;
2015-06-18 10:11:19 +02:00
$points = $this->resultSet->getPoints('', $tags);
2015-06-18 13:40:16 +02:00
$this->assertTrue(is_array($points));
$this->assertCount($expectedNumberOfPoints, $points);
}
public function testGetPointsFromNameAndTags()
{
$tags = array("host" => "server01");
$expectedNumberOfPoints = 2;
$points = $this->resultSet->getPoints('', $tags);
$this->assertTrue(is_array($points));
$this->assertCount($expectedNumberOfPoints, $points);
2015-06-17 15:35:42 +02:00
}
}