foo = 'bar'; $obj->fooNull = null; test('pass', function () use ($obj): void { expect($obj)->toHaveProperty('foo') ->toHaveProperty('foo', 'bar') ->toHaveProperty('fooNull') ->toHaveProperty('fooNull', null); }); test('failures', function () use ($obj): void { expect($obj)->toHaveProperty('bar'); })->throws(ExpectationFailedException::class); test('failures with message', function () use ($obj): void { expect($obj)->toHaveProperty(name: 'bar', message: 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); test('failures with message and Any matcher', function () use ($obj): void { expect($obj)->toHaveProperty('bar', expect()->any(), 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); test('not failures', function () use ($obj): void { expect($obj)->not->toHaveProperty('foo'); })->throws(ExpectationFailedException::class);