Files
pest/tests/Features/Expect/toHaveProperty.php
2022-09-19 10:37:37 +02:00

27 lines
807 B
PHP

<?php
use PHPUnit\Framework\ExpectationFailedException;
$obj = new stdClass();
$obj->foo = 'bar';
$obj->fooNull = null;
test('pass', function () use ($obj) {
expect($obj)->toHaveProperty('foo');
expect($obj)->toHaveProperty('foo', 'bar');
expect($obj)->toHaveProperty('fooNull');
expect($obj)->toHaveProperty('fooNull', null);
});
test('failures', function () use ($obj) {
expect($obj)->toHaveProperty('bar');
})->throws(ExpectationFailedException::class);
test('failures with message', function () use ($obj) {
expect($obj)->toHaveProperty(name: 'bar', failureMessage: 'oh no!');
})->throws(ExpectationFailedException::class, 'oh no!');
test('not failures', function () use ($obj) {
expect($obj)->not->toHaveProperty('foo');
})->throws(ExpectationFailedException::class);