示例#1
0
 public function testReportJsonSerializationSucceeds()
 {
     $connector_map = new ConnectorMap();
     $connector1 = new TestConnector('connection1', new ArrayConfig([]));
     $connector_map->setItem('connection1', $connector1);
     $connector_map->setItem('connection2', new TestConnector('connection2', new ArrayConfig(['fake_status' => Status::WORKING])));
     $connector_map->setItem('connection3', new TestConnector('connection3', new ArrayConfig(['fake_status' => Status::FAILING])));
     $report = StatusReport::generate($connector_map);
     $json = json_encode($report);
     $array = json_decode($json, true);
     $expected_stats = ['overall' => 3, 'failing' => 1, 'working' => 1, 'unknown' => 1];
     $this->assertSame(Status::FAILING, $array['status']);
     $this->assertSame($expected_stats, $array['stats']);
     $this->assertArrayHasKey('connection1', $array['details']);
     $this->assertArrayHasKey('connection2', $array['details']);
     $this->assertArrayHasKey('connection3', $array['details']);
     $this->assertArraySubset($connector1->getStatus()->toArray(), $array['details']['connection1']);
 }
 public function testDisconnectWorks()
 {
     $connector = new TestConnector('conn1', new ArrayConfig([]));
     $connector_map = new ConnectorMap();
     $connector_map->setItem('conn1', $connector);
     $service = new ConnectorService($connector_map);
     $this->assertFalse($connector->isConnected());
     $this->assertInstanceOf('\\stdClass', $service->getConnection('conn1'));
     $this->assertTrue($connector->isConnected());
     $service->disconnect('conn1');
     $this->assertFalse($connector->isConnected());
 }
 protected function registerConnectors(ConnectorMap $connector_map, array $connections_config)
 {
     foreach ($connections_config as $connection_name => $connection_config) {
         $connector_class = $connection_config['class'];
         if (!class_exists($connector_class)) {
             throw new RuntimeError(sprintf('Unable to load configured connector class: %s', $connector_class));
         }
         $object_state = [':name' => $connection_config['name'], ':config' => new ArrayConfig($connection_config['settings'])];
         if (array_key_exists('dependencies', $connection_config) && is_array($connection_config['dependencies'])) {
             foreach ($connection_config['dependencies'] as $key => $dependency) {
                 $object_state[$key] = $dependency;
             }
         }
         $connector = $this->di_container->make($connector_class, $object_state);
         $connector_map->setItem($connection_name, $connector);
     }
 }