Skip to content

Commit

Permalink
Allow for DropboxV2 (#47)
Browse files Browse the repository at this point in the history
* Allow for DropboxV2

* Fixed broken tests

* Make exception for lower versions of PHPUnit
  • Loading branch information
Nyholm authored Mar 13, 2018
1 parent 61e9fa0 commit 3b2ed5c
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ install:

script:
- composer validate --strict --no-check-lock
# - $TEST_COMMAND
- $TEST_COMMAND
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 2.1.3

### Fixed

- Fixed bug that made DropboxV2 config unavailable.

## 2.1.2

### Fixed
Expand Down
1 change: 0 additions & 1 deletion DependencyInjection/BMBackupManagerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use League\Flysystem\Adapter\Local;
use League\Flysystem\AwsS3v3\AwsS3Adapter;
use League\Flysystem\Dropbox\DropboxAdapter;
use Nyholm\DSN;
use Srmklive\Dropbox\Adapter\DropboxAdapter as Dropbox2Adapter;
use League\Flysystem\Rackspace\RackspaceAdapter;
use League\Flysystem\Sftp\SftpAdapter;
Expand Down
10 changes: 6 additions & 4 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ public function getConfigTreeBuilder()
if (!isset($config['type'])) {
throw new InvalidConfigurationException(sprintf('You must define a "type" for storage "%s"', $name));
}
$validTypes = ['Local', 'AwsS3', 'Rackspace', 'Dropbox', 'Ftp', 'Sftp'];
if (!in_array($config['type'], $validTypes)) {
throw new InvalidConfigurationException(sprintf('Type must be one of "%s", got "%s"', implode(', ', $validTypes), $config['type']));
}

switch ($config['type']) {
case 'Local':
Expand All @@ -43,12 +39,18 @@ public function getConfigTreeBuilder()
case 'Dropbox':
$this->validateAuthenticationType(['token', 'key', 'secret', 'app', 'root'], $config, 'Dropbox');
break;
case 'DropboxV2':
$this->validateAuthenticationType(['token', 'root'], $config, 'DropboxV2');
break;
case 'Ftp':
$this->validateAuthenticationType(['host', 'username', 'password', 'root', 'port', 'passive', 'ssl', 'timeout'], $config, 'Ftp');
break;
case 'Sftp':
$this->validateAuthenticationType(['host', 'username', 'password', 'root', 'port', 'timeout', 'privateKey'], $config, 'Sftp');
break;
default:
$validTypes = ['Local', 'AwsS3', 'Rackspace', 'Dropbox', 'DropboxV2', 'Ftp', 'Sftp'];
throw new InvalidConfigurationException(sprintf('Type must be one of "%s", got "%s"', implode(', ', $validTypes), $config['type']));
}
}

Expand Down
7 changes: 6 additions & 1 deletion Tests/Functional/BundleInitializationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ public function testNoConfig()

public function testNoDependencies()
{
$this->expectException(\LogicException::class);
if (method_exists($this, 'expectException')) {
$this->expectException(\LogicException::class);
} else {
// Legacy
$this->setExpectedException(\LogicException::class);
}

// Create a new Kernel
$kernel = $this->createKernel();
Expand Down
32 changes: 0 additions & 32 deletions Tests/Unit/DependencyInjection/BMBackupManagerExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,6 @@ public function testReplacementOfConfig()
$this->assertContainerBuilderHasServiceDefinitionWithArgument('backup_manager.config_database', 0, $dbConfig);
}

public function testDsn()
{
$storageConfig = ['local'=>['type'=>'Local', 'root'=>'/foo']];
$dbConfig = ['dev'=>[
'type'=>'mysql',
'host'=>'host.com',
'port'=>'3306',
'user'=>'user',
'pass'=>'pass',
'database'=>'db',
// The DSN should override them all.
'dsn'=>'pgsql://root:[email protected]:5432/test_db',
]];

$this->load([
'storage' => $storageConfig,
'database' => $dbConfig,
]);

$parsedConfig = ['dev'=>[
'type'=>'pgsql',
'host'=>'127.0.0.1',
'port'=>'5432',
'user'=>'root',
'pass'=>'root_pass',
'database'=>'test_db',
]];

$this->assertContainerBuilderHasServiceDefinitionWithArgument('backup_manager.config_storage', 0, $storageConfig);
$this->assertContainerBuilderHasServiceDefinitionWithArgument('backup_manager.config_database', 0, $parsedConfig);
}

/**
* Make sure we can have multiple storage names with the same type
*/
Expand Down
34 changes: 25 additions & 9 deletions Tests/Unit/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,32 +135,48 @@ public function testSingleTransactionOnValid()
);
}

public function testDsn()
public function testNoType()
{
$this->assertConfigurationIsInvalid(array(
[
'database'=>[
'dev'=>[
'dsn' => 'pgsql://root:[email protected]:5432/test_db',
'singleTransaction' => true,

],
],
]
)
),
'You must define a "type" or "dsn" for database "dev"'
);
}
public function testNoType()

/**
*
* @dataProvider validStorageTypes
*/
public function testStorageTypes($type)
{
$this->assertConfigurationIsInvalid(array(
$this->assertConfigurationIsValid(array(
[
'database'=>[
'dev'=>[

'type' => 'mysql'
],
],
'storage' => [
'foo' => [
'type' => $type,
]
]
]
),
'You must define a "type" or "dsn" for database "dev"'
)
);
}

public function validStorageTypes()
{
return [
['Local'],['AwsS3'], ['Rackspace'], ['Dropbox'], ['DropboxV2'], ['Ftp'], ['Sftp'],
];
}
}

0 comments on commit 3b2ed5c

Please sign in to comment.