From 4331b2aaf6d9dd03e07588556a5895425a7fce82 Mon Sep 17 00:00:00 2001 From: Esteban Date: Fri, 3 Sep 2021 04:26:57 -0400 Subject: [PATCH 1/3] Add toHaveProperties --- src/Expectation.php | 14 ++++++++++++ tests/Features/Expect/toHaveProperties.php | 26 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/Features/Expect/toHaveProperties.php diff --git a/src/Expectation.php b/src/Expectation.php index 6e5f6030..02d27c28 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 array $names + */ + public function toHaveProperties(array $names): Expectation + { + foreach ($names as $name) { + $this->toHaveProperty($name); + } + + return $this; + } + /** * Asserts that two variables have the same value. * 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); From 536ce1eca0b80c14e14a757cc47fe2e32915c806 Mon Sep 17 00:00:00 2001 From: Esteban Date: Fri, 3 Sep 2021 04:40:48 -0400 Subject: [PATCH 2/3] Update snapshots --- tests/.snapshots/success.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 From 253e9d10c8a25a0879665fa581f4819127957600 Mon Sep 17 00:00:00 2001 From: Esteban Date: Fri, 3 Sep 2021 04:44:10 -0400 Subject: [PATCH 3/3] Fix types --- src/Expectation.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Expectation.php b/src/Expectation.php index 02d27c28..253b1e1e 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -389,9 +389,9 @@ final class Expectation /** * Asserts that the value contains the provided properties $names. * - * @param array $names + * @param iterable $names */ - public function toHaveProperties(array $names): Expectation + public function toHaveProperties(iterable $names): Expectation { foreach ($names as $name) { $this->toHaveProperty($name);