mirror of
https://github.com/pestphp/pest.git
synced 2026-03-12 02:37:22 +01:00
Merge pull request #760 from lucasgiovanny/toHaveProperties
Add possibility to check property name and value with toHaveProperties
This commit is contained in:
@ -296,8 +296,8 @@ final class Expectation
|
|||||||
*/
|
*/
|
||||||
public function toHaveProperties(iterable $names, string $message = ''): self
|
public function toHaveProperties(iterable $names, string $message = ''): self
|
||||||
{
|
{
|
||||||
foreach ($names as $name) {
|
foreach ($names as $name => $value) {
|
||||||
$this->toHaveProperty($name, message: $message);
|
is_int($name) ? $this->toHaveProperty($value, message: $message) : $this->toHaveProperty($name, $value, $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|||||||
@ -1016,4 +1016,4 @@
|
|||||||
PASS Tests\Visual\Version
|
PASS Tests\Visual\Version
|
||||||
✓ visual snapshot of help command output
|
✓ visual snapshot of help command output
|
||||||
|
|
||||||
Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 14 skipped, 709 passed (1711 assertions)
|
Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 14 skipped, 709 passed (1717 assertions)
|
||||||
@ -4,30 +4,49 @@ use PHPUnit\Framework\ExpectationFailedException;
|
|||||||
|
|
||||||
test('pass', function () {
|
test('pass', function () {
|
||||||
$object = new stdClass();
|
$object = new stdClass();
|
||||||
$object->name = 'Jhon';
|
$object->name = 'John';
|
||||||
$object->age = 21;
|
$object->age = 21;
|
||||||
|
|
||||||
expect($object)->toHaveProperties(['name', 'age']);
|
expect($object)
|
||||||
|
->toHaveProperties(['name', 'age'])
|
||||||
|
->toHaveProperties([
|
||||||
|
'name' => 'John',
|
||||||
|
'age' => 21,
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('failures', function () {
|
test('failures', function () {
|
||||||
$object = new stdClass();
|
$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);
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|
||||||
test('failures with custom message', function () {
|
test('failures with custom message', function () {
|
||||||
$object = new stdClass();
|
$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!');
|
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||||
|
|
||||||
test('not failures', function () {
|
test('not failures', function () {
|
||||||
$object = new stdClass();
|
$object = new stdClass();
|
||||||
$object->name = 'Jhon';
|
$object->name = 'John';
|
||||||
$object->age = 21;
|
$object->age = 21;
|
||||||
|
|
||||||
expect($object)->not->toHaveProperties(['name', 'age']);
|
expect($object)->not->toHaveProperties(['name', 'age'])
|
||||||
|
->not->toHaveProperties([
|
||||||
|
'name' => 'John',
|
||||||
|
'age' => 21,
|
||||||
|
]);
|
||||||
})->throws(ExpectationFailedException::class);
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|||||||
@ -18,7 +18,7 @@ $run = function () {
|
|||||||
|
|
||||||
test('parallel', function () use ($run) {
|
test('parallel', function () use ($run) {
|
||||||
expect($run('--exclude-group=integration'))
|
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');
|
->toContain('Parallel: 3 processes');
|
||||||
})->skipOnWindows();
|
})->skipOnWindows();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user