mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
feat(expect): adds toHaveProperty
This commit is contained in:
@ -120,31 +120,26 @@
|
||||
PASS Tests\Expect\toContain
|
||||
✓ passes
|
||||
✓ failures
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Expect\toCount
|
||||
✓ pass
|
||||
✓ failures
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Expect\toEqual
|
||||
✓ pass
|
||||
✓ failures
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Expect\toEqualCanonicalizing
|
||||
✓ pass
|
||||
✓ failures
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Expect\toEqualIgnoringCase
|
||||
✓ pass
|
||||
✓ failures
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Expect\toEqualWithDelta
|
||||
✓ pass
|
||||
✓ failures
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Expect\toHaveCount
|
||||
✓ pass
|
||||
✓ failures
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Expect\toHaveProperty
|
||||
✓ pass
|
||||
✓ failures
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Features\AfterAll
|
||||
@ -312,5 +307,5 @@
|
||||
WARN Tests\Visual\Success
|
||||
- visual snapshot of test suite on success
|
||||
|
||||
Tests: 2 risked, 6 skipped, 181 passed
|
||||
Time: 5.72s
|
||||
Tests: 2 risked, 6 skipped, 178 passed
|
||||
Time: 5.70s
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect('hello')->toEqualIgnoringCase('HELLO');
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect('hello')->toEqualIgnoringCase('BAR');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures', function () {
|
||||
expect('HELLO')->not->toEqualIgnoringCase('HelLo');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
18
tests/Expect/toHaveProperty.php
Normal file
18
tests/Expect/toHaveProperty.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
$obj = new stdClass();
|
||||
$obj->foo = 'bar';
|
||||
|
||||
test('pass', function () use ($obj) {
|
||||
expect($obj)->toHaveProperty('foo');
|
||||
});
|
||||
|
||||
test('failures', function () use ($obj) {
|
||||
expect($obj)->toHaveProperty('bar');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures', function () use ($obj) {
|
||||
expect($obj)->not->toHaveProperty('foo');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
@ -11,10 +11,10 @@ afterEach(function () use ($state) {
|
||||
});
|
||||
|
||||
it('does not get executed before the test', function () {
|
||||
expect(property_exists($this->state, 'bar'))->toBeFalse();
|
||||
expect($this->state)->not->toHaveProperty('bar');
|
||||
});
|
||||
|
||||
it('gets executed after the test', function () {
|
||||
expect(property_exists($this->state, 'bar'))->toBeTrue();
|
||||
expect($this->state)->toHaveProperty('bar');
|
||||
expect($this->state->bar)->toBe(2);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user