From 31726b51ad0f6320a6df5617224a504e082e6208 Mon Sep 17 00:00:00 2001 From: Lucas Giovanny Date: Sun, 2 Apr 2023 11:15:31 +0100 Subject: [PATCH] update toHaveProperties --- src/Mixins/Expectation.php | 4 +-- tests/.snapshots/success.txt | 2 +- tests/Features/Expect/toHaveProperties.php | 35 +++++++++++++++++----- tests/Visual/Parallel.php | 2 +- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/Mixins/Expectation.php b/src/Mixins/Expectation.php index bd658817..ad95ea98 100644 --- a/src/Mixins/Expectation.php +++ b/src/Mixins/Expectation.php @@ -296,8 +296,8 @@ final class Expectation */ public function toHaveProperties(iterable $names, string $message = ''): self { - foreach ($names as $name) { - $this->toHaveProperty($name, message: $message); + foreach ($names as $name => $value) { + is_int($name) ? $this->toHaveProperty($value, message: $message) : $this->toHaveProperty($name, $value, $message); } return $this; diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index cee314ab..6f490dbe 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -1016,4 +1016,4 @@ PASS Tests\Visual\Version ✓ visual snapshot of help command output - Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 14 skipped, 709 passed (1711 assertions) \ No newline at end of file + Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 14 skipped, 709 passed (1717 assertions) \ No newline at end of file diff --git a/tests/Features/Expect/toHaveProperties.php b/tests/Features/Expect/toHaveProperties.php index c4102f42..cca0a38e 100644 --- a/tests/Features/Expect/toHaveProperties.php +++ b/tests/Features/Expect/toHaveProperties.php @@ -4,30 +4,49 @@ use PHPUnit\Framework\ExpectationFailedException; test('pass', function () { $object = new stdClass(); - $object->name = 'Jhon'; + $object->name = 'John'; $object->age = 21; - expect($object)->toHaveProperties(['name', 'age']); + expect($object) + ->toHaveProperties(['name', 'age']) + ->toHaveProperties([ + 'name' => 'John', + 'age' => 21, + ]); }); test('failures', function () { $object = new stdClass(); - $object->name = 'Jhon'; + $object->name = 'John'; - expect($object)->toHaveProperties(['name', 'age']); + expect($object) + ->toHaveProperties(['name', 'age']) + ->toHaveProperties([ + 'name' => 'John', + 'age' => 21, + ]); })->throws(ExpectationFailedException::class); test('failures with custom message', function () { $object = new stdClass(); - $object->name = 'Jhon'; + $object->name = 'John'; - expect($object)->toHaveProperties(['name', 'age'], 'oh no!'); + expect($object) + ->toHaveProperties(['name', 'age'], 'oh no!') + ->toHaveProperties([ + 'name' => 'John', + 'age' => 21, + ], 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); test('not failures', function () { $object = new stdClass(); - $object->name = 'Jhon'; + $object->name = 'John'; $object->age = 21; - expect($object)->not->toHaveProperties(['name', 'age']); + expect($object)->not->toHaveProperties(['name', 'age']) + ->not->toHaveProperties([ + 'name' => 'John', + 'age' => 21, + ]); })->throws(ExpectationFailedException::class); diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 6c266d5e..8a354fe2 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -18,7 +18,7 @@ $run = function () { test('parallel', function () use ($run) { expect($run('--exclude-group=integration')) - ->toContain('Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 11 skipped, 697 passed (1696 assertions)') + ->toContain('Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 11 skipped, 697 passed (1702 assertions)') ->toContain('Parallel: 3 processes'); })->skipOnWindows();