Testomatio - Test Management for Codeception
composer require --dev codeception/module-ftpWorks with SFTP/FTP servers.
In order to test the contents of a specific file stored on any remote FTP/SFTP system this module downloads a temporary file to the local system. The temporary directory is defined by default as
tests/_datato specify a different directory set the tmp config option to your chosen path.
Don’t forget to create the folder and ensure its writable.
Supported and tested FTP types are:
Connection uses php build in FTP client for FTP, connection to SFTP uses phpseclib pulled in using composer.
For SFTP, add phpseclib to require list.
"require": {
"phpseclib/phpseclib": "^2.0.14"
}modules:
enabled: [FTP]
config:
FTP:
type: ftp
host: '127.0.0.1'
port: 21
timeout: 120
user: 'root'
password: 'root'
key: ~/.ssh/id_rsa
tmp: 'tests/_data/ftp'
passive: true
cleanup: false
modules:
enabled: [FTP]
config:
FTP:
type: sftp
host: '127.0.0.1'
port: 22
timeout: 120
user: 'root'
password: 'root'
key: ''
tmp: 'tests/_data/ftp'
cleanup: false
This module extends the Filesystem module, file contents methods are inherited from this module.
param string $pathreturn voidEnters a directory on the ftp system - FTP root directory is used by default
param string $dirnamereturn voidErases directory contents on the FTP/SFTP server
<?php
$I->cleanDir('logs');param string $srcparam string $dstreturn voidCurrently not supported in this module, overwrite inherited method
param string $dirnamereturn voidDeletes directory with all subdirectories on the remote FTP/SFTP server
<?php
$I->deleteDir('vendor');param string $filenamereturn voidDeletes a file on the remote FTP/SFTP system
<?php
$I->deleteFile('composer.lock');return voidDeletes a file
param string $filenameparam string $pathreturn voidChecks if file does not exist in path on the remote FTP/SFTP system
param string $regexparam string $pathreturn voidChecks if file does not exist in path on the remote FTP/SFTP system, using regular expression as filename.
DOES NOT OPEN the file when it’s exists
param string $textreturn voidChecks If opened file doesn’t contain text in it
<?php
$I->openFile('composer.json');
$I->dontSeeInThisFile('codeception/codeception');return stringGrabber method to return current working directory
<?php
$pwd = $I->grabDirectory();param string $pathparam bool $ignore - suppress ‘.’, ‘..’ and ‘.thumbs.db’return intGrabber method for returning file/folders count in directory
<?php
$count = $I->grabFileCount();
$count = $I->grabFileCount('TEST', false); // Include . .. .thumbs.dbparam string $pathparam bool $ignore - suppress ‘.’, ‘..’ and ‘.thumbs.db’return arrayGrabber method for returning file/folders listing in an array
<?php
$files = $I->grabFileList();
$count = $I->grabFileList('TEST', false); // Include . .. .thumbs.dbparam string $filenamereturn intGrabber method to return last modified timestamp
<?php
$time = $I->grabFileModified('test.txt');param string $filenamereturn intGrabber method to return file size
<?php
$size = $I->grabFileSize('test.txt');param string $userparam string $passwordreturn voidChange the logged in user mid-way through your test, this closes the current connection to the server and initialises and new connection.
On initiation of this modules you are automatically logged into the server using the specified config options or defaulted to anonymous user if not provided.
<?php
$I->loginAs('user','password');param string $dirnamereturn voidCreate a directory on the server
<?php
$I->makeDir('vendor');param string $filenamereturn voidOpens a file (downloads from the remote FTP/SFTP system to a tmp directory for processing) and stores it’s content.
Usage:
<?php
$I->openFile('composer.json');
$I->seeInThisFile('codeception/codeception');param string $dirnameparam string $renamereturn voidRename/Move directory on the FTP/SFTP server
<?php
$I->renameDir('vendor', 'vendor_old');param string $filenameparam string $renamereturn voidRename/Move file on the FTP/SFTP server
<?php
$I->renameFile('composer.lock', 'composer_old.lock');param string $textreturn voidChecks the strict matching of file contents.
Unlike seeInThisFile will fail if file has something more than expected lines.
Better to use with HEREDOC strings.
Matching is done after removing “\r” chars from file content.
<?php
$I->openFile('process.pid');
$I->seeFileContentsEqual('3192');param string $filenameparam string $pathreturn voidChecks if file exists in path on the remote FTP/SFTP system.
DOES NOT OPEN the file when it’s exists
<?php
$I->seeFileFound('UserModel.php','app/models');param string $regexparam string $pathreturn voidChecks if file exists in path on the remote FTP/SFTP system, using regular expression as filename.
DOES NOT OPEN the file when it’s exists
<?php
$I->seeFileFoundMatches('/^UserModel_([0-9]{6}).php$/','app/models');param string $textreturn voidChecks If opened file has text in it.
Usage:
<?php
$I->openFile('composer.json');
$I->seeInThisFile('codeception/codeception');param int $number New linesreturn voidChecks If opened file has the number of new lines.
Usage:
<?php
$I->openFile('composer.json');
$I->seeNumberNewLines(5);param string $regexreturn voidChecks that contents of currently opened file matches $regex
param string $filenameparam string $contentsreturn voidSaves contents to tmp file and uploads the FTP/SFTP system.
Overwrites current file on server if exists.
<?php
$I->writeToFile('composer.json', 'some data here');