diff --git a/src/Expectation.php b/src/Expectation.php index 6e5f6030..253b1e1e 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -386,6 +386,20 @@ final class Expectation return $this; } + /** + * Asserts that the value contains the provided properties $names. + * + * @param iterable $names + */ + public function toHaveProperties(iterable $names): Expectation + { + foreach ($names as $name) { + $this->toHaveProperty($name); + } + + return $this; + } + /** * Asserts that two variables have the same value. * diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index ae209f43..4442bbb9 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -433,6 +433,11 @@ ✓ it fails with (true) ✓ it fails with (null) + PASS Tests\Features\Expect\toHaveProperties + ✓ pass + ✓ failures + ✓ not failures + PASS Tests\Features\Expect\toHaveProperty ✓ pass ✓ failures @@ -676,5 +681,5 @@ ✓ it is a test ✓ it uses correct parent class - Tests: 4 incompleted, 9 skipped, 444 passed + Tests: 4 incompleted, 9 skipped, 447 passed \ No newline at end of file diff --git a/tests/Features/Expect/toHaveProperties.php b/tests/Features/Expect/toHaveProperties.php new file mode 100644 index 00000000..ad3da1b0 --- /dev/null +++ b/tests/Features/Expect/toHaveProperties.php @@ -0,0 +1,26 @@ +name = 'Jhon'; + $object->age = 21; + + expect($object)->toHaveProperties(['name', 'age']); +}); + +test('failures', function () { + $object = new stdClass(); + $object->name = 'Jhon'; + + expect($object)->toHaveProperties(['name', 'age']); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + $object = new stdClass(); + $object->name = 'Jhon'; + $object->age = 21; + + expect($object)->not->toHaveProperties(['name', 'age']); +})->throws(ExpectationFailedException::class);