/**
  * @param string $message
  * @param int    $expectedSubscriptionId
  * @param string $expectedState
  * @param string $expectedJson
  *
  * @dataProvider messageProvider
  */
 public function testParseMessage($message, $expectedSubscriptionId, $expectedState, $expectedJson)
 {
     $logMessage = new LogMessageNotification();
     $logMessage->logtxt = $message;
     $stateChanges = StateChangeParser::parseStateChanges([$logMessage]);
     $stateChange = $stateChanges[0];
     $this->assertEquals($expectedSubscriptionId, $stateChange->getSubscriptionId());
     $this->assertEquals($expectedState, $stateChange->getState());
     $this->assertJson(json_encode($stateChange), $expectedJson);
 }
 /**
  * Retrieves and returns all status messages for the configured
  * instances
  *
  * @param \SplObjectStorage $instances the instances and their state
  *
  * @return InstanceStatusCollection
  */
 private function getStatusMessages($instances)
 {
     $collection = new InstanceStatusCollection();
     foreach ($instances as $instance) {
         /* @var Instance $instance */
         $tvheadend = $instance->getInstance();
         $instanceName = $instance->getName();
         $instanceState = $instances[$instance];
         // Collect statuses from currently reachable instances
         if ($instanceState->isReachable()) {
             try {
                 $collection->add(new InstanceStatus($instanceName, $tvheadend->getInputStatus(), $tvheadend->getSubscriptionStatus(), $tvheadend->getConnectionStatus(), StateChangeParser::parseStateChanges($tvheadend->getLogMessages())));
                 $this->eventDispatcher->dispatch(Events::INSTANCE_STATE_REACHABLE, new InstanceStateEvent($instance));
             } catch (\Exception $e) {
                 if ($e instanceof RequestFailedException) {
                     // Check for authentication errors
                     $statusCode = $e->getResponse()->getStatusCode();
                     if ($statusCode >= 400 && $statusCode < 500) {
                         $this->logger->error('Authentication/authorization failed when connecting to {instanceName} (HTTP {statusCode})', ['instanceName' => $instanceName, 'statusCode' => $e->getResponse()->getStatusCode()]);
                     }
                 }
                 $this->eventDispatcher->dispatch(Events::INSTANCE_STATE_UNREACHABLE, new InstanceStateEvent($instance));
             }
         } else {
             $this->eventDispatcher->dispatch(Events::INSTANCE_STATE_MAYBE_REACHABLE, new InstanceStateEvent($instance));
         }
     }
     return $collection;
 }