Skip to content

Commit

Permalink
Merge pull request #12 from jonag/add_ignorePassiveAddress_option
Browse files Browse the repository at this point in the history
Add the ability to configure the ignorePassiveAddress option of the FTP adapter
  • Loading branch information
tgalopin authored May 22, 2019
2 parents 3aa87cb + bb9fde4 commit 993e8a4
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/3-interacting-with-ftp-and-sftp-servers.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ flysystem:
passive: true
ssl: true
timeout: 30
ignore_passive_address: ~
```
## SFTP
Expand Down
1 change: 1 addition & 0 deletions docs/B-configuration-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ flysystem:
passive: true
ssl: true
timeout: 30
ignore_passive_address: ~

users7.storage:
adapter: 'gcloud'
Expand Down
6 changes: 6 additions & 0 deletions src/Adapter/Builder/FtpAdapterDefinitionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,16 @@ protected function configureOptions(OptionsResolver $resolver)

$resolver->setDefault('timeout', 90);
$resolver->setAllowedTypes('timeout', 'scalar');

$resolver->setDefault('ignore_passive_address', null);
$resolver->setAllowedTypes('ignore_passive_address', ['null', 'bool']);
}

protected function configureDefinition(Definition $definition, array $options)
{
$options['ignorePassiveAddress'] = $options['ignore_passive_address'];
unset($options['ignore_passive_address']);

$definition->setClass(Ftp::class);
$definition->setArgument(0, $options);
}
Expand Down
83 changes: 83 additions & 0 deletions tests/Adapter/Builder/FtpAdapterDefinitionBuilderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

/*
* This file is part of the flysystem-bundle project.
*
* (c) Titouan Galopin <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Tests\League\FlysystemBundle\Adapter\Builder;

use League\Flysystem\Adapter\Ftp;
use League\FlysystemBundle\Adapter\Builder\FtpAdapterDefinitionBuilder;
use PHPUnit\Framework\TestCase;

class FtpAdapterDefinitionBuilderTest extends TestCase
{
public function createBuilder()
{
return new FtpAdapterDefinitionBuilder();
}

public function provideValidOptions()
{
yield 'minimal' => [[
'host' => 'ftp.example.com',
'username' => 'username',
'password' => 'password',
]];

yield 'full' => [[
'host' => 'ftp.example.com',
'username' => 'username',
'password' => 'password',
'port' => 21,
'root' => '/path/to/root',
'passive' => true,
'ssl' => true,
'timeout' => 30,
'ignore_passive_address' => true,
]];
}

/**
* @dataProvider provideValidOptions
*/
public function testCreateDefinition($options)
{
$this->assertSame(Ftp::class, $this->createBuilder()->createDefinition($options)->getClass());
}

public function testOptionsBehavior()
{
$definition = $this->createBuilder()->createDefinition([
'host' => 'ftp.example.com',
'username' => 'username',
'password' => 'password',
'port' => 21,
'root' => '/path/to/root',
'passive' => true,
'ssl' => true,
'timeout' => 30,
'ignore_passive_address' => true,
]);

$expected = [
'port' => 21,
'root' => '/path/to/root',
'passive' => true,
'ssl' => true,
'timeout' => 30,
'host' => 'ftp.example.com',
'username' => 'username',
'password' => 'password',
'ignorePassiveAddress' => true,
];

$this->assertSame(Ftp::class, $definition->getClass());
$this->assertSame($expected, $definition->getArgument(0));
}
}
77 changes: 77 additions & 0 deletions tests/Adapter/Builder/SftpAdapterDefinitionBuilderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

/*
* This file is part of the flysystem-bundle project.
*
* (c) Titouan Galopin <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Tests\League\FlysystemBundle\Adapter\Builder;

use League\Flysystem\Sftp\SftpAdapter;
use League\FlysystemBundle\Adapter\Builder\SftpAdapterDefinitionBuilder;
use PHPUnit\Framework\TestCase;

class SftpAdapterDefinitionBuilderTest extends TestCase
{
public function createBuilder()
{
return new SftpAdapterDefinitionBuilder();
}

public function provideValidOptions()
{
yield 'minimal' => [[
'host' => 'ftp.example.com',
'username' => 'username',
'password' => 'password',
]];

yield 'full' => [[
'host' => 'ftp.example.com',
'username' => 'username',
'password' => 'password',
'port' => 22,
'root' => '/path/to/root',
'private_key' => '/path/to/or/contents/of/privatekey',
'timeout' => 30,
]];
}

/**
* @dataProvider provideValidOptions
*/
public function testCreateDefinition($options)
{
$this->assertSame(SftpAdapter::class, $this->createBuilder()->createDefinition($options)->getClass());
}

public function testOptionsBehavior()
{
$definition = $this->createBuilder()->createDefinition([
'host' => 'ftp.example.com',
'username' => 'username',
'password' => 'password',
'port' => 22,
'root' => '/path/to/root',
'private_key' => '/path/to/or/contents/of/privatekey',
'timeout' => 30,
]);

$expected = [
'port' => 22,
'root' => '/path/to/root',
'private_key' => '/path/to/or/contents/of/privatekey',
'timeout' => 30,
'host' => 'ftp.example.com',
'username' => 'username',
'password' => 'password',
];

$this->assertSame(SftpAdapter::class, $definition->getClass());
$this->assertSame($expected, $definition->getArgument(0));
}
}
1 change: 1 addition & 0 deletions tests/Adapter/options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ fs_ftp:
passive: true
ssl: true
timeout: 30
ignore_passive_address: true

fs_gcloud:
adapter: 'gcloud'
Expand Down

0 comments on commit 993e8a4

Please sign in to comment.