Search

Filesystem

Installation

composer require --dev codeception/module-filesystem

Description

Module for testing local filesystem. Fork it to extend the module for FTP, Amazon S3, others.

Status

Module was developed to test Codeception itself.

Actions

amInPath

  • param string $path
  • return void

Enters a directory In local filesystem.

Project root directory is used by default

cleanDir

  • param string $dirname
  • return void

Erases directory contents

<?php
$I->cleanDir('logs');

copyDir

  • param string $src
  • param string $dst
  • return void

Copies directory with all contents

<?php
$I->copyDir('vendor','old_vendor');

deleteDir

  • param string $dirname
  • return void

Deletes directory with all subdirectories

<?php
$I->deleteDir('vendor');

deleteFile

  • param string $filename
  • return void

Deletes a file

<?php
$I->deleteFile('composer.lock');

deleteThisFile

  • return void

Deletes a file

dontSeeFileFound

  • param string $filename
  • param string $path
  • return void

Checks if file does not exist in path

dontSeeInThisFile

  • param string $text
  • return void

Checks If opened file doesn’t contain text in it

<?php
$I->openFile('composer.json');
$I->dontSeeInThisFile('codeception/codeception');

openFile

  • param string $filename
  • return void

Opens a file and stores it’s content.

Usage:

<?php
$I->openFile('composer.json');
$I->seeInThisFile('codeception/codeception');

seeFileContentsEqual

  • param string $text
  • return void

Checks 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');

seeFileFound

  • param string $filename
  • param string $path
  • return void

Checks if file exists in path.

Opens a file when it’s exists

<?php
$I->seeFileFound('UserModel.php','app/models');

seeInThisFile

  • param string $text
  • return void

Checks If opened file has text in it.

Usage:

<?php
$I->openFile('composer.json');
$I->seeInThisFile('codeception/codeception');

seeNumberNewLines

  • param int $number New lines
  • return void

Checks If opened file has the number of new lines.

Usage:

<?php
$I->openFile('composer.json');
$I->seeNumberNewLines(5);

seeThisFileMatches

  • param string $regex
  • return void

Checks that contents of currently opened file matches $regex

writeToFile

  • param string $filename
  • param string $contents
  • return void

Saves contents to file

 

Module reference is taken from the source code. Help us to improve documentation. Edit module reference
Don't know how to write tests on your own? We will build or improve them for you. Request a quote for official enterprise support or trainings