From 50cd1056eb818ee79d2ed54c24c737ea6d1cf1e3 Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Wed, 12 Aug 2020 12:24:00 +0100 Subject: [PATCH 1/5] feat(expectations): add file assertions --- src/Expectation.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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. * From e1fbf56f3d96484289ca20def1bcfab883bb6932 Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Wed, 12 Aug 2020 12:51:35 +0100 Subject: [PATCH 2/5] tests(expectations): fix method in test file --- tests/Expect/toBeReadableDirectory.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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); From 8cc95802537482c11b9c279569d50057d9ba9a52 Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Wed, 12 Aug 2020 12:51:49 +0100 Subject: [PATCH 3/5] tests(expectations): add tests for file assertions --- tests/Expect/toBeFile.php | 23 +++++++++++++++++++++++ tests/Expect/toBeReadableFile.php | 23 +++++++++++++++++++++++ tests/Expect/toBeWritableFile.php | 23 +++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 tests/Expect/toBeFile.php create mode 100644 tests/Expect/toBeReadableFile.php create mode 100644 tests/Expect/toBeWritableFile.php 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/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); From 3695736b3a725c00620166f122d8d570e116ebe7 Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Wed, 12 Aug 2020 12:58:01 +0100 Subject: [PATCH 4/5] tests: update snapshots --- tests/.snapshots/success.txt | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 500f7a52..4d1480dd 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,6 @@ ✓ 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 + Time: 5.89s + From 708b4b1d498ed420b47c12439c36a91a68ae0320 Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Thu, 13 Aug 2020 10:03:15 +0100 Subject: [PATCH 5/5] tests: fix snapshots --- tests/.snapshots/success.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 4d1480dd..a0769abf 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -353,5 +353,3 @@ ✓ depends run test only once Tests: 6 skipped, 207 passed - Time: 5.89s -