diff --git a/src/Expectation.php b/src/Expectation.php index 0770e367..4e5b9633 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -414,6 +414,36 @@ final class Expectation return $this; } + /** + * Asserts that the value is a file. + */ + public function toBeFile(): Expectation + { + Assert::assertFileExists($this->value); + + return $this; + } + + /** + * Asserts that the value is a file and is readable. + */ + public function toBeReadableFile(): Expectation + { + Assert::assertFileIsReadable($this->value); + + return $this; + } + + /** + * Asserts that the value is a file and is writable. + */ + public function toBeWritableFile(): Expectation + { + Assert::assertFileIsWritable($this->value); + + return $this; + } + /** * Dynamically calls methods on the class without any arguments. * diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 500f7a52..a0769abf 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -39,6 +39,11 @@ PASS Tests\Expect\toBeFalse ✓ strict comparisons ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeFile + ✓ pass + ✓ failures ✓ not failures PASS Tests\Expect\toBeFloat @@ -109,6 +114,11 @@ PASS Tests\Expect\toBeReadableDirectory ✓ pass ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeReadableFile + ✓ pass + ✓ failures ✓ not failures PASS Tests\Expect\toBeResource @@ -134,6 +144,11 @@ PASS Tests\Expect\toBeWritableDirectory ✓ pass ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeWritableFile + ✓ pass + ✓ failures ✓ not failures PASS Tests\Expect\toContain @@ -337,4 +352,4 @@ ✓ depends with defined arguments ✓ depends run test only once - Tests: 6 skipped, 198 passed \ No newline at end of file + Tests: 6 skipped, 207 passed diff --git a/tests/Expect/toBeFile.php b/tests/Expect/toBeFile.php new file mode 100644 index 00000000..e8bc59d1 --- /dev/null +++ b/tests/Expect/toBeFile.php @@ -0,0 +1,23 @@ +tempFile = sys_get_temp_dir() . '/fake.file'); +}); + +afterEach(function () { + unlink($this->tempFile); +}); + +test('pass', function () { + expect($this->tempFile)->toBeFile(); +}); + +test('failures', function () { + expect('/random/path/whatever.file')->toBeFile(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect($this->tempFile)->not->toBeFile(); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toBeReadableDirectory.php b/tests/Expect/toBeReadableDirectory.php index 88f96019..704109b5 100644 --- a/tests/Expect/toBeReadableDirectory.php +++ b/tests/Expect/toBeReadableDirectory.php @@ -3,13 +3,13 @@ use PHPUnit\Framework\ExpectationFailedException; test('pass', function () { - expect(sys_get_temp_dir())->toBeWritableDirectory(); + expect(sys_get_temp_dir())->toBeReadableDirectory(); }); test('failures', function () { - expect('/random/path/whatever')->toBeWritableDirectory(); + expect('/random/path/whatever')->toBeReadableDirectory(); })->throws(ExpectationFailedException::class); test('not failures', function () { - expect(sys_get_temp_dir())->not->toBeWritableDirectory(); + expect(sys_get_temp_dir())->not->toBeReadableDirectory(); })->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toBeReadableFile.php b/tests/Expect/toBeReadableFile.php new file mode 100644 index 00000000..756046fa --- /dev/null +++ b/tests/Expect/toBeReadableFile.php @@ -0,0 +1,23 @@ +tempFile = sys_get_temp_dir() . '/fake.file'); +}); + +afterEach(function () { + unlink($this->tempFile); +}); + +test('pass', function () { + expect($this->tempFile)->toBeReadableFile(); +}); + +test('failures', function () { + expect('/random/path/whatever.file')->toBeReadableFile(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect($this->tempFile)->not->toBeReadableFile(); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toBeWritableFile.php b/tests/Expect/toBeWritableFile.php new file mode 100644 index 00000000..96fe05c3 --- /dev/null +++ b/tests/Expect/toBeWritableFile.php @@ -0,0 +1,23 @@ +tempFile = sys_get_temp_dir() . '/fake.file'); +}); + +afterEach(function () { + unlink($this->tempFile); +}); + +test('pass', function () { + expect($this->tempFile)->toBeWritableFile(); +}); + +test('failures', function () { + expect('/random/path/whatever.file')->toBeWritableFile(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect($this->tempFile)->not->toBeWritableFile(); +})->throws(ExpectationFailedException::class);