Merge branch 'master' into performs_no_expectations

This commit is contained in:
Luke Downing
2022-02-10 17:26:15 +00:00
9 changed files with 111 additions and 18 deletions

View File

@ -74,8 +74,37 @@ it('works with higher order tests')
->name()->toEqual('Has Methods')
->books()->each->toBeArray;
it('can use the scoped method to lock into the given level for expectations', function () {
expect(new HasMethods())
->attributes()->scoped(fn ($attributes) => $attributes
->name->toBe('Has Methods')
->quantity->toBe(20)
)
->name()->toBeString()->toBe('Has Methods')
->newInstance()->newInstance()->scoped(fn ($instance) => $instance
->name()->toBe('Has Methods')
->quantity()->toBe(20)
->attributes()->scoped(fn ($attributes) => $attributes
->name->toBe('Has Methods')
->quantity->toBe(20)
)
);
});
it('works consistently with the json expectation method', function () {
expect(new HasMethods())
->jsonString()->json()->id->toBe(1)
->jsonString()->json()->name->toBe('Has Methods')->toBeString()
->jsonString()->json()->quantity->toBe(20)->toBeInt();
});
class HasMethods
{
public function jsonString(): string
{
return '{ "id": 1, "name": "Has Methods", "quantity": 20 }';
}
public function name()
{
return 'Has Methods';

View File

@ -48,6 +48,15 @@ it('can start a new higher order expectation using the and syntax in higher orde
->toBeArray()
->foo->toEqual('bar');
it('can start a new higher order expectation using the and syntax without nesting expectations', function () {
expect(new HasMethodsAndProperties())
->toBeInstanceOf(HasMethodsAndProperties::class)
->meta
->sequence(
function ($value, $key) { $value->toBeArray()->and($key)->toBe('foo'); },
);
});
class HasMethodsAndProperties
{
public $name = 'Has Methods and Properties';

View File

@ -87,3 +87,11 @@ it('accepts callables', function () {
expect(static::getCount())->toBe(12);
});
it('passes the key of the current item to callables', function () {
expect([1, 2, 3])->each(function ($number, $key) {
expect($key)->toBeInt();
});
expect(static::getCount())->toBe(3);
});

View File

@ -21,9 +21,9 @@ it('resolves expect callables correctly')
test('does not treat method names as callables')
->expect('it')->toBeString();
it('can tap into the test')
it('can defer a method until after test setup')
->expect('foo')->toBeString()
->tap(function () { expect($this)->toBeInstanceOf(TestCase::class); })
->defer(function () { expect($this)->toBeInstanceOf(TestCase::class); })
->toBe('foo')
->and('hello world')->toBeString();
@ -32,15 +32,15 @@ it('can pass datasets into the expect callables')
->expect(function (...$numbers) { return $numbers; })->toBe([1, 2, 3])
->and(function (...$numbers) { return $numbers; })->toBe([1, 2, 3]);
it('can pass datasets into the tap callable')
it('can pass datasets into the defer callable')
->with([[1, 2, 3]])
->tap(function (...$numbers) { expect($numbers)->toBe([1, 2, 3]); });
->defer(function (...$numbers) { expect($numbers)->toBe([1, 2, 3]); });
it('can pass shared datasets into callables')
->with('numbers.closure.wrapped')
->expect(function ($value) { return $value; })
->and(function ($value) { return $value; })
->tap(function ($value) { expect($value)->toBeInt(); })
->defer(function ($value) { expect($value)->toBeInt(); })
->toBeInt();
afterEach()->assertTrue(true);