/**
  * @param DbalConnection $connection
  * @param null|string $alternativeKey If null then the dbname is used as key
  * @return void
  */
 public function add($connection, $alternativeKey = null)
 {
     if (is_null($alternativeKey)) {
         $alternativeKey = $connection->config()['dbname'];
     }
     $this->set($alternativeKey, $connection);
 }
 protected function setUp()
 {
     $this->connection = DbalConnection::fromConfiguration(['driver' => 'pdo_sqlite', 'memory' => true, 'dbname' => 'test_db']);
     $testDataTable = new Table("test_data");
     $testDataTable->addColumn("name", "string");
     $testDataTable->addColumn("age", "integer");
     $testDataTable->addColumn("created_at", "datetime");
     $testDataTable->addColumn("price", "float");
     $testDataTable->addColumn("active", "boolean");
     $testDataTable->setPrimaryKey(["name"]);
     $this->connection->connection()->getSchemaManager()->createTable($testDataTable);
     $this->dataTypeLocation = ApplicationDataTypeLocation::fromPath(sys_get_temp_dir());
     $this->commandBus = new CommandBusMock();
     if (!is_dir(sys_get_temp_dir() . "/SqlConnector")) {
         mkdir(sys_get_temp_dir() . "/SqlConnector");
         mkdir(sys_get_temp_dir() . "/SqlConnector/DataType");
     }
     $connections = new DbalConnectionCollection();
     $connections->add($this->connection);
     $this->tableConnectorGenerator = new TableConnectorGenerator($connections, $this->dataTypeLocation, ConfigLocation::fromPath(sys_get_temp_dir()), $this->commandBus, Bootstrap::getServiceManager()->get("config")['prooph.link.sqlconnector']['doctrine_processing_type_map']);
 }
 /**
  * @param array $connection
  * @param null|string $alternativeKey
  * @throws \InvalidArgumentException
  */
 public function updateConnection(array $connection, $alternativeKey = null)
 {
     if (is_null($alternativeKey)) {
         if (!isset($connection['dbname'])) {
             throw new \InvalidArgumentException('Missing dbname key in connection configuration');
         }
         $connectionObj = $this->findByDbName($connection['dbname']);
         if (!$connectionObj) {
             throw new \InvalidArgumentException('No connection found for db: ' . $connection['dbname']);
         }
         $alternativeKey = $this->connections->indexOf($connectionObj);
     }
     Assertion::string($alternativeKey);
     if (!$this->connections->containsKey($alternativeKey)) {
         throw new \InvalidArgumentException(sprintf('Connection for DB %s can not be found', $connection['dbname']));
     }
     $this->connections->set($alternativeKey, DbalConnection::fromConfiguration($connection));
     $this->saveConnections();
 }