|
| 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 | +``` |
0 commit comments