mirror of
https://github.com/pestphp/pest.git
synced 2026-03-12 02:37:22 +01:00
Add toHaveProperties
This commit is contained in:
@ -386,6 +386,20 @@ final class Expectation
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the value contains the provided properties $names.
|
||||||
|
*
|
||||||
|
* @param array<string> $names
|
||||||
|
*/
|
||||||
|
public function toHaveProperties(array $names): Expectation
|
||||||
|
{
|
||||||
|
foreach ($names as $name) {
|
||||||
|
$this->toHaveProperty($name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that two variables have the same value.
|
* Asserts that two variables have the same value.
|
||||||
*
|
*
|
||||||
|
|||||||
26
tests/Features/Expect/toHaveProperties.php
Normal file
26
tests/Features/Expect/toHaveProperties.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
|
test('pass', function () {
|
||||||
|
$object = new stdClass();
|
||||||
|
$object->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);
|
||||||
Reference in New Issue
Block a user