Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

strategy:
matrix:
php: [7.1, 7.2, 7.3, 7.4, 8.0]
php: [7.4, 8.0, 8.1]

steps:
- name: Checkout code
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
"minimum-stability": "RC",
"require": {
"php": "^7.1 || ^8.0",
"php": "^7.4 || ^8.0",
"codeception/codeception": "*@dev",
"symfony/finder": ">=3.4 <6.0"
},
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A Codeception module for testing local filesystem.

## Requirements

* `PHP 7.1` or higher.
* `PHP 7.4` or higher.

## Installation

Expand Down
44 changes: 22 additions & 22 deletions src/Codeception/Module/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

namespace Codeception\Module;

use Codeception\Util\FileSystem as Util;
use Symfony\Component\Finder\Finder;
use Codeception\Configuration;
use Codeception\Module;
use Codeception\PHPUnit\TestCase;
use Codeception\TestInterface;
use Codeception\Configuration;
use Codeception\Util\FileSystem as Util;
use PHPUnit\Framework\AssertionFailedError;
use Symfony\Component\Finder\Finder;

/**
* Module for testing local filesystem.
Expand All @@ -24,16 +26,11 @@
*/
class Filesystem extends Module
{
protected $file;
/**
* @var string|null
*/
protected $filepath;
protected string $file = '';

/**
* @var string
*/
protected $path = '';
protected string $filePath = '';

protected string $path = '';

public function _before(TestInterface $test): void
{
Expand All @@ -56,6 +53,7 @@ protected function absolutizePath(string $path): string
if (strpos($path, '/') === 0) {
return $path;
}

// windows
if (strpos($path, ':\\') === 1) {
return $path;
Expand All @@ -78,7 +76,7 @@ protected function absolutizePath(string $path): string
public function openFile(string $filename): void
{
$this->file = file_get_contents($this->absolutizePath($filename));
$this->filepath = $filename;
$this->filePath = $filename;
}

/**
Expand All @@ -92,8 +90,9 @@ public function openFile(string $filename): void
public function deleteFile(string $filename): void
{
if (!file_exists($this->absolutizePath($filename))) {
\Codeception\PHPUnit\TestCase::fail('file not found');
TestCase::fail('file not found');
}

unlink($this->absolutizePath($filename));
}

Expand Down Expand Up @@ -162,6 +161,7 @@ public function seeNumberNewLines(int $number): void
"The number of new lines does not match with {$number}"
);
}

/**
* Checks that contents of currently opened file matches $regex
*/
Expand All @@ -185,7 +185,7 @@ public function seeThisFileMatches(string $regex): void
public function seeFileContentsEqual(string $text): void
{
$file = str_replace("\r", '', $this->file);
\Codeception\PHPUnit\TestCase::assertEquals($text, $file);
TestCase::assertEquals($text, $file);
}

/**
Expand All @@ -207,7 +207,7 @@ public function dontSeeInThisFile(string $text): void
*/
public function deleteThisFile(): void
{
$this->deleteFile($this->filepath);
$this->deleteFile($this->filePath);
}

/**
Expand All @@ -223,7 +223,7 @@ public function seeFileFound(string $filename, string $path = ''): void
{
if ($path === '' && file_exists($filename)) {
$this->openFile($filename);
\Codeception\PHPUnit\TestCase::assertFileExists($filename);
TestCase::assertFileExists($filename);
return;
}

Expand All @@ -234,7 +234,7 @@ public function seeFileFound(string $filename, string $path = ''): void
}

$this->openFile($found);
\Codeception\PHPUnit\TestCase::assertFileExists($found);
TestCase::assertFileExists($found);
}

/**
Expand All @@ -243,25 +243,25 @@ public function seeFileFound(string $filename, string $path = ''): void
public function dontSeeFileFound(string $filename, string $path = ''): void
{
if ($path === '') {
\Codeception\PHPUnit\TestCase::assertFileNotExists($filename);
TestCase::assertFileDoesNotExist($filename);
return;
}

$found = $this->findFileInPath($filename, $path);

if ($found === false) {
//this line keeps a count of assertions correct
\Codeception\PHPUnit\TestCase::assertTrue(true);
TestCase::assertTrue(true);
return;
}

\Codeception\PHPUnit\TestCase::assertFileNotExists($found);
TestCase::assertFileDoesNotExist($found);
}

/**
* Finds the first matching file
*
* @throws \PHPUnit\Framework\AssertionFailedError When path does not exist
* @throws AssertionFailedError When path does not exist
* @return string|false Path to the first matching file
*/
private function findFileInPath(string $filename, string $path)
Expand Down
11 changes: 5 additions & 6 deletions tests/unit/Codeception/Module/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@

declare(strict_types=1);

use Codeception\Lib\ModuleContainer;
use Codeception\Module\Filesystem;
use Codeception\PHPUnit\TestCase;
use Codeception\Stub;
use PHPUnit\Framework\AssertionFailedError;

if (!function_exists('make_container')) {
function make_container()
{
return Stub::make(\Codeception\Lib\ModuleContainer::class);
return Stub::make(ModuleContainer::class);
}
}

final class FilesystemTest extends \Codeception\PHPUnit\TestCase
final class FilesystemTest extends TestCase
{

/**
* @var \Codeception\Module\Filesystem
*/
protected $module;
protected ?Filesystem $module = null;

public function _setUp()
{
Expand Down