You are here

protected function MonitoringServicesTest::assertSensorResult in Monitoring 7

Do sensor result assertions.

Parameters

array $response_result: Result received via response.

\Drupal\monitoring\Sensor\SensorInfo $sensor_info: Sensor info for which we have the result.

1 call to MonitoringServicesTest::assertSensorResult()
MonitoringServicesTest::testSensorResult in test/tests/monitoring.services.test
Test sensor result API calls.

File

test/tests/monitoring.services.test, line 145
Contains \MonitoringServicesTest.

Class

MonitoringServicesTest
Tests for cron sensor.

Code

protected function assertSensorResult($response_result, SensorInfo $sensor_info) {
  $this
    ->assertEqual($response_result['sensor_name'], $sensor_info
    ->getName());

  // Test the uri - the hardcoded endpoint is defined in the
  // monitoring_test.default_services.inc.
  $this
    ->assertEqual($response_result['uri'], url('monitoring/v1/sensor-result/' . $sensor_info
    ->getName(), array(
    'absolute' => TRUE,
  )));

  // If the result is cached test also for the result values. In case of
  // result which is not cached we might not get the same values.
  if ($sensor_info
    ->getCachingTime()) {

    // Cannot use $this->runSensor() as the cache needs to remain.
    $result = monitoring_sensor_run($sensor_info
      ->getName());
    $this
      ->assertEqual($response_result['status'], $result
      ->getStatus());
    $this
      ->assertEqual($response_result['value'], $result
      ->getValue());
    $this
      ->assertEqual($response_result['expected_value'], $result
      ->getExpectedValue());
    $this
      ->assertEqual($response_result['numeric_value'], $result
      ->toNumber());
    $this
      ->assertEqual($response_result['message'], $result
      ->getMessage());
    $this
      ->assertEqual($response_result['timestamp'], $result
      ->getTimestamp());
    $this
      ->assertEqual($response_result['execution_time'], $result
      ->getExecutionTime());
  }
  if (isset($response_result['sensor_info'])) {
    $this
      ->assertEqual($response_result['sensor_info'], $sensor_info
      ->toArray());
  }
}