Uses Collision ^7.0

This commit is contained in:
Nuno Maduro
2022-09-15 01:07:15 +01:00
parent eab944023c
commit 3ff95faaaa
47 changed files with 646 additions and 308 deletions

View File

@ -9,17 +9,17 @@ beforeEach(function () {
it('pass', function () {
expect('baz')
->match('foo', [
'bar' => function ($value) {
$this->matched = 'bar';
'bar' => function ($value) {
$this->matched = 'bar';
return $value->toEqual('bar');
},
'foo' => function ($value) {
$this->matched = 'baz';
return $value->toEqual('bar');
},
'foo' => function ($value) {
$this->matched = 'baz';
return $value->toEqual('baz');
},
]
return $value->toEqual('baz');
},
]
)
->toEqual($this->matched);
@ -29,30 +29,30 @@ it('pass', function () {
it('failures', function () {
expect(true)
->match('foo', [
'bar' => function ($value) {
return $value->toBeTrue();
},
'foo' => function ($value) {
return $value->toBeFalse();
},
]
'bar' => function ($value) {
return $value->toBeTrue();
},
'foo' => function ($value) {
return $value->toBeFalse();
},
]
);
})->throws(ExpectationFailedException::class, 'true is false');
it('runs with truthy', function () {
expect('foo')
->match(1, [
'bar' => function ($value) {
$this->matched = 'bar';
'bar' => function ($value) {
$this->matched = 'bar';
return $value->toEqual('bar');
},
true => function ($value) {
$this->matched = 'foo';
return $value->toEqual('bar');
},
true => function ($value) {
$this->matched = 'foo';
return $value->toEqual('foo');
},
]
return $value->toEqual('foo');
},
]
)
->toEqual($this->matched);
@ -62,17 +62,17 @@ it('runs with truthy', function () {
it('runs with falsy', function () {
expect('foo')
->match(false, [
'bar' => function ($value) {
$this->matched = 'bar';
'bar' => function ($value) {
$this->matched = 'bar';
return $value->toEqual('bar');
},
false => function ($value) {
$this->matched = 'foo';
return $value->toEqual('bar');
},
false => function ($value) {
$this->matched = 'foo';
return $value->toEqual('foo');
},
]
return $value->toEqual('foo');
},
]
)
->toEqual($this->matched);
@ -82,7 +82,9 @@ it('runs with falsy', function () {
it('runs with truthy closure condition', function () {
expect('foo')
->match(
function () { return '1'; }, [
function () {
return '1';
}, [
'bar' => function ($value) {
$this->matched = 'bar';
@ -103,7 +105,9 @@ it('runs with truthy closure condition', function () {
it('runs with falsy closure condition', function () {
expect('foo')
->match(
function () { return '0'; }, [
function () {
return '0';
}, [
'bar' => function ($value) {
$this->matched = 'bar';
@ -124,9 +128,9 @@ it('runs with falsy closure condition', function () {
it('can be passed non-callable values', function () {
expect('foo')
->match('pest', [
'bar' => 'foo',
'pest' => 'baz',
]
'bar' => 'foo',
'pest' => 'baz',
]
);
})->throws(ExpectationFailedException::class, 'two strings are equal');
@ -137,7 +141,9 @@ it('fails with unhandled match', function () {
it('can be used in higher order tests')
->expect(true)
->match(
function () { return true; }, [
function () {
return true;
}, [
false => function ($value) {
return $value->toBeFalse();
},