-
Notifications
You must be signed in to change notification settings - Fork 17
/
FtpAdapterTest.php
119 lines (99 loc) · 3.4 KB
/
FtpAdapterTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
declare(strict_types=1);
namespace League\Flysystem\Ftp;
use League\Flysystem\FilesystemAdapter;
use function mock_function;
use function reset_function_mocks;
/**
* @group ftp
*/
class FtpAdapterTest extends FtpAdapterTestCase
{
protected static function createFilesystemAdapter(): FilesystemAdapter
{
$options = FtpConnectionOptions::fromArray([
'host' => 'localhost',
'port' => 2121,
'timestampsOnUnixListingsEnabled' => true,
'root' => '/home/foo/upload/',
'username' => 'foo',
'password' => 'pass',
]);
static::$connectivityChecker = new ConnectivityCheckerThatCanFail(new NoopCommandConnectivityChecker());
static::$connectionProvider = new StubConnectionProvider(new FtpConnectionProvider());
return new FtpAdapter(
$options,
static::$connectionProvider,
static::$connectivityChecker,
);
}
/**
* @test
*/
public function disconnect_after_destruct(): void
{
/** @var FtpAdapter $adapter */
$adapter = $this->adapter();
$reflection = new \ReflectionObject($adapter);
$adapter->fileExists('foo.txt');
$reflectionProperty = $reflection->getProperty('connection');
$reflectionProperty->setAccessible(true);
$connection = $reflectionProperty->getValue($adapter);
unset($reflection);
$this->assertTrue(false !== ftp_pwd($connection));
$adapter->__destruct();
static::clearFilesystemAdapterCache();
$this->assertFalse((new NoopCommandConnectivityChecker())->isConnected($connection));
}
/**
* @test
*/
public function it_can_disconnect(): void
{
/** @var FtpAdapter $adapter */
$adapter = $this->adapter();
$this->assertFalse($adapter->fileExists('not-existing.file'));
self::assertTrue(static::$connectivityChecker->isConnected(static::$connectionProvider->connection));
$adapter->disconnect();
self::assertFalse(static::$connectivityChecker->isConnected(static::$connectionProvider->connection));
}
/**
* @test
*/
public function not_being_able_to_resolve_connection_root(): void
{
$options = FtpConnectionOptions::fromArray([
'host' => 'localhost',
'port' => 2121,
'timestampsOnUnixListingsEnabled' => true,
'root' => '/invalid/root',
'username' => 'foo',
'password' => 'pass',
]);
$adapter = new FtpAdapter($options);
$this->expectExceptionObject(UnableToResolveConnectionRoot::itDoesNotExist('/invalid/root'));
$adapter->delete('something');
}
/**
* @test
*/
public function not_being_able_to_resolve_connection_root_pwd(): void
{
$options = FtpConnectionOptions::fromArray([
'host' => 'localhost',
'port' => 2121,
'timestampsOnUnixListingsEnabled' => true,
'root' => '/home/foo/upload/',
'username' => 'foo',
'password' => 'pass',
]);
$this->expectExceptionObject(UnableToResolveConnectionRoot::couldNotGetCurrentDirectory());
mock_function('ftp_pwd', false);
$adapter = new FtpAdapter($options);
$adapter->delete('something');
}
protected function tearDown(): void
{
reset_function_mocks();
}
}