protected function MonitoringServicesTest::assertSensorResult in Monitoring 8
Do sensor result assertions.
Parameters
array $response_result: Result received via response.
\Drupal\monitoring\Entity\SensorConfig $sensor_config: Sensor config for which we have the result.
1 call to MonitoringServicesTest::assertSensorResult()
- MonitoringServicesTest::testSensorResult in tests/
src/ Functional/ MonitoringServicesTest.php - Test sensor result API calls.
File
- tests/
src/ Functional/ MonitoringServicesTest.php, line 166
Class
- MonitoringServicesTest
- Tests for monitoring services.
Namespace
Drupal\Tests\monitoring\FunctionalCode
protected function assertSensorResult($response_result, SensorConfig $sensor_config) {
$this
->assertEqual($response_result['sensor_name'], $sensor_config
->id());
$this
->assertEqual($response_result['uri'], Url::fromRoute('rest.monitoring-sensor-result.GET', [
'id' => $sensor_config
->id(),
'_format' => 'json',
])
->setAbsolute()
->toString());
// 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_config
->getCachingTime()) {
// Cannot use $this->runSensor() as the cache needs to remain.
$result = monitoring_sensor_run($sensor_config
->id());
$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_config
->toArray());
}
}