diff --git a/src/Expectation.php b/src/Expectation.php index 4aa2eee9..f46053fa 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -372,6 +372,46 @@ final class Expectation 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. * diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index af19b3e5..cf138b1c 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -24,6 +24,11 @@ PASS Tests\Expect\toBeCallable ✓ pass ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeDirectory + ✓ pass + ✓ failures ✓ not failures PASS Tests\Expect\toBeEmpty @@ -99,6 +104,11 @@ PASS Tests\Expect\toBeObject ✓ pass ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeReadableDirectory + ✓ pass + ✓ failures ✓ not failures PASS Tests\Expect\toBeResource @@ -119,6 +129,11 @@ PASS Tests\Expect\toBeTrue ✓ strict comparisons ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeWritableDirectory + ✓ pass + ✓ failures ✓ not failures PASS Tests\Expect\toContain @@ -140,6 +155,11 @@ PASS Tests\Expect\toHaveCount ✓ pass ✓ failures + ✓ not failures + + PASS Tests\Expect\toHaveKey + ✓ pass + ✓ failures ✓ not failures PASS Tests\Expect\toHaveProperty @@ -312,5 +332,5 @@ WARN Tests\Visual\Success - visual snapshot of test suite on success - Tests: 6 skipped, 183 passed - Time: 5.77s + Tests: 6 skipped, 195 passed + Time: 5.27s diff --git a/tests/Expect/toBeDirectory.php b/tests/Expect/toBeDirectory.php new file mode 100644 index 00000000..f30df144 --- /dev/null +++ b/tests/Expect/toBeDirectory.php @@ -0,0 +1,17 @@ +toBeDirectory(); +}); + +test('failures', function () { + expect('/random/path/whatever')->toBeDirectory(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect('.')->not->toBeDirectory(); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toBeReadableDirectory.php b/tests/Expect/toBeReadableDirectory.php new file mode 100644 index 00000000..88f96019 --- /dev/null +++ b/tests/Expect/toBeReadableDirectory.php @@ -0,0 +1,15 @@ +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); diff --git a/tests/Expect/toBeWritableDirectory.php b/tests/Expect/toBeWritableDirectory.php new file mode 100644 index 00000000..88f96019 --- /dev/null +++ b/tests/Expect/toBeWritableDirectory.php @@ -0,0 +1,15 @@ +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); diff --git a/tests/Expect/toEqualCanonicalizing.php b/tests/Expect/toEqualCanonicalizing.php new file mode 100644 index 00000000..5e1178b9 --- /dev/null +++ b/tests/Expect/toEqualCanonicalizing.php @@ -0,0 +1,16 @@ +toEqualCanonicalizing([3, 1, 2]); + expect(['g', 'a', 'z'])->not->toEqualCanonicalizing(['a', 'z']); +}); + +test('failures', function () { + expect([3, 2, 1])->toEqualCanonicalizing([1, 2]); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect(['a', 'b', 'c'])->not->toEqualCanonicalizing(['b', 'a', 'c']); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toHaveKey.php b/tests/Expect/toHaveKey.php new file mode 100644 index 00000000..1695688b --- /dev/null +++ b/tests/Expect/toHaveKey.php @@ -0,0 +1,15 @@ + 1, 'b', 'c' => 'world'])->toHaveKey('c'); +}); + +test('failures', function () { + expect(['a' => 1, 'b', 'c' => 'world'])->toHaveKey('hello'); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect(['a' => 1, 'hello' => 'world', 'c'])->not->toHaveKey('hello'); +})->throws(ExpectationFailedException::class);