mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
feat(expect): add more methods
This commit is contained in:
@ -372,6 +372,46 @@ final class Expectation
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assert that the value array has the key.
|
||||||
|
*/
|
||||||
|
public function toHaveKey(string $key): Expectation
|
||||||
|
{
|
||||||
|
Assert::assertArrayHasKey($key, $this->value);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assert that the value is a directory.
|
||||||
|
*/
|
||||||
|
public function toBeDirectory(): Expectation
|
||||||
|
{
|
||||||
|
Assert::assertDirectoryExists($this->value);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assert that the value is a directory and is readable.
|
||||||
|
*/
|
||||||
|
public function toBeReadableDirectory(): Expectation
|
||||||
|
{
|
||||||
|
Assert::assertDirectoryIsReadable($this->value);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assert that the value is a directory and is writable.
|
||||||
|
*/
|
||||||
|
public function toBeWritableDirectory(): Expectation
|
||||||
|
{
|
||||||
|
Assert::assertDirectoryIsWritable($this->value);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dynamically calls methods on the class without any arguments.
|
* Dynamically calls methods on the class without any arguments.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -24,6 +24,11 @@
|
|||||||
PASS Tests\Expect\toBeCallable
|
PASS Tests\Expect\toBeCallable
|
||||||
✓ pass
|
✓ pass
|
||||||
✓ failures
|
✓ failures
|
||||||
|
✓ not failures
|
||||||
|
|
||||||
|
PASS Tests\Expect\toBeDirectory
|
||||||
|
✓ pass
|
||||||
|
✓ failures
|
||||||
✓ not failures
|
✓ not failures
|
||||||
|
|
||||||
PASS Tests\Expect\toBeEmpty
|
PASS Tests\Expect\toBeEmpty
|
||||||
@ -99,6 +104,11 @@
|
|||||||
PASS Tests\Expect\toBeObject
|
PASS Tests\Expect\toBeObject
|
||||||
✓ pass
|
✓ pass
|
||||||
✓ failures
|
✓ failures
|
||||||
|
✓ not failures
|
||||||
|
|
||||||
|
PASS Tests\Expect\toBeReadableDirectory
|
||||||
|
✓ pass
|
||||||
|
✓ failures
|
||||||
✓ not failures
|
✓ not failures
|
||||||
|
|
||||||
PASS Tests\Expect\toBeResource
|
PASS Tests\Expect\toBeResource
|
||||||
@ -119,12 +129,22 @@
|
|||||||
PASS Tests\Expect\toBeTrue
|
PASS Tests\Expect\toBeTrue
|
||||||
✓ strict comparisons
|
✓ strict comparisons
|
||||||
✓ failures
|
✓ failures
|
||||||
|
✓ not failures
|
||||||
|
|
||||||
|
PASS Tests\Expect\toBeWritableDirectory
|
||||||
|
✓ pass
|
||||||
|
✓ failures
|
||||||
✓ not failures
|
✓ not failures
|
||||||
|
|
||||||
PASS Tests\Expect\toContain
|
PASS Tests\Expect\toContain
|
||||||
✓ passes strings
|
✓ passes strings
|
||||||
✓ passes arrays
|
✓ passes arrays
|
||||||
✓ failures
|
✓ failures
|
||||||
|
✓ not failures
|
||||||
|
|
||||||
|
PASS Tests\Expect\toCount
|
||||||
|
✓ pass
|
||||||
|
✓ failures
|
||||||
✓ not failures
|
✓ not failures
|
||||||
|
|
||||||
PASS Tests\Expect\toEqual
|
PASS Tests\Expect\toEqual
|
||||||
@ -137,7 +157,7 @@
|
|||||||
✓ failures
|
✓ failures
|
||||||
✓ not failures
|
✓ not failures
|
||||||
|
|
||||||
PASS Tests\Expect\toHaveCount
|
PASS Tests\Expect\toHaveKey
|
||||||
✓ pass
|
✓ pass
|
||||||
✓ failures
|
✓ failures
|
||||||
✓ not failures
|
✓ not failures
|
||||||
@ -312,5 +332,5 @@
|
|||||||
WARN Tests\Visual\Success
|
WARN Tests\Visual\Success
|
||||||
- visual snapshot of test suite on success
|
- visual snapshot of test suite on success
|
||||||
|
|
||||||
Tests: 6 skipped, 183 passed
|
Tests: 6 skipped, 195 passed
|
||||||
Time: 5.77s
|
Time: 5.27s
|
||||||
|
|||||||
17
tests/Expect/toBeDirectory.php
Normal file
17
tests/Expect/toBeDirectory.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
|
test('pass', function () {
|
||||||
|
$temp = sys_get_temp_dir();
|
||||||
|
|
||||||
|
expect($temp)->toBeDirectory();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('failures', function () {
|
||||||
|
expect('/random/path/whatever')->toBeDirectory();
|
||||||
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|
||||||
|
test('not failures', function () {
|
||||||
|
expect('.')->not->toBeDirectory();
|
||||||
|
})->throws(ExpectationFailedException::class);
|
||||||
15
tests/Expect/toBeReadableDirectory.php
Normal file
15
tests/Expect/toBeReadableDirectory.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
|
test('pass', function () {
|
||||||
|
expect(sys_get_temp_dir())->toBeWritableDirectory();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('failures', function () {
|
||||||
|
expect('/random/path/whatever')->toBeWritableDirectory();
|
||||||
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|
||||||
|
test('not failures', function () {
|
||||||
|
expect(sys_get_temp_dir())->not->toBeWritableDirectory();
|
||||||
|
})->throws(ExpectationFailedException::class);
|
||||||
15
tests/Expect/toBeWritableDirectory.php
Normal file
15
tests/Expect/toBeWritableDirectory.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
|
test('pass', function () {
|
||||||
|
expect(sys_get_temp_dir())->toBeWritableDirectory();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('failures', function () {
|
||||||
|
expect('/random/path/whatever')->toBeWritableDirectory();
|
||||||
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|
||||||
|
test('not failures', function () {
|
||||||
|
expect(sys_get_temp_dir())->not->toBeWritableDirectory();
|
||||||
|
})->throws(ExpectationFailedException::class);
|
||||||
Reference in New Issue
Block a user