mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
update toHaveProperties
This commit is contained in:
@ -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);
|
||||
|
||||
Reference in New Issue
Block a user