Merge branch 'master' into fix-missing-dataset-errors

This commit is contained in:
Jordan Brauer
2021-06-21 19:50:15 -05:00
committed by GitHub
16 changed files with 213 additions and 64 deletions

View File

@ -111,9 +111,11 @@
✓ it works inside of each
✓ it works with sequence
✓ it can compose complex expectations
✓ it can handle nested method calls
PASS Tests\Features\Expect\HigherOrder\methodsAndProperties
✓ it can access methods and properties
✓ it can handle nested methods and properties
PASS Tests\Features\Expect\HigherOrder\properties
✓ it allows properties to be accessed from the value
@ -124,6 +126,7 @@
✓ it works with sequence
✓ it can compose complex expectations
✓ it works with objects
✓ it works with nested properties
PASS Tests\Features\Expect\each
✓ an exception is thrown if the the type is not iterable
@ -140,6 +143,10 @@
✓ it macros true is true with argument
✓ it macros false is not true with argument
PASS Tests\Features\Expect\json
✓ it properly parses json string
✓ fails with broken json string
PASS Tests\Features\Expect\not
✓ not property calls
@ -152,6 +159,8 @@
✓ loops back to the start if it runs out of sequence items
✓ it works if the number of items in the iterable is smaller than the number of expectations
✓ it works with associative arrays
✓ it can be passed non-callable values
✓ it can be passed a mixture of value types
PASS Tests\Features\Expect\toBe
✓ strict comparisons
@ -570,5 +579,5 @@
✓ it is a test
✓ it uses correct parent class
Tests: 4 incompleted, 7 skipped, 356 passed
Tests: 4 incompleted, 7 skipped, 363 passed

View File

@ -59,6 +59,14 @@ it('can compose complex expectations', function () {
);
});
it('can handle nested method calls', function () {
expect(new HasMethods())
->newInstance()->newInstance()->name()->toEqual('Has Methods')->toBeString()
->newInstance()->name()->toEqual('Has Methods')->not->toBeInt
->name()->toEqual('Has Methods')
->books()->each->toBeArray();
});
class HasMethods
{
public function name()
@ -97,4 +105,9 @@ class HasMethods
],
];
}
public function newInstance()
{
return new static();
}
}

View File

@ -14,10 +14,20 @@ it('can access methods and properties', function () {
);
});
it('can handle nested methods and properties', function () {
expect(new HasMethodsAndProperties())
->meta->foo->bar->toBeString()->toEqual('baz')->not->toBeInt
->newInstance()->meta->foo->toBeArray()
->newInstance()->multiply(2, 2)->toEqual(4)->not->toEqual(5)
->newInstance()->books()->toBeArray();
});
class HasMethodsAndProperties
{
public $name = 'Has Methods and Properties';
public $meta = ['foo' => ['bar' => 'baz']];
public $posts = [
[
'is_published' => true,
@ -47,4 +57,9 @@ class HasMethodsAndProperties
{
return $x * $y;
}
public function newInstance()
{
return new static();
}
}

View File

@ -58,6 +58,12 @@ it('works with objects', function () {
);
});
it('works with nested properties', function () {
expect(new HasProperties())
->nested->foo->bar->toBeString()->toEqual('baz')
->posts->toBeArray()->toHaveCount(2);
});
class HasProperties
{
public $name = 'foo';
@ -72,4 +78,8 @@ class HasProperties
'title' => 'Bar',
],
];
public $nested = [
'foo' => ['bar' => 'baz'],
];
}

View File

@ -0,0 +1,14 @@
<?php
use PHPUnit\Framework\ExpectationFailedException;
test('it properly parses json string', function () {
expect('{"name":"Nuno"}')
->json()
->name
->toBe('Nuno');
});
test('fails with broken json string', function () {
expect('{":"Nuno"}')->json();
})->throws(ExpectationFailedException::class);

View File

@ -44,3 +44,19 @@ test('it works with associative arrays', function () {
function ($expectation, $key) { $expectation->toEqual('boom'); $key->toEqual('baz'); },
);
});
test('it can be passed non-callable values', function () {
expect(['foo', 'bar', 'baz'])->sequence('foo', 'bar', 'baz');
expect(static::getCount())->toBe(3);
});
test('it can be passed a mixture of value types', function () {
expect(['foo', 'bar', 'baz'])->sequence(
'foo',
function ($expectation) { $expectation->toEqual('bar')->toBeString(); },
'baz'
);
expect(static::getCount())->toBe(4);
});