diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bfbad11..8ab4cff 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/composer.json b/composer.json index 1864faf..6289b08 100644 --- a/composer.json +++ b/composer.json @@ -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" }, diff --git a/readme.md b/readme.md index 937e409..eb095a0 100644 --- a/readme.md +++ b/readme.md @@ -9,7 +9,7 @@ A Codeception module for testing local filesystem. ## Requirements -* `PHP 7.1` or higher. +* `PHP 7.4` or higher. ## Installation diff --git a/src/Codeception/Module/Filesystem.php b/src/Codeception/Module/Filesystem.php index 7268389..33d5606 100644 --- a/src/Codeception/Module/Filesystem.php +++ b/src/Codeception/Module/Filesystem.php @@ -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. @@ -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 { @@ -56,6 +53,7 @@ protected function absolutizePath(string $path): string if (strpos($path, '/') === 0) { return $path; } + // windows if (strpos($path, ':\\') === 1) { return $path; @@ -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; } /** @@ -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)); } @@ -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 */ @@ -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); } /** @@ -207,7 +207,7 @@ public function dontSeeInThisFile(string $text): void */ public function deleteThisFile(): void { - $this->deleteFile($this->filepath); + $this->deleteFile($this->filePath); } /** @@ -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; } @@ -234,7 +234,7 @@ public function seeFileFound(string $filename, string $path = ''): void } $this->openFile($found); - \Codeception\PHPUnit\TestCase::assertFileExists($found); + TestCase::assertFileExists($found); } /** @@ -243,7 +243,7 @@ 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; } @@ -251,17 +251,17 @@ public function dontSeeFileFound(string $filename, string $path = ''): void 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) diff --git a/tests/unit/Codeception/Module/FilesystemTest.php b/tests/unit/Codeception/Module/FilesystemTest.php index e3bc481..a077630 100644 --- a/tests/unit/Codeception/Module/FilesystemTest.php +++ b/tests/unit/Codeception/Module/FilesystemTest.php @@ -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() {