mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
Merge pull request #391 from gabbanaesteban/master
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 iterable<array-key, string> $names
|
||||||
|
*/
|
||||||
|
public function toHaveProperties(iterable $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.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -433,6 +433,11 @@
|
|||||||
✓ it fails with (true)
|
✓ it fails with (true)
|
||||||
✓ it fails with (null)
|
✓ it fails with (null)
|
||||||
|
|
||||||
|
PASS Tests\Features\Expect\toHaveProperties
|
||||||
|
✓ pass
|
||||||
|
✓ failures
|
||||||
|
✓ not failures
|
||||||
|
|
||||||
PASS Tests\Features\Expect\toHaveProperty
|
PASS Tests\Features\Expect\toHaveProperty
|
||||||
✓ pass
|
✓ pass
|
||||||
✓ failures
|
✓ failures
|
||||||
@ -676,5 +681,5 @@
|
|||||||
✓ it is a test
|
✓ it is a test
|
||||||
✓ it uses correct parent class
|
✓ it uses correct parent class
|
||||||
|
|
||||||
Tests: 4 incompleted, 9 skipped, 444 passed
|
Tests: 4 incompleted, 9 skipped, 447 passed
|
||||||
|
|
||||||
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