Skip to content

Commit 372f86e

Browse files
author
Dorozhkin Anton Vyacheslavovich
committed
Initial commit
0 parents  commit 372f86e

File tree

11 files changed

+553
-0
lines changed

11 files changed

+553
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/vendor/
2+
/composer.lock
3+
/.php_cs.cache

.php_cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->exclude('vendor')
5+
->in(__DIR__);
6+
7+
return PhpCsFixer\Config::create()
8+
->setRules([
9+
'@Symfony' => true,
10+
'concat_space' => ['spacing' => 'one'],
11+
'phpdoc_align' => false,
12+
'phpdoc_to_comment' => false,
13+
'header_comment' => false,
14+
])
15+
->setFinder($finder);

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2017-2018 Lamoda
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
WORKING_DIR=$(CURDIR)
2+
3+
php-cs-check:
4+
$(WORKING_DIR)/vendor/bin/php-cs-fixer fix --dry-run --format=junit --diff
5+
6+
php-cs-fix:
7+
$(WORKING_DIR)/vendor/bin/php-cs-fixer fix

README.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Codeception FlySystem Extension
2+
3+
This extension supports working with [FlySystem](https://flysystem.thephpleague.com/) with several adapters.
4+
5+
Provides a set of methods for checking and modifying files on remote storage.
6+
7+
## Installation
8+
9+
1. Install library
10+
```bash
11+
composer require lamoda/codeception-flysystem
12+
```
13+
14+
2. Add configuration to codeception.yml
15+
```yaml
16+
modules:
17+
config:
18+
\Lamoda\Codeception\Extension\FlySystemModule:
19+
adapters:
20+
webdav:
21+
builderAdapter: \Lamoda\Codeception\Extension\AdapterBuilder\WebdavAdapterBuilder
22+
config:
23+
baseUri: "http://webdav-host"
24+
userName: "userName"
25+
password: "password"
26+
authType: "authType"
27+
sftp:
28+
builderAdapter: \Lamoda\Codeception\Extension\AdapterBuilder\SftpAdapterBuilder
29+
config:
30+
host: "http://sftp-host"
31+
username: "username"
32+
password: "password"
33+
port: "22"
34+
root: "/"
35+
```
36+
37+
3. Include to suite
38+
```yaml
39+
modules:
40+
enabled:
41+
- \Lamoda\Codeception\Extension\FlySystemModule
42+
```
43+
44+
## Supported adapters
45+
46+
### [sftp](https://flysystem.thephpleague.com/adapter/sftp/)
47+
48+
Configuration example:
49+
50+
```yaml
51+
modules:
52+
config:
53+
\Lamoda\Codeception\Extension\FlySystemModule:
54+
adapters:
55+
sftp:
56+
builderAdapter: \Lamoda\Codeception\Extension\AdapterBuilder\SftpAdapterBuilder
57+
config:
58+
host: "http://sftp-host"
59+
username: "username"
60+
password: "password"
61+
port: "22"
62+
root: "/"
63+
```
64+
65+
Usage:
66+
67+
```php
68+
$fileSystem = $this->tester->getFileSystem('sftp');
69+
```
70+
71+
### [webdav](https://flysystem.thephpleague.com/adapter/webdav/)
72+
73+
Configuration example:
74+
75+
```yaml
76+
modules:
77+
config:
78+
\Lamoda\Codeception\Extension\FlySystemModule:
79+
adapters:
80+
webdav:
81+
builderAdapter: \Lamoda\Codeception\Extension\AdapterBuilder\WebdavAdapterBuilder
82+
config:
83+
baseUri: "http://webdav-host"
84+
userName: "userName"
85+
password: "password"
86+
authType: "authType"
87+
```
88+
89+
Usage:
90+
91+
```php
92+
$fileSystem = $this->tester->getFileSystem('webdav');
93+
```
94+
95+
## Usage
96+
97+
Get instance of FileSystem by name from config:
98+
99+
```php
100+
$fileSystem = $this->tester->getFileSystem('sftp');
101+
```
102+
103+
Modify file on remote server:
104+
105+
```php
106+
$fileSystem->clearDir('/path/to/dir');
107+
$fileSystem->writeFile('test.txt', 'Hello world!');
108+
$fileSystem->copyFile('test.txt', 'test_copy.txt');
109+
$fileSystem->deleteFile('test.txt');
110+
111+
$files = $fileSystem->grabFileList('/path/to/dir');
112+
```
113+
114+
Check files on remote server:
115+
116+
```php
117+
$fileSystem->canSeeFile('test_copy.txt');
118+
$fileSystem->cantSeeFile('test.txt');
119+
120+
$fileSystem->seeInFile('test_copy.txt', 'Hello');
121+
122+
$fileSystem->seeFilesCount('/path/to/dir', 1);
123+
124+
$fileSystem->seeFileFoundMatches('/copy$/', '/path/to/dir');
125+
$fileSystem->dontSeeFileFoundMatches('/test$/', '/path/to/dir');
126+
```
127+
128+
## Development
129+
130+
### PHP Coding Standards Fixer
131+
132+
```bash
133+
make php-cs-check
134+
make php-cs-fix
135+
```

composer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "lamoda/codeception-flysystem",
3+
"description": "Remote files checker for codeception tests",
4+
"type": "library",
5+
"license": "MIT",
6+
"minimum-stability": "stable",
7+
"require": {
8+
"php": ">=5.6",
9+
"codeception/codeception": "~2.3.0",
10+
"oneup/flysystem-bundle": "~1.7.0",
11+
"league/flysystem-sftp": "~1.0.0",
12+
"league/flysystem-webdav": "~1.0.0"
13+
},
14+
"autoload": {
15+
"psr-4": {
16+
"Lamoda\\Codeception\\Extension\\": "src/Extension/"
17+
}
18+
},
19+
"require-dev": {
20+
"friendsofphp/php-cs-fixer": "^2.13"
21+
}
22+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Lamoda\Codeception\Extension\AdapterFactory;
4+
5+
use League\Flysystem\AdapterInterface;
6+
7+
interface AdapterFactoryInterface
8+
{
9+
/**
10+
* @param array $config
11+
*
12+
* @return AdapterInterface
13+
*/
14+
public static function createAdapter(array $config);
15+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Lamoda\Codeception\Extension\AdapterFactory;
4+
5+
use League\Flysystem\AdapterInterface;
6+
use League\Flysystem\Sftp\SftpAdapter;
7+
8+
class SftpAdapterFactory implements AdapterFactoryInterface
9+
{
10+
/**
11+
* @param array $config
12+
*
13+
* @return AdapterInterface
14+
*/
15+
public static function createAdapter(array $config)
16+
{
17+
return new SftpAdapter($config);
18+
}
19+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Lamoda\Codeception\Extension\AdapterFactory;
4+
5+
use League\Flysystem\AdapterInterface;
6+
use League\Flysystem\WebDAV\WebDAVAdapter;
7+
use Sabre\DAV\Client;
8+
9+
class WebdavAdapterFactory implements AdapterFactoryInterface
10+
{
11+
/**
12+
* @param array $config
13+
*
14+
* @return AdapterInterface
15+
*/
16+
public static function createAdapter(array $config)
17+
{
18+
$client = new Client($config);
19+
20+
return new WebDAVAdapter($client);
21+
}
22+
}

0 commit comments

Comments
 (0)