mirror of
https://github.com/pestphp/pest.git
synced 2026-03-11 18:27:23 +01:00
Merge pull request #162 from owenvoke/feature/file-expectations
feat(expectations): add file assertions
This commit is contained in:
@ -414,6 +414,36 @@ final class Expectation
|
|||||||
return $this;
|
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.
|
* Dynamically calls methods on the class without any arguments.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -39,6 +39,11 @@
|
|||||||
PASS Tests\Expect\toBeFalse
|
PASS Tests\Expect\toBeFalse
|
||||||
✓ strict comparisons
|
✓ strict comparisons
|
||||||
✓ failures
|
✓ failures
|
||||||
|
✓ not failures
|
||||||
|
|
||||||
|
PASS Tests\Expect\toBeFile
|
||||||
|
✓ pass
|
||||||
|
✓ failures
|
||||||
✓ not failures
|
✓ not failures
|
||||||
|
|
||||||
PASS Tests\Expect\toBeFloat
|
PASS Tests\Expect\toBeFloat
|
||||||
@ -109,6 +114,11 @@
|
|||||||
PASS Tests\Expect\toBeReadableDirectory
|
PASS Tests\Expect\toBeReadableDirectory
|
||||||
✓ pass
|
✓ pass
|
||||||
✓ failures
|
✓ failures
|
||||||
|
✓ not failures
|
||||||
|
|
||||||
|
PASS Tests\Expect\toBeReadableFile
|
||||||
|
✓ pass
|
||||||
|
✓ failures
|
||||||
✓ not failures
|
✓ not failures
|
||||||
|
|
||||||
PASS Tests\Expect\toBeResource
|
PASS Tests\Expect\toBeResource
|
||||||
@ -134,6 +144,11 @@
|
|||||||
PASS Tests\Expect\toBeWritableDirectory
|
PASS Tests\Expect\toBeWritableDirectory
|
||||||
✓ pass
|
✓ pass
|
||||||
✓ failures
|
✓ failures
|
||||||
|
✓ not failures
|
||||||
|
|
||||||
|
PASS Tests\Expect\toBeWritableFile
|
||||||
|
✓ pass
|
||||||
|
✓ failures
|
||||||
✓ not failures
|
✓ not failures
|
||||||
|
|
||||||
PASS Tests\Expect\toContain
|
PASS Tests\Expect\toContain
|
||||||
@ -337,4 +352,4 @@
|
|||||||
✓ depends with defined arguments
|
✓ depends with defined arguments
|
||||||
✓ depends run test only once
|
✓ depends run test only once
|
||||||
|
|
||||||
Tests: 6 skipped, 198 passed
|
Tests: 6 skipped, 207 passed
|
||||||
|
|||||||
23
tests/Expect/toBeFile.php
Normal file
23
tests/Expect/toBeFile.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
touch($this->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);
|
||||||
@ -3,13 +3,13 @@
|
|||||||
use PHPUnit\Framework\ExpectationFailedException;
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
test('pass', function () {
|
test('pass', function () {
|
||||||
expect(sys_get_temp_dir())->toBeWritableDirectory();
|
expect(sys_get_temp_dir())->toBeReadableDirectory();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('failures', function () {
|
test('failures', function () {
|
||||||
expect('/random/path/whatever')->toBeWritableDirectory();
|
expect('/random/path/whatever')->toBeReadableDirectory();
|
||||||
})->throws(ExpectationFailedException::class);
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|
||||||
test('not failures', function () {
|
test('not failures', function () {
|
||||||
expect(sys_get_temp_dir())->not->toBeWritableDirectory();
|
expect(sys_get_temp_dir())->not->toBeReadableDirectory();
|
||||||
})->throws(ExpectationFailedException::class);
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|||||||
23
tests/Expect/toBeReadableFile.php
Normal file
23
tests/Expect/toBeReadableFile.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
touch($this->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);
|
||||||
23
tests/Expect/toBeWritableFile.php
Normal file
23
tests/Expect/toBeWritableFile.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
touch($this->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);
|
||||||
Reference in New Issue
Block a user