From 8cc95802537482c11b9c279569d50057d9ba9a52 Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Wed, 12 Aug 2020 12:51:49 +0100 Subject: [PATCH] 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);