mirror of
https://github.com/pestphp/pest.git
synced 2026-07-24 18:40:03 +02:00
fix: package lock fingerprint
This commit is contained in:
@@ -1,73 +1,72 @@
|
||||
<?php
|
||||
|
||||
it('can access methods', function () {
|
||||
it('can access methods', function (): void {
|
||||
expect(new HasMethods)
|
||||
->name()->toBeString()->toEqual('Has Methods');
|
||||
});
|
||||
|
||||
it('can access multiple methods', function () {
|
||||
it('can access multiple methods', function (): void {
|
||||
expect(new HasMethods)
|
||||
->name()->toBeString()->toEqual('Has Methods')
|
||||
->quantity()->toBeInt()->toEqual(20);
|
||||
});
|
||||
|
||||
it('works with not', function () {
|
||||
it('works with not', function (): void {
|
||||
expect(new HasMethods)
|
||||
->name()->not->toEqual('world')->toEqual('Has Methods')
|
||||
->quantity()->toEqual(20)->not()->toEqual('bar')->not->toBeNull;
|
||||
});
|
||||
|
||||
it('can accept arguments', function () {
|
||||
it('can accept arguments', function (): void {
|
||||
expect(new HasMethods)
|
||||
->multiply(5, 4)->toBeInt->toEqual(20);
|
||||
});
|
||||
|
||||
it('works with each', function () {
|
||||
it('works with each', function (): void {
|
||||
expect(new HasMethods)
|
||||
->attributes()->toBeArray->each->not()->toBeNull
|
||||
->attributes()->each(function ($attribute) {
|
||||
->attributes()->each(function ($attribute): void {
|
||||
$attribute->not->toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
it('works inside of each', function () {
|
||||
it('works inside of each', function (): void {
|
||||
expect(new HasMethods)
|
||||
->books()->each(function ($book) {
|
||||
->books()->each(function ($book): void {
|
||||
$book->title->not->toBeNull->cost->toBeGreaterThan(19);
|
||||
});
|
||||
});
|
||||
|
||||
it('works with sequence', function () {
|
||||
it('works with sequence', function (): void {
|
||||
expect(new HasMethods)
|
||||
->books()->sequence(
|
||||
function ($book) {
|
||||
function ($book): void {
|
||||
$book->title->toEqual('Foo')->cost->toEqual(20);
|
||||
},
|
||||
function ($book) {
|
||||
function ($book): void {
|
||||
$book->title->toEqual('Bar')->cost->toEqual(30);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it('can compose complex expectations', function () {
|
||||
it('can compose complex expectations', function (): void {
|
||||
expect(new HasMethods)
|
||||
->toBeObject()
|
||||
->name()->toEqual('Has Methods')->not()->toEqual('bar')
|
||||
->quantity()->not->toEqual('world')->toEqual(20)->toBeInt
|
||||
->multiply(3, 4)->not->toBeString->toEqual(12)
|
||||
->attributes()->toBeArray()
|
||||
->books()->toBeArray->each->not->toBeEmpty
|
||||
->books()->sequence(
|
||||
function ($book) {
|
||||
function ($book): void {
|
||||
$book->title->toEqual('Foo')->cost->toEqual(20);
|
||||
},
|
||||
function ($book) {
|
||||
function ($book): void {
|
||||
$book->title->toEqual('Bar')->cost->toEqual(30);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it('can handle nested method calls', function () {
|
||||
it('can handle nested method calls', function (): void {
|
||||
expect(new HasMethods)
|
||||
->newInstance()->newInstance()->name()->toEqual('Has Methods')->toBeString()
|
||||
->newInstance()->name()->toEqual('Has Methods')->not->toBeInt
|
||||
@@ -82,7 +81,7 @@ 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 () {
|
||||
it('can use the scoped method to lock into the given level for expectations', function (): void {
|
||||
expect(new HasMethods)
|
||||
->attributes()->scoped(fn ($attributes) => $attributes
|
||||
->name->toBe('Has Methods')
|
||||
@@ -99,7 +98,7 @@ it('can use the scoped method to lock into the given level for expectations', fu
|
||||
);
|
||||
});
|
||||
|
||||
it('works consistently with the json expectation method', function () {
|
||||
it('works consistently with the json expectation method', function (): void {
|
||||
expect(new HasMethods)
|
||||
->jsonString()->json()->id->toBe(1)
|
||||
->jsonString()->json()->name->toBe('Has Methods')->toBeString()
|
||||
@@ -113,22 +112,22 @@ class HasMethods
|
||||
return '{ "id": 1, "name": "Has Methods", "quantity": 20 }';
|
||||
}
|
||||
|
||||
public function name()
|
||||
public function name(): string
|
||||
{
|
||||
return 'Has Methods';
|
||||
}
|
||||
|
||||
public function quantity()
|
||||
public function quantity(): int
|
||||
{
|
||||
return 20;
|
||||
}
|
||||
|
||||
public function multiply($x, $y)
|
||||
public function multiply($x, $y): int|float
|
||||
{
|
||||
return $x * $y;
|
||||
}
|
||||
|
||||
public function attributes()
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'name' => $this->name(),
|
||||
@@ -136,7 +135,7 @@ class HasMethods
|
||||
];
|
||||
}
|
||||
|
||||
public function books()
|
||||
public function books(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
@@ -150,7 +149,7 @@ class HasMethods
|
||||
];
|
||||
}
|
||||
|
||||
public function newInstance()
|
||||
public function newInstance(): static
|
||||
{
|
||||
return new static;
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
<?php
|
||||
|
||||
it('can access methods and properties', function () {
|
||||
it('can access methods and properties', function (): void {
|
||||
expect(new HasMethodsAndProperties)
|
||||
->name->toEqual('Has Methods and Properties')->not()->toEqual('bar')
|
||||
->multiply(3, 4)->not->toBeString->toEqual(12)
|
||||
->posts->each(function ($post) {
|
||||
->posts->each(function ($post): void {
|
||||
$post->is_published->toBeTrue;
|
||||
})->books()->toBeArray()
|
||||
->posts->toBeArray->each->not->toBeEmpty
|
||||
->books()->sequence(
|
||||
function ($book) {
|
||||
function ($book): void {
|
||||
$book->title->toEqual('Foo')->cost->toEqual(20);
|
||||
},
|
||||
function ($book) {
|
||||
function ($book): void {
|
||||
$book->title->toEqual('Bar')->cost->toEqual(30);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it('can handle nested methods and properties', function () {
|
||||
it('can handle nested methods and properties', function (): void {
|
||||
expect(new HasMethodsAndProperties)
|
||||
->meta->foo->bar->toBeString()->toEqual('baz')->not->toBeInt
|
||||
->newInstance()->meta->foo->toBeArray()
|
||||
@@ -33,15 +33,14 @@ it('works with higher order tests')
|
||||
->newInstance()->multiply(2, 2)->toEqual(4)->not->toEqual(5)
|
||||
->newInstance()->books()->toBeArray();
|
||||
|
||||
it('can start a new higher order expectation using the and syntax', function () {
|
||||
it('can start a new higher order expectation using the and syntax', function (): void {
|
||||
expect(new HasMethodsAndProperties)
|
||||
->toBeInstanceOf(HasMethodsAndProperties::class)
|
||||
->meta->toBeArray
|
||||
->and(['foo' => 'bar'])
|
||||
->toBeArray()
|
||||
->foo->toEqual('bar');
|
||||
|
||||
expect(static::getCount())->toEqual(4);
|
||||
->foo->toEqual('bar')
|
||||
->and(static::getCount())->toEqual(4);
|
||||
});
|
||||
|
||||
it('can start a new higher order expectation using the and syntax in higher order tests')
|
||||
@@ -52,12 +51,12 @@ 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 () {
|
||||
it('can start a new higher order expectation using the and syntax without nesting expectations', function (): void {
|
||||
expect(new HasMethodsAndProperties)
|
||||
->toBeInstanceOf(HasMethodsAndProperties::class)
|
||||
->meta
|
||||
->sequence(
|
||||
function ($value, $key) {
|
||||
function ($value, $key): void {
|
||||
$value->toBeArray()->and($key)->toBe('foo');
|
||||
},
|
||||
);
|
||||
@@ -80,7 +79,7 @@ class HasMethodsAndProperties
|
||||
],
|
||||
];
|
||||
|
||||
public function books()
|
||||
public function books(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
@@ -94,12 +93,12 @@ class HasMethodsAndProperties
|
||||
];
|
||||
}
|
||||
|
||||
public function multiply($x, $y)
|
||||
public function multiply($x, $y): int|float
|
||||
{
|
||||
return $x * $y;
|
||||
}
|
||||
|
||||
public function newInstance()
|
||||
public function newInstance(): static
|
||||
{
|
||||
return new static;
|
||||
}
|
||||
|
||||
@@ -1,50 +1,50 @@
|
||||
<?php
|
||||
|
||||
it('allows properties to be accessed from the value', function () {
|
||||
it('allows properties to be accessed from the value', function (): void {
|
||||
expect(['foo' => 1])->foo->toBeInt()->toEqual(1);
|
||||
});
|
||||
|
||||
it('can access multiple properties from the value', function () {
|
||||
it('can access multiple properties from the value', function (): void {
|
||||
expect(['foo' => 'bar', 'hello' => 'world'])
|
||||
->foo->toBeString()->toEqual('bar')
|
||||
->hello->toBeString()->toEqual('world');
|
||||
});
|
||||
|
||||
it('works with not', function () {
|
||||
it('works with not', function (): void {
|
||||
expect(['foo' => 'bar', 'hello' => 'world'])
|
||||
->foo->not->not->toEqual('bar')
|
||||
->foo->not->toEqual('world')->toEqual('bar')
|
||||
->hello->toEqual('world')->not()->toEqual('bar')->not->toBeNull;
|
||||
});
|
||||
|
||||
it('works with each', function () {
|
||||
it('works with each', function (): void {
|
||||
expect(['numbers' => [1, 2, 3, 4], 'words' => ['hey', 'there']])
|
||||
->numbers->toEqual([1, 2, 3, 4])->each->toBeInt->toBeLessThan(5)
|
||||
->words->each(function ($word) {
|
||||
->words->each(function ($word): void {
|
||||
$word->toBeString()->not->toBeInt();
|
||||
});
|
||||
});
|
||||
|
||||
it('works inside of each', function () {
|
||||
it('works inside of each', function (): void {
|
||||
expect(['books' => [['title' => 'Foo', 'cost' => 20], ['title' => 'Bar', 'cost' => 30]]])
|
||||
->books->each(function ($book) {
|
||||
->books->each(function ($book): void {
|
||||
$book->title->not->toBeNull->cost->toBeGreaterThan(19);
|
||||
});
|
||||
});
|
||||
|
||||
it('works with sequence', function () {
|
||||
it('works with sequence', function (): void {
|
||||
expect(['books' => [['title' => 'Foo', 'cost' => 20], ['title' => 'Bar', 'cost' => 30]]])
|
||||
->books->sequence(
|
||||
function ($book) {
|
||||
function ($book): void {
|
||||
$book->title->toEqual('Foo')->cost->toEqual(20);
|
||||
},
|
||||
function ($book) {
|
||||
function ($book): void {
|
||||
$book->title->toEqual('Bar')->cost->toEqual(30);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it('can compose complex expectations', function () {
|
||||
it('can compose complex expectations', function (): void {
|
||||
expect(['foo' => 'bar', 'numbers' => [1, 2, 3, 4]])
|
||||
->toContain('bar')->toBeArray()
|
||||
->numbers->toEqual([1, 2, 3, 4])->not()->toEqual('bar')->each->toBeInt
|
||||
@@ -52,23 +52,23 @@ it('can compose complex expectations', function () {
|
||||
->numbers->toBeArray();
|
||||
});
|
||||
|
||||
it('works with objects', function () {
|
||||
it('works with objects', function (): void {
|
||||
expect(new HasProperties)
|
||||
->name->toEqual('foo')->not->toEqual('world')
|
||||
->posts->toHaveCount(2)->each(function ($post) {
|
||||
->posts->toHaveCount(2)->each(function ($post): void {
|
||||
$post->is_published->toBeTrue();
|
||||
})
|
||||
->posts->sequence(
|
||||
function ($post) {
|
||||
function ($post): void {
|
||||
$post->title->toEqual('Foo');
|
||||
},
|
||||
function ($post) {
|
||||
function ($post): void {
|
||||
$post->title->toEqual('Bar');
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it('works with nested properties', function () {
|
||||
it('works with nested properties', function (): void {
|
||||
expect(new HasProperties)
|
||||
->nested->foo->bar->toBeString()->toEqual('baz')
|
||||
->posts->toBeArray()->toHaveCount(2);
|
||||
|
||||
@@ -2,16 +2,15 @@
|
||||
|
||||
use Pest\Expectation;
|
||||
|
||||
test('an exception is thrown if the the type is not iterable', function () {
|
||||
test('an exception is thrown if the the type is not iterable', function (): void {
|
||||
expect('Foobar')->each()->toEqual('Foobar');
|
||||
})->throws(BadMethodCallException::class, 'Expectation value is not iterable.');
|
||||
|
||||
it('expects on each item', function () {
|
||||
it('expects on each item', function (): void {
|
||||
expect([1, 1, 1])
|
||||
->each()
|
||||
->toEqual(1);
|
||||
|
||||
expect(static::getCount())->toBe(3); // + 1 assertion
|
||||
->toEqual(1)
|
||||
->and(static::getCount())->toBe(3); // + 1 assertion
|
||||
|
||||
expect([1, 1, 1])
|
||||
->each
|
||||
@@ -20,13 +19,12 @@ it('expects on each item', function () {
|
||||
expect(static::getCount())->toBe(7);
|
||||
});
|
||||
|
||||
it('chains expectations on each item', function () {
|
||||
it('chains expectations on each item', function (): void {
|
||||
expect([1, 1, 1])
|
||||
->each()
|
||||
->toBeInt()
|
||||
->toEqual(1);
|
||||
|
||||
expect(static::getCount())->toBe(6); // + 1 assertion
|
||||
->toEqual(1)
|
||||
->and(static::getCount())->toBe(6); // + 1 assertion
|
||||
|
||||
expect([2, 2, 2])
|
||||
->each
|
||||
@@ -36,13 +34,12 @@ it('chains expectations on each item', function () {
|
||||
expect(static::getCount())->toBe(13);
|
||||
});
|
||||
|
||||
test('opposite expectations on each item', function () {
|
||||
test('opposite expectations on each item', function (): void {
|
||||
expect([1, 2, 3])
|
||||
->each()
|
||||
->not()
|
||||
->toEqual(4);
|
||||
|
||||
expect(static::getCount())->toBe(3);
|
||||
->toEqual(4)
|
||||
->and(static::getCount())->toBe(3);
|
||||
|
||||
expect([1, 2, 3])
|
||||
->each()
|
||||
@@ -51,17 +48,16 @@ test('opposite expectations on each item', function () {
|
||||
expect(static::getCount())->toBe(7);
|
||||
});
|
||||
|
||||
test('chained opposite and non-opposite expectations', function () {
|
||||
test('chained opposite and non-opposite expectations', function (): void {
|
||||
expect([1, 2, 3])
|
||||
->each()
|
||||
->not()
|
||||
->toEqual(4)
|
||||
->toBeInt();
|
||||
|
||||
expect(static::getCount())->toBe(6);
|
||||
->toBeInt()
|
||||
->and(static::getCount())->toBe(6);
|
||||
});
|
||||
|
||||
it('can add expectations via "and"', function () {
|
||||
it('can add expectations via "and"', function (): void {
|
||||
expect([1, 2, 3])
|
||||
->each()
|
||||
->toBeInt // + 3
|
||||
@@ -78,20 +74,18 @@ it('can add expectations via "and"', function () {
|
||||
expect(static::getCount())->toBe(14);
|
||||
});
|
||||
|
||||
it('accepts callables', function () {
|
||||
expect([1, 2, 3])->each(function ($number) {
|
||||
expect($number)->toBeInstanceOf(Expectation::class);
|
||||
expect($number->value)->toBeInt();
|
||||
it('accepts callables', function (): void {
|
||||
expect([1, 2, 3])->each(function ($number): void {
|
||||
expect($number)->toBeInstanceOf(Expectation::class)
|
||||
->and($number->value)->toBeInt();
|
||||
$number->toBeInt->not->toBeString;
|
||||
});
|
||||
|
||||
expect(static::getCount())->toBe(12);
|
||||
})
|
||||
->and(static::getCount())->toBe(12);
|
||||
});
|
||||
|
||||
it('passes the key of the current item to callables', function () {
|
||||
expect([1, 2, 3])->each(function ($number, $key) {
|
||||
it('passes the key of the current item to callables', function (): void {
|
||||
expect([1, 2, 3])->each(function ($number, $key): void {
|
||||
expect($key)->toBeInt();
|
||||
});
|
||||
|
||||
expect(static::getCount())->toBe(3);
|
||||
})
|
||||
->and(static::getCount())->toBe(3);
|
||||
});
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
<?php
|
||||
|
||||
expect()->extend('toBeAMacroExpectation', function () {
|
||||
expect()->extend('toBeAMacroExpectation', function (): object {
|
||||
$this->toBeTrue();
|
||||
|
||||
return $this;
|
||||
});
|
||||
|
||||
expect()->extend('toBeAMacroExpectationWithArguments', function (bool $value) {
|
||||
expect()->extend('toBeAMacroExpectationWithArguments', function (bool $value): object {
|
||||
$this->toBe($value);
|
||||
|
||||
return $this;
|
||||
});
|
||||
|
||||
it('macros true is true', function () {
|
||||
it('macros true is true', function (): void {
|
||||
expect(true)->toBeAMacroExpectation();
|
||||
});
|
||||
|
||||
it('macros false is not true', function () {
|
||||
it('macros false is not true', function (): void {
|
||||
expect(false)->not->toBeAMacroExpectation();
|
||||
});
|
||||
|
||||
it('macros true is true with argument', function () {
|
||||
it('macros true is true with argument', function (): void {
|
||||
expect(true)->toBeAMacroExpectationWithArguments(true);
|
||||
});
|
||||
|
||||
it('macros false is not true with argument', function () {
|
||||
it('macros false is not true with argument', function (): void {
|
||||
expect(false)->not->toBeAMacroExpectationWithArguments(true);
|
||||
});
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('it properly parses json string', function () {
|
||||
test('it properly parses json string', function (): void {
|
||||
expect('{"name":"Nuno"}')
|
||||
->json()
|
||||
->name
|
||||
->toBe('Nuno');
|
||||
});
|
||||
|
||||
test('fails with broken json string', function () {
|
||||
test('fails with broken json string', function (): void {
|
||||
expect('{":"Nuno"}')->json();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
beforeEach(function () {
|
||||
beforeEach(function (): void {
|
||||
$this->matched = null;
|
||||
});
|
||||
|
||||
it('pass', function () {
|
||||
it('pass', function (): void {
|
||||
expect('baz')
|
||||
->match('foo', [
|
||||
'bar' => function ($value) {
|
||||
@@ -21,25 +21,20 @@ it('pass', function () {
|
||||
},
|
||||
]
|
||||
)
|
||||
->toEqual($this->matched);
|
||||
|
||||
expect(static::getCount())->toBe(2);
|
||||
->toEqual($this->matched)
|
||||
->and(static::getCount())->toBe(2);
|
||||
});
|
||||
|
||||
it('failures', function () {
|
||||
it('failures', function (): void {
|
||||
expect(true)
|
||||
->match('foo', [
|
||||
'bar' => function ($value) {
|
||||
return $value->toBeTrue();
|
||||
},
|
||||
'foo' => function ($value) {
|
||||
return $value->toBeFalse();
|
||||
},
|
||||
'bar' => fn ($value) => $value->toBeTrue(),
|
||||
'foo' => fn ($value) => $value->toBeFalse(),
|
||||
]
|
||||
);
|
||||
})->throws(ExpectationFailedException::class, 'true is false');
|
||||
|
||||
it('runs with truthy', function () {
|
||||
it('runs with truthy', function (): void {
|
||||
expect('foo')
|
||||
->match(1, [
|
||||
'bar' => function ($value) {
|
||||
@@ -54,12 +49,11 @@ it('runs with truthy', function () {
|
||||
},
|
||||
]
|
||||
)
|
||||
->toEqual($this->matched);
|
||||
|
||||
expect(static::getCount())->toBe(2);
|
||||
->toEqual($this->matched)
|
||||
->and(static::getCount())->toBe(2);
|
||||
});
|
||||
|
||||
it('runs with falsy', function () {
|
||||
it('runs with falsy', function (): void {
|
||||
expect('foo')
|
||||
->match(false, [
|
||||
'bar' => function ($value) {
|
||||
@@ -74,17 +68,14 @@ it('runs with falsy', function () {
|
||||
},
|
||||
]
|
||||
)
|
||||
->toEqual($this->matched);
|
||||
|
||||
expect(static::getCount())->toBe(2);
|
||||
->toEqual($this->matched)
|
||||
->and(static::getCount())->toBe(2);
|
||||
});
|
||||
|
||||
it('runs with truthy closure condition', function () {
|
||||
it('runs with truthy closure condition', function (): void {
|
||||
expect('foo')
|
||||
->match(
|
||||
function () {
|
||||
return '1';
|
||||
}, [
|
||||
fn (): string => '1', [
|
||||
'bar' => function ($value) {
|
||||
$this->matched = 'bar';
|
||||
|
||||
@@ -97,17 +88,14 @@ it('runs with truthy closure condition', function () {
|
||||
},
|
||||
]
|
||||
)
|
||||
->toEqual($this->matched);
|
||||
|
||||
expect(static::getCount())->toBe(2);
|
||||
->toEqual($this->matched)
|
||||
->and(static::getCount())->toBe(2);
|
||||
});
|
||||
|
||||
it('runs with falsy closure condition', function () {
|
||||
it('runs with falsy closure condition', function (): void {
|
||||
expect('foo')
|
||||
->match(
|
||||
function () {
|
||||
return '0';
|
||||
}, [
|
||||
fn (): string => '0', [
|
||||
'bar' => function ($value) {
|
||||
$this->matched = 'bar';
|
||||
|
||||
@@ -120,12 +108,11 @@ it('runs with falsy closure condition', function () {
|
||||
},
|
||||
]
|
||||
)
|
||||
->toEqual($this->matched);
|
||||
|
||||
expect(static::getCount())->toBe(2);
|
||||
->toEqual($this->matched)
|
||||
->and(static::getCount())->toBe(2);
|
||||
});
|
||||
|
||||
it('can be passed non-callable values', function () {
|
||||
it('can be passed non-callable values', function (): void {
|
||||
expect('foo')
|
||||
->match('pest', [
|
||||
'bar' => 'foo',
|
||||
@@ -134,21 +121,15 @@ it('can be passed non-callable values', function () {
|
||||
);
|
||||
})->throws(ExpectationFailedException::class, 'two strings are equal');
|
||||
|
||||
it('fails with unhandled match', function () {
|
||||
it('fails with unhandled match', function (): void {
|
||||
expect('foo')->match('bar', []);
|
||||
})->throws(ExpectationFailedException::class, 'Unhandled match value.');
|
||||
|
||||
it('can be used in higher order tests')
|
||||
->expect(true)
|
||||
->match(
|
||||
function () {
|
||||
return true;
|
||||
}, [
|
||||
false => function ($value) {
|
||||
return $value->toBeFalse();
|
||||
},
|
||||
true => function ($value) {
|
||||
return $value->toBeTrue();
|
||||
},
|
||||
fn (): true => true, [
|
||||
false => fn ($value) => $value->toBeFalse(),
|
||||
true => fn ($value) => $value->toBeTrue(),
|
||||
]
|
||||
);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
test('not property calls', function () {
|
||||
test('not property calls', function (): void {
|
||||
expect(true)
|
||||
->toBeTrue()
|
||||
->not()->toBeFalse()
|
||||
|
||||
@@ -61,7 +61,7 @@ $state = new State;
|
||||
/*
|
||||
* Overrides toBe to assert two Characters are the same
|
||||
*/
|
||||
expect()->pipe('toBe', function ($next, $expected) use ($state) {
|
||||
expect()->pipe('toBe', function ($next, $expected) use ($state): void {
|
||||
$state->runCount['char']++;
|
||||
|
||||
if ($this->value instanceof Char) {
|
||||
@@ -81,7 +81,7 @@ expect()->pipe('toBe', function ($next, $expected) use ($state) {
|
||||
/*
|
||||
* Overrides toBe to assert two Number objects are the same
|
||||
*/
|
||||
expect()->intercept('toBe', Number::class, function ($expected) use ($state) {
|
||||
expect()->intercept('toBe', Number::class, function ($expected) use ($state): void {
|
||||
$state->runCount['number']++;
|
||||
$state->appliedCount['number']++;
|
||||
|
||||
@@ -92,7 +92,7 @@ expect()->intercept('toBe', Number::class, function ($expected) use ($state) {
|
||||
/*
|
||||
* Overrides toBe to assert all integers are allowed if value is a wildcard (*)
|
||||
*/
|
||||
expect()->intercept('toBe', fn ($value, $expected) => $value === '*' && is_numeric($expected), function ($expected) use ($state) {
|
||||
expect()->intercept('toBe', fn ($value, $expected) => $value === '*' && is_numeric($expected), function ($expected) use ($state): void {
|
||||
$state->runCount['wildcard']++;
|
||||
$state->appliedCount['wildcard']++;
|
||||
});
|
||||
@@ -100,7 +100,7 @@ expect()->intercept('toBe', fn ($value, $expected) => $value === '*' && is_numer
|
||||
/*
|
||||
* Overrides toBe to assert to Symbols are the same
|
||||
*/
|
||||
expect()->pipe('toBe', function ($next, $expected) use ($state) {
|
||||
expect()->pipe('toBe', function ($next, $expected) use ($state): void {
|
||||
$state->runCount['symbol']++;
|
||||
|
||||
if ($this->value instanceof Symbol) {
|
||||
@@ -117,7 +117,7 @@ expect()->pipe('toBe', function ($next, $expected) use ($state) {
|
||||
/*
|
||||
* Overrides toBe to allow ignoring case when checking strings
|
||||
*/
|
||||
expect()->intercept('toBe', fn ($value) => is_string($value), function ($expected, $ignoreCase = false) {
|
||||
expect()->intercept('toBe', fn ($value) => is_string($value), function ($expected, $ignoreCase = false): void {
|
||||
if ($ignoreCase) {
|
||||
assertEqualsIgnoringCase($expected, $this->value);
|
||||
} else {
|
||||
@@ -125,7 +125,7 @@ expect()->intercept('toBe', fn ($value) => is_string($value), function ($expecte
|
||||
}
|
||||
});
|
||||
|
||||
test('pipe is applied and can stop pipeline', function () use ($state) {
|
||||
test('pipe is applied and can stop pipeline', function () use ($state): void {
|
||||
$char = new Char('A');
|
||||
|
||||
$state->reset();
|
||||
@@ -146,7 +146,7 @@ test('pipe is applied and can stop pipeline', function () use ($state) {
|
||||
]);
|
||||
});
|
||||
|
||||
test('pipe is run and can let the pipeline keep going', function () use ($state) {
|
||||
test('pipe is run and can let the pipeline keep going', function () use ($state): void {
|
||||
$state->reset();
|
||||
|
||||
expect(3)->toBe(3)
|
||||
@@ -165,7 +165,7 @@ test('pipe is run and can let the pipeline keep going', function () use ($state)
|
||||
]);
|
||||
});
|
||||
|
||||
test('pipe works with negated expectation', function () use ($state) {
|
||||
test('pipe works with negated expectation', function () use ($state): void {
|
||||
$char = new Char('A');
|
||||
|
||||
$state->reset();
|
||||
@@ -186,7 +186,7 @@ test('pipe works with negated expectation', function () use ($state) {
|
||||
]);
|
||||
});
|
||||
|
||||
test('interceptor is applied', function () use ($state) {
|
||||
test('interceptor is applied', function () use ($state): void {
|
||||
$number = new Number(1);
|
||||
|
||||
$state->reset();
|
||||
@@ -197,7 +197,7 @@ test('interceptor is applied', function () use ($state) {
|
||||
->appliedCount->toHaveKey('number', 1);
|
||||
});
|
||||
|
||||
test('interceptor stops the pipeline', function () use ($state) {
|
||||
test('interceptor stops the pipeline', function () use ($state): void {
|
||||
$number = new Number(1);
|
||||
|
||||
$state->reset();
|
||||
@@ -218,7 +218,7 @@ test('interceptor stops the pipeline', function () use ($state) {
|
||||
]);
|
||||
});
|
||||
|
||||
test('interceptor is called only when filter is met', function () use ($state) {
|
||||
test('interceptor is called only when filter is met', function () use ($state): void {
|
||||
$state->reset();
|
||||
|
||||
expect(1)->toBe(1)
|
||||
@@ -227,7 +227,7 @@ test('interceptor is called only when filter is met', function () use ($state) {
|
||||
->appliedCount->toHaveKey('number', 0);
|
||||
});
|
||||
|
||||
test('interceptor can be filtered with a closure', function () use ($state) {
|
||||
test('interceptor can be filtered with a closure', function () use ($state): void {
|
||||
$state->reset();
|
||||
|
||||
expect('*')->toBe(1)
|
||||
@@ -236,7 +236,7 @@ test('interceptor can be filtered with a closure', function () use ($state) {
|
||||
->appliedCount->toHaveKey('wildcard', 1);
|
||||
});
|
||||
|
||||
test('interceptor can be filter the expected parameter as well', function () use ($state) {
|
||||
test('interceptor can be filter the expected parameter as well', function () use ($state): void {
|
||||
$state->reset();
|
||||
|
||||
expect('*')->toBe('*')
|
||||
@@ -245,13 +245,13 @@ test('interceptor can be filter the expected parameter as well', function () use
|
||||
->appliedCount->toHaveKey('wildcard', 0);
|
||||
});
|
||||
|
||||
test('interceptor works with negated expectation', function () {
|
||||
test('interceptor works with negated expectation', function (): void {
|
||||
$char = new Number(1);
|
||||
|
||||
expect($char)->not->toBe(new Char('B'));
|
||||
});
|
||||
|
||||
test('intercept can add new parameters to the expectation', function () {
|
||||
test('intercept can add new parameters to the expectation', function (): void {
|
||||
$ignoreCase = true;
|
||||
|
||||
expect('Foo')->toBe('foo', $ignoreCase);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
test('ray calls do not fail when ray is not installed', function () {
|
||||
expect(true)->ray()->toBe(true);
|
||||
declare(strict_types=1);
|
||||
|
||||
test('ray calls do not fail when ray is not installed', function (): void {
|
||||
expect(true)->toBeTrue();
|
||||
});
|
||||
|
||||
@@ -1,95 +1,91 @@
|
||||
<?php
|
||||
|
||||
test('an exception is thrown if the the type is not iterable', function () {
|
||||
test('an exception is thrown if the the type is not iterable', function (): void {
|
||||
expect('Foobar')->each->sequence();
|
||||
})->throws(BadMethodCallException::class, 'Expectation value is not iterable.');
|
||||
|
||||
test('an exception is thrown if there are no expectations', function () {
|
||||
test('an exception is thrown if there are no expectations', function (): void {
|
||||
expect(['Foobar'])->sequence();
|
||||
})->throws(InvalidArgumentException::class, 'No sequence expectations defined.');
|
||||
|
||||
test('allows for sequences of checks to be run on iterable data', function () {
|
||||
test('allows for sequences of checks to be run on iterable data', function (): void {
|
||||
expect([1, 2, 3])
|
||||
->sequence(
|
||||
function ($expectation) {
|
||||
function ($expectation): void {
|
||||
$expectation->toBeInt()->toEqual(1);
|
||||
},
|
||||
function ($expectation) {
|
||||
function ($expectation): void {
|
||||
$expectation->toBeInt()->toEqual(2);
|
||||
},
|
||||
function ($expectation) {
|
||||
function ($expectation): void {
|
||||
$expectation->toBeInt()->toEqual(3);
|
||||
},
|
||||
);
|
||||
|
||||
expect(static::getCount())->toBe(6);
|
||||
)
|
||||
->and(static::getCount())->toBe(6);
|
||||
});
|
||||
|
||||
test('loops back to the start if it runs out of sequence items', function () {
|
||||
test('loops back to the start if it runs out of sequence items', function (): void {
|
||||
expect([1, 2, 3, 1, 2, 3, 1, 2])
|
||||
->sequence(
|
||||
function ($expectation) {
|
||||
function ($expectation): void {
|
||||
$expectation->toBeInt()->toEqual(1);
|
||||
},
|
||||
function ($expectation) {
|
||||
function ($expectation): void {
|
||||
$expectation->toBeInt()->toEqual(2);
|
||||
},
|
||||
function ($expectation) {
|
||||
function ($expectation): void {
|
||||
$expectation->toBeInt()->toEqual(3);
|
||||
},
|
||||
);
|
||||
|
||||
expect(static::getCount())->toBe(16);
|
||||
)
|
||||
->and(static::getCount())->toBe(16);
|
||||
});
|
||||
|
||||
test('fails if the number of iterable items is less than the number of expectations', function () {
|
||||
test('fails if the number of iterable items is less than the number of expectations', function (): void {
|
||||
expect([1, 2])
|
||||
->sequence(
|
||||
function ($expectation) {
|
||||
function ($expectation): void {
|
||||
$expectation->toBeInt()->toEqual(1);
|
||||
},
|
||||
function ($expectation) {
|
||||
function ($expectation): void {
|
||||
$expectation->toBeInt()->toEqual(2);
|
||||
},
|
||||
function ($expectation) {
|
||||
function ($expectation): void {
|
||||
$expectation->toBeInt()->toEqual(3);
|
||||
},
|
||||
);
|
||||
})->throws(OutOfRangeException::class, 'Sequence expectations are more than the iterable items.');
|
||||
|
||||
test('it works with associative arrays', function () {
|
||||
test('it works with associative arrays', function (): void {
|
||||
expect(['foo' => 'bar', 'baz' => 'boom'])
|
||||
->sequence(
|
||||
function ($expectation, $key) {
|
||||
function ($expectation, $key): void {
|
||||
$expectation->toEqual('bar');
|
||||
$key->toEqual('foo');
|
||||
},
|
||||
function ($expectation, $key) {
|
||||
function ($expectation, $key): void {
|
||||
$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 non-callable values', function (): void {
|
||||
expect(['foo', 'bar', 'baz'])->sequence('foo', 'bar', 'baz')
|
||||
->and(static::getCount())->toBe(3);
|
||||
});
|
||||
|
||||
test('it can be passed a mixture of value types', function () {
|
||||
test('it can be passed a mixture of value types', function (): void {
|
||||
expect(['foo', 'bar', 'baz'])->sequence(
|
||||
'foo',
|
||||
function ($expectation) {
|
||||
function ($expectation): void {
|
||||
$expectation->toEqual('bar')->toBeString();
|
||||
},
|
||||
'baz'
|
||||
);
|
||||
|
||||
expect(static::getCount())->toBe(4);
|
||||
)
|
||||
->and(static::getCount())->toBe(4);
|
||||
});
|
||||
|
||||
test('it works with traversables', function () {
|
||||
test('it works with traversables', function (): void {
|
||||
$generator = (function () {
|
||||
yield 'one' => (fn () => yield from [1, 2, 3])();
|
||||
yield 'two' => (fn () => yield from [4, 5, 6])();
|
||||
|
||||
@@ -4,21 +4,21 @@ use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
expect(true)->toBeTrue()->and(false)->toBeFalse();
|
||||
|
||||
test('strict comparisons', function () {
|
||||
test('strict comparisons', function (): void {
|
||||
$nuno = new stdClass;
|
||||
$dries = new stdClass;
|
||||
|
||||
expect($nuno)->toBe($nuno)->not->toBe($dries);
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect(1)->toBe(2);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect(1)->toBe(2, 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect(1)->not->toBe(1);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect('abc')->toBeAlpha();
|
||||
expect('123')->not->toBeAlpha();
|
||||
test('pass', function (): void {
|
||||
expect('abc')->toBeAlpha()
|
||||
->and('123')->not->toBeAlpha();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('123')->toBeAlpha();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect('123')->toBeAlpha('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect('abc')->not->toBeAlpha();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect('abc123')->toBeAlphaNumeric();
|
||||
expect('-')->not->toBeAlphaNumeric();
|
||||
test('pass', function (): void {
|
||||
expect('abc123')->toBeAlphaNumeric()
|
||||
->and('-')->not->toBeAlphaNumeric();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('-')->toBeAlphaNumeric();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect('-')->toBeAlphaNumeric('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect('abc123')->not->toBeAlphaNumeric();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect([1, 2, 3])->toBeArray();
|
||||
expect('1, 2, 3')->not->toBeArray();
|
||||
test('pass', function (): void {
|
||||
expect([1, 2, 3])->toBeArray()
|
||||
->and('1, 2, 3')->not->toBeArray();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect(null)->toBeArray();
|
||||
test('failures', function (): void {
|
||||
expect()->toBeArray();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
expect(null)->toBeArray('oh no!');
|
||||
test('failures with custom message', function (): void {
|
||||
expect()->toBeArray('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect(['a', 'b', 'c'])->not->toBeArray();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,43 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('passes with int', function () {
|
||||
test('passes with int', function (): void {
|
||||
expect(2)->toBeBetween(1, 3);
|
||||
});
|
||||
|
||||
test('passes with float', function () {
|
||||
test('passes with float', function (): void {
|
||||
expect(1.5)->toBeBetween(1.25, 1.75);
|
||||
});
|
||||
|
||||
test('passes with float and int', function () {
|
||||
test('passes with float and int', function (): void {
|
||||
expect(1.5)->toBeBetween(1, 2);
|
||||
});
|
||||
|
||||
test('passes with DateTime', function () {
|
||||
test('passes with DateTime', function (): void {
|
||||
expect(new DateTime('2023-09-22'))->toBeBetween(new DateTime('2023-09-21'), new DateTime('2023-09-23'));
|
||||
});
|
||||
|
||||
test('failure with int', function () {
|
||||
test('failure with int', function (): void {
|
||||
expect(4)->toBeBetween(1, 3);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failure with float', function () {
|
||||
test('failure with float', function (): void {
|
||||
expect(2)->toBeBetween(1.5, 1.75);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failure with float and int', function () {
|
||||
test('failure with float and int', function (): void {
|
||||
expect(2.1)->toBeBetween(1, 2);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failure with DateTime', function () {
|
||||
test('failure with DateTime', function (): void {
|
||||
expect(new DateTime('2023-09-20'))->toBeBetween(new DateTime('2023-09-21'), new DateTime('2023-09-23'));
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect(4)->toBeBetween(1, 3, 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect(2)->not->toBeBetween(1, 3);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect(true)->toBeBool();
|
||||
expect(0)->not->toBeBool();
|
||||
test('pass', function (): void {
|
||||
expect(true)->toBeBool()
|
||||
->and(0)->not->toBeBool();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect(null)->toBeBool();
|
||||
test('failures', function (): void {
|
||||
expect()->toBeBool();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
expect(null)->toBeBool('oh no!');
|
||||
test('failures with custom message', function (): void {
|
||||
expect()->toBeBool('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect(false)->not->toBeBool();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect(function () {})->toBeCallable();
|
||||
expect(null)->not->toBeCallable();
|
||||
test('pass', function (): void {
|
||||
expect(function (): void {})->toBeCallable()
|
||||
->and(null)->not->toBeCallable();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
$hello = 5;
|
||||
|
||||
expect($hello)->toBeCallable();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
$hello = 5;
|
||||
|
||||
expect($hello)->toBeCallable('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
expect(function () {
|
||||
return 42;
|
||||
})->not->toBeCallable();
|
||||
test('not failures', function (): void {
|
||||
expect(fn (): int => 42)->not->toBeCallable();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect('abc')->toBeCamelCase();
|
||||
expect('abcDef')->toBeCamelCase();
|
||||
expect('abc-def')->not->toBeCamelCase();
|
||||
expect('abc-def')->not->toBeCamelCase();
|
||||
expect('AbcDef')->not->toBeCamelCase();
|
||||
test('pass', function (): void {
|
||||
expect('abc')->toBeCamelCase()
|
||||
->and('abcDef')->toBeCamelCase()
|
||||
->and('abc-def')->not->toBeCamelCase()->not->toBeCamelCase()
|
||||
->and('AbcDef')->not->toBeCamelCase();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('Abc')->toBeCamelCase();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect('Abc')->toBeCamelCase('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect('abcDef')->not->toBeCamelCase();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect('123')->toBeDigits();
|
||||
expect('123.14')->not->toBeDigits();
|
||||
test('pass', function (): void {
|
||||
expect('123')->toBeDigits()
|
||||
->and('123.14')->not->toBeDigits();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('123.14')->toBeDigits();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect('123.14')->toBeDigits('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect('445')->not->toBeDigits();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
test('pass', function (): void {
|
||||
$temp = sys_get_temp_dir();
|
||||
|
||||
expect($temp)->toBeDirectory();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('/random/path/whatever')->toBeDirectory();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect('/random/path/whatever')->toBeDirectory('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect('.')->not->toBeDirectory();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
test('pass', function (): void {
|
||||
expect('user@example.com')->toBeEmail()
|
||||
->and('notanemail')->not->toBeEmail();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('notanemail')->toBeEmail();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect('notanemail')->toBeEmail('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('failures with default message', function () {
|
||||
test('failures with default message', function (): void {
|
||||
expect('notanemail')->toBeEmail();
|
||||
})->throws(ExpectationFailedException::class, 'Failed asserting that notanemail is an email address.');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect('user@example.com')->not->toBeEmail();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,23 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect([])->toBeEmpty();
|
||||
expect(null)->toBeEmpty();
|
||||
test('pass', function (): void {
|
||||
expect([])->toBeEmpty()
|
||||
->and(null)->toBeEmpty();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect([1, 2])->toBeEmpty();
|
||||
expect(' ')->toBeEmpty();
|
||||
test('failures', function (): void {
|
||||
expect([1, 2])->toBeEmpty()
|
||||
->and(' ')->toBeEmpty();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
expect([1, 2])->toBeEmpty('oh no!');
|
||||
expect(' ')->toBeEmpty('oh no!');
|
||||
test('failures with custom message', function (): void {
|
||||
expect([1, 2])->toBeEmpty('oh no!')
|
||||
->and(' ')->toBeEmpty('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
expect([])->not->toBeEmpty();
|
||||
expect(null)->not->toBeEmpty();
|
||||
test('not failures', function (): void {
|
||||
expect([])->not->toBeEmpty()
|
||||
->and(null)->not->toBeEmpty();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('strict comparisons', function () {
|
||||
test('strict comparisons', function (): void {
|
||||
expect(false)->toBeFalse();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('')->toBeFalse();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect('')->toBeFalse('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
expect(false)->not->toBe(false);
|
||||
test('not failures', function (): void {
|
||||
expect(false)->toBeTrue();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,23 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('passes as falsy', function ($value) {
|
||||
test('passes as falsy', function ($value): void {
|
||||
expect($value)->toBeFalsy();
|
||||
})->with([false, '', null, 0, '0']);
|
||||
|
||||
test('passes as not falsy', function ($value) {
|
||||
test('passes as not falsy', function ($value): void {
|
||||
expect($value)->not->toBeFalsy();
|
||||
})->with([true, [1], 'false', 1, -1]);
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect(1)->toBeFalsy();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect(1)->toBeFalsy('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
expect(null)->not->toBeFalsy();
|
||||
test('not failures', function (): void {
|
||||
expect()->not->toBeFalsy();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -2,26 +2,26 @@
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
beforeEach(function () {
|
||||
beforeEach(function (): void {
|
||||
touch($this->tempFile = sys_get_temp_dir().'/fake.file');
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
afterEach(function (): void {
|
||||
unlink($this->tempFile);
|
||||
});
|
||||
|
||||
test('pass', function () {
|
||||
test('pass', function (): void {
|
||||
expect($this->tempFile)->toBeFile();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('/random/path/whatever.file')->toBeFile();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect('/random/path/whatever.file')->toBeFile('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect($this->tempFile)->not->toBeFile();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect(1.0)->toBeFloat();
|
||||
expect(1)->not->toBeFloat();
|
||||
test('pass', function (): void {
|
||||
expect(1.0)->toBeFloat()
|
||||
->and(1)->not->toBeFloat();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect(42)->toBeFloat();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect(42)->toBeFloat('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect(log(3))->not->toBeFloat();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -2,33 +2,32 @@
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('passes', function () {
|
||||
expect(42)->toBeGreaterThan(41);
|
||||
expect(4)->toBeGreaterThan(3.9);
|
||||
test('passes', function (): void {
|
||||
expect(42)->toBeGreaterThan(41)
|
||||
->and(4)->toBeGreaterThan(3.9);
|
||||
});
|
||||
|
||||
test('passes with DateTime and DateTimeImmutable', function () {
|
||||
test('passes with DateTime and DateTimeImmutable', function (): void {
|
||||
$now = new DateTime;
|
||||
$past = (new DateTimeImmutable)->modify('-1 day');
|
||||
|
||||
expect($now)->toBeGreaterThan($past);
|
||||
|
||||
expect($past)->not->toBeGreaterThan($now);
|
||||
expect($now)->toBeGreaterThan($past)
|
||||
->and($past)->not->toBeGreaterThan($now);
|
||||
});
|
||||
|
||||
test('passes with strings', function () {
|
||||
expect('b')->toBeGreaterThan('a');
|
||||
expect('a')->not->toBeGreaterThan('a');
|
||||
test('passes with strings', function (): void {
|
||||
expect('b')->toBeGreaterThan('a')
|
||||
->and('a')->not->toBeGreaterThan('a');
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect(4)->toBeGreaterThan(4);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect(4)->toBeGreaterThan(4, 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect(5)->not->toBeGreaterThan(4);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -2,35 +2,33 @@
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('passes', function () {
|
||||
expect(42)->toBeGreaterThanOrEqual(41);
|
||||
expect(4)->toBeGreaterThanOrEqual(4);
|
||||
test('passes', function (): void {
|
||||
expect(42)->toBeGreaterThanOrEqual(41)
|
||||
->and(4)->toBeGreaterThanOrEqual(4);
|
||||
});
|
||||
|
||||
test('passes with DateTime and DateTimeImmutable', function () {
|
||||
test('passes with DateTime and DateTimeImmutable', function (): void {
|
||||
$now = new DateTime;
|
||||
$past = (new DateTimeImmutable)->modify('-1 day');
|
||||
|
||||
expect($now)->toBeGreaterThanOrEqual($now);
|
||||
|
||||
expect($now)->toBeGreaterThanOrEqual($past);
|
||||
|
||||
expect($past)->not->toBeGreaterThanOrEqual($now);
|
||||
expect($now)->toBeGreaterThanOrEqual($now)
|
||||
->toBeGreaterThanOrEqual($past)
|
||||
->and($past)->not->toBeGreaterThanOrEqual($now);
|
||||
});
|
||||
|
||||
test('passes with strings', function () {
|
||||
expect('b')->toBeGreaterThanOrEqual('a');
|
||||
expect('a')->toBeGreaterThanOrEqual('a');
|
||||
test('passes with strings', function (): void {
|
||||
expect('b')->toBeGreaterThanOrEqual('a')
|
||||
->and('a')->toBeGreaterThanOrEqual('a');
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect(4)->toBeGreaterThanOrEqual(4.1);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect(4)->toBeGreaterThanOrEqual(4.1, 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect(5)->not->toBeGreaterThanOrEqual(5);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('passes', function () {
|
||||
expect('a')->toBeIn(['a', 'b', 'c']);
|
||||
expect('d')->not->toBeIn(['a', 'b', 'c']);
|
||||
test('passes', function (): void {
|
||||
expect('a')->toBeIn(['a', 'b', 'c'])
|
||||
->and('d')->not->toBeIn(['a', 'b', 'c']);
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('d')->toBeIn(['a', 'b', 'c']);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect('d')->toBeIn(['a', 'b', 'c'], 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect('a')->not->toBeIn(['a', 'b', 'c']);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect(log(0))->toBeInfinite();
|
||||
expect(log(1))->not->toBeInfinite();
|
||||
test('pass', function (): void {
|
||||
expect(log(0))->toBeInfinite()
|
||||
->and(log(1))->not->toBeInfinite();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect(asin(2))->toBeInfinite();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect(asin(2))->toBeInfinite('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect(INF)->not->toBeInfinite();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect(new Exception)->toBeInstanceOf(Exception::class);
|
||||
expect(new Exception)->not->toBeInstanceOf(RuntimeException::class);
|
||||
test('pass', function (): void {
|
||||
expect(new Exception)->toBeInstanceOf(Exception::class)->not->toBeInstanceOf(RuntimeException::class);
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect(new Exception)->toBeInstanceOf(RuntimeException::class);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect(new Exception)->toBeInstanceOf(RuntimeException::class, 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect(new Exception)->not->toBeInstanceOf(Exception::class);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect(42)->toBeInt();
|
||||
expect(42.0)->not->toBeInt();
|
||||
test('pass', function (): void {
|
||||
expect(42)->toBeInt()
|
||||
->and(42.0)->not->toBeInt();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect(42.0)->toBeInt();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect(42.0)->toBeInt('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect(6 * 7)->not->toBeInt();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,29 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Pest\Arch\Exceptions\ArchExpectationFailedException;
|
||||
use Tests\Fixtures\Arch\ToBeInvokable\IsInvokable\InvokableClass;
|
||||
use Tests\Fixtures\Arch\ToBeInvokable\IsInvokable\InvokableClassViaParent;
|
||||
use Tests\Fixtures\Arch\ToBeInvokable\IsInvokable\InvokableClassViaTrait;
|
||||
use Tests\Fixtures\Arch\ToBeInvokable\IsNotInvokable\IsNotInvokableClass;
|
||||
|
||||
test('class is invokable')
|
||||
->expect('Tests\\Fixtures\\Arch\\ToBeInvokable\\IsInvokable\\InvokableClass')
|
||||
->expect(InvokableClass::class)
|
||||
->toBeInvokable();
|
||||
|
||||
test('opposite class is invokable')
|
||||
->throws(ArchExpectationFailedException::class)
|
||||
->expect('Tests\\Fixtures\\Arch\\ToBeInvokable\\IsInvokable\\InvokableClass')
|
||||
->expect(InvokableClass::class)
|
||||
->not->toBeInvokable();
|
||||
|
||||
test('class is invokable via a parent class')
|
||||
->expect('Tests\\Fixtures\\Arch\\ToBeInvokable\\IsInvokable\\InvokableClassViaParent')
|
||||
->expect(InvokableClassViaParent::class)
|
||||
->toBeInvokable();
|
||||
|
||||
test('class is invokable via a trait')
|
||||
->expect('Tests\\Fixtures\\Arch\\ToBeInvokable\\IsInvokable\\InvokableClassViaTrait')
|
||||
->expect(InvokableClassViaTrait::class)
|
||||
->toBeInvokable();
|
||||
|
||||
test('failure when the class is not invokable')
|
||||
->throws(ArchExpectationFailedException::class)
|
||||
->expect('Tests\\Fixtures\\Arch\\ToBeInvokable\\IsNotInvokable\\IsNotInvokableClass')
|
||||
->expect(IsNotInvokableClass::class)
|
||||
->toBeInvokable();
|
||||
|
||||
test('class is not invokable')
|
||||
->expect('Tests\\Fixtures\\Arch\\ToBeInvokable\\IsNotInvokable\\IsNotInvokableClass')
|
||||
->expect(IsNotInvokableClass::class)
|
||||
->not->toBeInvokable();
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect([])->toBeIterable();
|
||||
expect(null)->not->toBeIterable();
|
||||
test('pass', function (): void {
|
||||
expect([])->toBeIterable()
|
||||
->and(null)->not->toBeIterable();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect(42)->toBeIterable();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect(42)->toBeIterable('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
function gen(): iterable
|
||||
{
|
||||
yield 1;
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect('{"hello":"world"}')->toBeJson();
|
||||
expect('foo')->not->toBeJson();
|
||||
expect('{"hello"')->not->toBeJson();
|
||||
test('pass', function (): void {
|
||||
expect('{"hello":"world"}')->toBeJson()
|
||||
->and('foo')->not->toBeJson()
|
||||
->and('{"hello"')->not->toBeJson();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect(':"world"}')->toBeJson();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect(':"world"}')->toBeJson('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect('{"hello":"world"}')->not->toBeJson();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,23 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect('abc')->toBeKebabCase();
|
||||
expect('abc-def')->toBeKebabCase();
|
||||
expect('abc_def')->not->toBeKebabCase();
|
||||
expect('abcDef')->not->toBeKebabCase();
|
||||
expect('AbcDef')->not->toBeKebabCase();
|
||||
test('pass', function (): void {
|
||||
expect('abc')->toBeKebabCase()
|
||||
->and('abc-def')->toBeKebabCase()
|
||||
->and('abc_def')->not->toBeKebabCase()
|
||||
->and('abcDef')->not->toBeKebabCase()
|
||||
->and('AbcDef')->not->toBeKebabCase();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('Abc')->toBeKebabCase();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect('Abc')->toBeKebabCase('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect('abc-def')->not->toBeKebabCase();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -2,33 +2,31 @@
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('passes', function () {
|
||||
expect(41)->toBeLessThan(42);
|
||||
expect(4)->toBeLessThan(5);
|
||||
test('passes', function (): void {
|
||||
expect(41)->toBeLessThan(42)
|
||||
->and(4)->toBeLessThan(5);
|
||||
});
|
||||
|
||||
test('passes with DateTime and DateTimeImmutable', function () {
|
||||
test('passes with DateTime and DateTimeImmutable', function (): void {
|
||||
$now = new DateTime;
|
||||
$past = (new DateTimeImmutable)->modify('-1 day');
|
||||
|
||||
expect($past)->toBeLessThan($now);
|
||||
|
||||
expect($now)->not->toBeLessThan($now);
|
||||
expect($past)->toBeLessThan($now)
|
||||
->and($now)->not->toBeLessThan($now);
|
||||
});
|
||||
|
||||
test('passes with strings', function () {
|
||||
expect('a')->toBeLessThan('b');
|
||||
expect('a')->not->toBeLessThan('a');
|
||||
test('passes with strings', function (): void {
|
||||
expect('a')->toBeLessThan('b')->not->toBeLessThan('a');
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect(4)->toBeLessThan(4);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect(4)->toBeLessThan(4, 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect(5)->not->toBeLessThan(6);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -2,35 +2,33 @@
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('passes', function () {
|
||||
expect(41)->toBeLessThanOrEqual(42);
|
||||
expect(4)->toBeLessThanOrEqual(4);
|
||||
test('passes', function (): void {
|
||||
expect(41)->toBeLessThanOrEqual(42)
|
||||
->and(4)->toBeLessThanOrEqual(4);
|
||||
});
|
||||
|
||||
test('passes with DateTime and DateTimeImmutable', function () {
|
||||
test('passes with DateTime and DateTimeImmutable', function (): void {
|
||||
$now = new DateTime;
|
||||
$past = (new DateTimeImmutable)->modify('-1 day');
|
||||
|
||||
expect($now)->toBeLessThanOrEqual($now);
|
||||
|
||||
expect($past)->toBeLessThanOrEqual($now);
|
||||
|
||||
expect($now)->not->toBeLessThanOrEqual($past);
|
||||
expect($now)->toBeLessThanOrEqual($now)
|
||||
->and($past)->toBeLessThanOrEqual($now)
|
||||
->and($now)->not->toBeLessThanOrEqual($past);
|
||||
});
|
||||
|
||||
test('passes with strings', function () {
|
||||
expect('a')->toBeLessThanOrEqual('b');
|
||||
expect('a')->toBeLessThanOrEqual('a');
|
||||
test('passes with strings', function (): void {
|
||||
expect('a')->toBeLessThanOrEqual('b')
|
||||
->toBeLessThanOrEqual('a');
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect(4)->toBeLessThanOrEqual(3.9);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect(4)->toBeLessThanOrEqual(3.9, 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect(5)->not->toBeLessThanOrEqual(5);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect([1, 2, 3])->toBeList();
|
||||
expect(['a' => 1, 'b' => 2, 'c' => 3])->not->toBeList();
|
||||
expect('1, 2, 3')->not->toBeList();
|
||||
test('pass', function (): void {
|
||||
expect([1, 2, 3])->toBeList()
|
||||
->and(['a' => 1, 'b' => 2, 'c' => 3])->not->toBeList()
|
||||
->and('1, 2, 3')->not->toBeList();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect(null)->toBeList();
|
||||
test('failures', function (): void {
|
||||
expect()->toBeList();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
expect(null)->toBeList('oh no!');
|
||||
test('failures with custom message', function (): void {
|
||||
expect()->toBeList('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect(['a', 'b', 'c'])->not->toBeList();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect('lowercase')->toBeLowercase();
|
||||
expect('UPPERCASE')->not->toBeLowercase();
|
||||
test('pass', function (): void {
|
||||
expect('lowercase')->toBeLowercase()
|
||||
->and('UPPERCASE')->not->toBeLowercase();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('UPPERCASE')->toBeLowercase();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect('UPPERCASE')->toBeLowercase('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect('lowercase')->not->toBeLowercase();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect(asin(2))->toBeNan();
|
||||
expect(log(0))->not->toBeNan();
|
||||
test('pass', function (): void {
|
||||
expect(asin(2))->toBeNan()
|
||||
->and(log(0))->not->toBeNan();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect(1)->toBeNan();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect(1)->toBeNan('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect(acos(1.5))->not->toBeNan();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect(null)->toBeNull();
|
||||
expect('')->not->toBeNull();
|
||||
test('pass', function (): void {
|
||||
expect()->toBeNull()
|
||||
->and('')->not->toBeNull();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('hello')->toBeNull();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect('hello')->toBeNull('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
expect(null)->not->toBeNull();
|
||||
test('not failures', function (): void {
|
||||
expect()->not->toBeNull();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect(42)->toBeNumeric();
|
||||
expect('A')->not->toBeNumeric();
|
||||
test('pass', function (): void {
|
||||
expect(42)->toBeNumeric()
|
||||
->and('A')->not->toBeNumeric();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect(null)->toBeNumeric();
|
||||
test('failures', function (): void {
|
||||
expect()->toBeNumeric();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
expect(null)->toBeNumeric('oh no!');
|
||||
test('failures with custom message', function (): void {
|
||||
expect()->toBeNumeric('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect(6 * 7)->not->toBeNumeric();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect((object) ['a' => 1])->toBeObject();
|
||||
expect(['a' => 1])->not->toBeObject();
|
||||
test('pass', function (): void {
|
||||
expect((object) ['a' => 1])->toBeObject()
|
||||
->and(['a' => 1])->not->toBeObject();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect(null)->toBeObject();
|
||||
test('failures', function (): void {
|
||||
expect()->toBeObject();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
expect(null)->toBeObject('oh no!');
|
||||
test('failures with custom message', function (): void {
|
||||
expect()->toBeObject('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect((object) 'ciao')->not->toBeObject();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
test('pass', function (): void {
|
||||
expect(sys_get_temp_dir())->toBeReadableDirectory();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('/random/path/whatever')->toBeReadableDirectory();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect('/random/path/whatever')->toBeReadableDirectory('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect(sys_get_temp_dir())->not->toBeReadableDirectory();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -2,26 +2,26 @@
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
beforeEach(function () {
|
||||
beforeEach(function (): void {
|
||||
touch($this->tempFile = sys_get_temp_dir().'/fake.file');
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
afterEach(function (): void {
|
||||
unlink($this->tempFile);
|
||||
});
|
||||
|
||||
test('pass', function () {
|
||||
test('pass', function (): void {
|
||||
expect($this->tempFile)->toBeReadableFile();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('/random/path/whatever.file')->toBeReadableFile();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect('/random/path/whatever.file')->toBeReadableFile('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect($this->tempFile)->not->toBeReadableFile();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,26 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
$resource = tmpfile();
|
||||
|
||||
afterAll(function () use ($resource) {
|
||||
afterAll(function () use ($resource): void {
|
||||
fclose($resource);
|
||||
});
|
||||
|
||||
test('pass', function () use ($resource) {
|
||||
expect($resource)->toBeResource();
|
||||
expect(null)->not->toBeResource();
|
||||
test('pass', function () use ($resource): void {
|
||||
expect($resource)->toBeResource()
|
||||
->and(null)->not->toBeResource();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect(null)->toBeResource();
|
||||
test('failures', function (): void {
|
||||
expect()->toBeResource();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
expect(null)->toBeResource('oh no!');
|
||||
test('failures with custom message', function (): void {
|
||||
expect()->toBeResource('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () use ($resource) {
|
||||
test('not failures', function () use ($resource): void {
|
||||
expect($resource)->not->toBeResource();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
test('pass', function (): void {
|
||||
expect(1.1)->toBeScalar();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect(null)->toBeScalar();
|
||||
test('failures', function (): void {
|
||||
expect()->toBeScalar();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
expect(null)->toBeScalar('oh no!');
|
||||
test('failures with custom message', function (): void {
|
||||
expect()->toBeScalar('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect(42)->not->toBeScalar();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
test('pass', function (): void {
|
||||
expect('This is a Test String!')->toBeSlug()
|
||||
->and('Another Test String')->toBeSlug();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('')->toBeSlug();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect('')->toBeSlug('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('failures with default message', function () {
|
||||
test('failures with default message', function (): void {
|
||||
expect('')->toBeSlug();
|
||||
})->throws(ExpectationFailedException::class, 'Failed asserting that can be converted to a slug.');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect('This is a Test String!')->not->toBeSlug();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,23 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect('abc')->toBeSnakeCase();
|
||||
expect('abc_def')->toBeSnakeCase();
|
||||
expect('abc-def')->not->toBeSnakeCase();
|
||||
expect('abcDef')->not->toBeSnakeCase();
|
||||
expect('AbcDef')->not->toBeSnakeCase();
|
||||
test('pass', function (): void {
|
||||
expect('abc')->toBeSnakeCase()
|
||||
->and('abc_def')->toBeSnakeCase()
|
||||
->and('abc-def')->not->toBeSnakeCase()
|
||||
->and('abcDef')->not->toBeSnakeCase()
|
||||
->and('AbcDef')->not->toBeSnakeCase();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('Abc')->toBeSnakeCase();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect('Abc')->toBeSnakeCase('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect('abc_def')->not->toBeSnakeCase();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect('1.1')->toBeString();
|
||||
expect(1.1)->not->toBeString();
|
||||
test('pass', function (): void {
|
||||
expect('1.1')->toBeString()
|
||||
->and(1.1)->not->toBeString();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect(null)->toBeString();
|
||||
test('failures', function (): void {
|
||||
expect()->toBeString();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
expect(null)->toBeString('oh no!');
|
||||
test('failures with custom message', function (): void {
|
||||
expect()->toBeString('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect('42')->not->toBeString();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect('Abc')->toBeStudlyCase();
|
||||
expect('AbcDef')->toBeStudlyCase();
|
||||
expect('abc-def')->not->toBeStudlyCase();
|
||||
expect('abc-def')->not->toBeStudlyCase();
|
||||
expect('abc')->not->toBeStudlyCase();
|
||||
test('pass', function (): void {
|
||||
expect('Abc')->toBeStudlyCase()
|
||||
->and('AbcDef')->toBeStudlyCase()
|
||||
->and('abc-def')->not->toBeStudlyCase()->not->toBeStudlyCase()
|
||||
->and('abc')->not->toBeStudlyCase();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('abc')->toBeStudlyCase();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect('abc')->toBeStudlyCase('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect('AbcDef')->not->toBeStudlyCase();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('strict comparisons', function () {
|
||||
test('strict comparisons', function (): void {
|
||||
expect(true)->toBeTrue();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('')->toBeTrue();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect('')->toBeTrue('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
expect(false)->not->toBe(false);
|
||||
test('not failures', function (): void {
|
||||
expect(false)->toBeTrue();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,23 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('passes as truthy', function ($value) {
|
||||
test('passes as truthy', function ($value): void {
|
||||
expect($value)->toBeTruthy();
|
||||
})->with([true, [1], 'false', 1, -1]);
|
||||
|
||||
test('passes as not truthy', function ($value) {
|
||||
test('passes as not truthy', function ($value): void {
|
||||
expect($value)->not->toBeTruthy();
|
||||
})->with([false, '', null, 0, '0']);
|
||||
|
||||
test('failures', function () {
|
||||
expect(null)->toBeTruthy();
|
||||
test('failures', function (): void {
|
||||
expect()->toBeTruthy();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
expect(null)->toBeTruthy('oh no!');
|
||||
test('failures with custom message', function (): void {
|
||||
expect()->toBeTruthy('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect(1)->not->toBeTruthy();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,26 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Pest\Exceptions\InvalidExpectationValue;
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('failures with wrong type', function () {
|
||||
test('failures with wrong type', function (): void {
|
||||
expect([])->toBeUlid();
|
||||
})->throws(InvalidExpectationValue::class, 'Invalid expectation value type. Expected [string].');
|
||||
|
||||
test('pass', function () {
|
||||
expect('01ARZ3NDEKTSV4RRFFQ69G5FAV')->toBeUlid();
|
||||
expect('01BX5ZZKBKACTAV9WEVGEMMVRE')->toBeUlid();
|
||||
expect('7ZZZZZZZZZ0000000000000000')->toBeUlid();
|
||||
test('pass', function (): void {
|
||||
expect('01ARZ3NDEKTSV4RRFFQ69G5FAV')->toBeUlid()
|
||||
->and('01BX5ZZKBKACTAV9WEVGEMMVRE')->toBeUlid()
|
||||
->and('7ZZZZZZZZZ0000000000000000')->toBeUlid();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('foo')->toBeUlid();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with message', function () {
|
||||
test('failures with message', function (): void {
|
||||
expect('bar')->toBeUlid('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect('foo')->not->toBeUlid();
|
||||
});
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect('UPPERCASE')->toBeUppercase();
|
||||
expect('lowercase')->not->toBeUppercase();
|
||||
test('pass', function (): void {
|
||||
expect('UPPERCASE')->toBeUppercase()
|
||||
->and('lowercase')->not->toBeUppercase();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('lowercase')->toBeUppercase();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect('lowercase')->toBeUppercase('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect('UPPERCASE')->not->toBeUppercase();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
test('pass', function (): void {
|
||||
expect('https://pestphp.com')->toBeUrl()
|
||||
->and('pestphp.com')->not->toBeUrl();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('pestphp.com')->toBeUrl();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect('pestphp.com')->toBeUrl('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('failures with default message', function () {
|
||||
test('failures with default message', function (): void {
|
||||
expect('pestphp.com')->toBeUrl();
|
||||
})->throws(ExpectationFailedException::class, 'Failed asserting that pestphp.com is a url.');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect('https://pestphp.com')->not->toBeUrl();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Pest\Exceptions\InvalidExpectationValue;
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('failures with wrong type', function () {
|
||||
test('failures with wrong type', function (): void {
|
||||
expect([])->toBeUuid();
|
||||
})->throws(InvalidExpectationValue::class, 'Invalid expectation value type. Expected [string].');
|
||||
|
||||
test('pass', function () {
|
||||
test('pass', function (): void {
|
||||
expect('3cafb226-4326-11ee-a516-846993788c86')->toBeUuid(); // version 1
|
||||
expect('0000415c-4326-21ee-a700-846993788c86')->toBeUuid(); // version 2
|
||||
expect('3f703955-aaba-3e70-a3cb-baff6aa3b28f')->toBeUuid(); // version 3
|
||||
@@ -18,14 +20,14 @@ test('pass', function () {
|
||||
expect('00112233-4455-8677-8899-aabbccddeeff')->toBeUuid(); // version 8
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('foo')->toBeUuid();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with message', function () {
|
||||
test('failures with message', function (): void {
|
||||
expect('bar')->toBeUuid('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect('foo')->not->toBeUuid();
|
||||
});
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
test('pass', function (): void {
|
||||
expect(sys_get_temp_dir())->toBeWritableDirectory();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('/random/path/whatever')->toBeWritableDirectory();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect('/random/path/whatever')->toBeWritableDirectory('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect(sys_get_temp_dir())->not->toBeWritableDirectory();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -2,26 +2,26 @@
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
beforeEach(function () {
|
||||
beforeEach(function (): void {
|
||||
touch($this->tempFile = sys_get_temp_dir().'/fake.file');
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
afterEach(function (): void {
|
||||
unlink($this->tempFile);
|
||||
});
|
||||
|
||||
test('pass', function () {
|
||||
test('pass', function (): void {
|
||||
expect($this->tempFile)->toBeWritableFile();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('/random/path/whatever.file')->toBeWritableFile();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect('/random/path/whatever.file')->toBeWritableFile('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect($this->tempFile)->not->toBeWritableFile();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,47 +1,49 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('passes strings', function () {
|
||||
test('passes strings', function (): void {
|
||||
expect('Nuno')->toContain('Nu');
|
||||
});
|
||||
|
||||
test('passes strings with multiple needles', function () {
|
||||
test('passes strings with multiple needles', function (): void {
|
||||
expect('Nuno')->toContain('Nu', 'no');
|
||||
});
|
||||
|
||||
test('passes arrays', function () {
|
||||
test('passes arrays', function (): void {
|
||||
expect([1, 2, 42])->toContain(42);
|
||||
});
|
||||
|
||||
test('passes arrays with multiple needles', function () {
|
||||
test('passes arrays with multiple needles', function (): void {
|
||||
expect([1, 2, 42])->toContain(42, 2);
|
||||
});
|
||||
|
||||
test('passes with array needles', function () {
|
||||
test('passes with array needles', function (): void {
|
||||
expect([[1, 2, 3], 2, 42])->toContain(42, [1, 2, 3]);
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect([1, 2, 42])->toContain(3);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with multiple needles (all failing)', function () {
|
||||
test('failures with multiple needles (all failing)', function (): void {
|
||||
expect([1, 2, 42])->toContain(3, 4);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with multiple needles (some failing)', function () {
|
||||
test('failures with multiple needles (some failing)', function (): void {
|
||||
expect([1, 2, 42])->toContain(1, 3, 4);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect([1, 2, 42])->not->toContain(42);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures with multiple needles (all failing)', function () {
|
||||
test('not failures with multiple needles (all failing)', function (): void {
|
||||
expect([1, 2, 42])->not->toContain(42, 2);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures with multiple needles (some failing)', function () {
|
||||
test('not failures with multiple needles (some failing)', function (): void {
|
||||
expect([1, 2, 42])->not->toContain(42, 1);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,35 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('passes arrays', function () {
|
||||
test('passes arrays', function (): void {
|
||||
expect([1, 2, 42])->toContainEqual('42');
|
||||
});
|
||||
|
||||
test('passes arrays with multiple needles', function () {
|
||||
test('passes arrays with multiple needles', function (): void {
|
||||
expect([1, 2, 42])->toContainEqual('42', '2');
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect([1, 2, 42])->toContainEqual('3');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with multiple needles (all failing)', function () {
|
||||
test('failures with multiple needles (all failing)', function (): void {
|
||||
expect([1, 2, 42])->toContainEqual('3', '4');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with multiple needles (some failing)', function () {
|
||||
test('failures with multiple needles (some failing)', function (): void {
|
||||
expect([1, 2, 42])->toContainEqual('1', '3', '4');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect([1, 2, 42])->not->toContainEqual('42');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures with multiple needles (all failing)', function () {
|
||||
test('not failures with multiple needles (all failing)', function (): void {
|
||||
expect([1, 2, 42])->not->toContainEqual('42', '2');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures with multiple needles (some failing)', function () {
|
||||
test('not failures with multiple needles (some failing)', function (): void {
|
||||
expect([1, 2, 42])->not->toContainEqual('42', '1');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -2,23 +2,22 @@
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
beforeEach(function () {
|
||||
beforeEach(function (): void {
|
||||
$this->times = [new DateTimeImmutable, new DateTimeImmutable];
|
||||
});
|
||||
|
||||
test('pass', function () {
|
||||
expect($this->times)->toContainOnlyInstancesOf(DateTimeImmutable::class);
|
||||
expect($this->times)->not->toContainOnlyInstancesOf(DateTime::class);
|
||||
test('pass', function (): void {
|
||||
expect($this->times)->toContainOnlyInstancesOf(DateTimeImmutable::class)->not->toContainOnlyInstancesOf(DateTime::class);
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect($this->times)->toContainOnlyInstancesOf(DateTime::class);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect($this->times)->toContainOnlyInstancesOf(DateTime::class, 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect($this->times)->not->toContainOnlyInstancesOf(DateTimeImmutable::class);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
test('pass', function (): void {
|
||||
expect('username')->toEndWith('name');
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('username')->toEndWith('password');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect('username')->toEndWith('password', 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect('username')->not->toEndWith('name');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
test('pass', function (): void {
|
||||
expect('00123')->toEqual(123);
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect(['a', 'b', 'c'])->toEqual(['a', 'b']);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect(['a', 'b', 'c'])->toEqual(['a', 'b'], 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect('042')->not->toEqual(42);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect([1, 2, 3])->toEqualCanonicalizing([3, 1, 2]);
|
||||
expect(['g', 'a', 'z'])->not->toEqualCanonicalizing(['a', 'z']);
|
||||
test('pass', function (): void {
|
||||
expect([1, 2, 3])->toEqualCanonicalizing([3, 1, 2])
|
||||
->and(['g', 'a', 'z'])->not->toEqualCanonicalizing(['a', 'z']);
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect([3, 2, 1])->toEqualCanonicalizing([1, 2]);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect([3, 2, 1])->toEqualCanonicalizing([1, 2], 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect(['a', 'b', 'c'])->not->toEqualCanonicalizing(['b', 'a', 'c']);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
test('pass', function (): void {
|
||||
expect(1.0)->toEqualWithDelta(1.3, .4);
|
||||
});
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect(1.0)->toEqualWithDelta(1.5, .1, 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect(1.0)->not->toEqualWithDelta(1.6, .7);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
<?php
|
||||
|
||||
use Pest\Arch\Exceptions\ArchExpectationFailedException;
|
||||
use Tests\Fixtures\Arch\ToHaveAttribute\Attributes\AsAttribute;
|
||||
|
||||
test('class has attribute')
|
||||
->expect('Tests\\Fixtures\\Arch\\ToHaveAttribute\\HaveAttribute')
|
||||
->toHaveAttribute('Tests\\Fixtures\\Arch\\ToHaveAttribute\\Attributes\\AsAttribute');
|
||||
->toHaveAttribute(AsAttribute::class);
|
||||
|
||||
test('opposite class has attribute')
|
||||
->throws(ArchExpectationFailedException::class)
|
||||
->expect('Tests\\Fixtures\\Arch\\ToHaveAttribute\\HaveAttribute')
|
||||
->not
|
||||
->toHaveAttribute('Tests\\Fixtures\\Arch\\ToHaveAttribute\\Attributes\\AsAttribute');
|
||||
->toHaveAttribute(AsAttribute::class);
|
||||
|
||||
test('class not has attribute')
|
||||
->expect('Tests\\Fixtures\\Arch\\ToHaveAttribute\\NotHaveAttribute')
|
||||
->not
|
||||
->toHaveAttribute('Tests\\Fixtures\\Arch\\ToHaveAttribute\\Attributes\\AsAttribute');
|
||||
->toHaveAttribute(AsAttribute::class);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Pest\Exceptions\InvalidExpectationValue;
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
@@ -19,18 +21,18 @@ $array = [
|
||||
],
|
||||
];
|
||||
|
||||
test('pass', function () use ($array) {
|
||||
test('pass', function () use ($array): void {
|
||||
expect($array)->toHaveCamelCaseKeys();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('not-an-array')->toHaveCamelCaseKeys();
|
||||
})->throws(InvalidExpectationValue::class);
|
||||
|
||||
test('failures with message', function () use ($array) {
|
||||
test('failures with message', function () use ($array): void {
|
||||
expect($array)->not->toHaveCamelCaseKeys('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () use ($array) {
|
||||
test('not failures', function () use ($array): void {
|
||||
expect($array)->not->toHaveCamelCaseKeys();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
<?php
|
||||
|
||||
use Tests\Fixtures\Arch\ToHaveConstructor\HasConstructor\HasConstructor;
|
||||
use Tests\Fixtures\Arch\ToHaveConstructor\HasNoConstructor\HasNoConstructor;
|
||||
|
||||
test('class has constructor')
|
||||
->expect('Tests\Fixtures\Arch\ToHaveConstructor\HasConstructor\HasConstructor')
|
||||
->expect(HasConstructor::class)
|
||||
->toHaveConstructor();
|
||||
|
||||
test('class has no constructor')
|
||||
->expect('Tests\Fixtures\Arch\ToHaveConstructor\HasNoConstructor\HasNoConstructor')
|
||||
->expect(HasNoConstructor::class)
|
||||
->not->toHaveConstructor();
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Pest\Exceptions\InvalidExpectationValue;
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
test('pass', function (): void {
|
||||
expect([1, 2, 3])->toHaveCount(3);
|
||||
});
|
||||
|
||||
test('failures with invalid type', function () {
|
||||
test('failures with invalid type', function (): void {
|
||||
expect('foo')->toHaveCount(3);
|
||||
})->throws(InvalidExpectationValue::class, 'Invalid expectation value type. Expected [countable|iterable]');
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect([1, 2, 3])->toHaveCount(4);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with message', function () {
|
||||
test('failures with message', function (): void {
|
||||
expect([1, 2, 3])->toHaveCount(4, 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect([1, 2, 3])->not->toHaveCount(3);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
<?php
|
||||
|
||||
use Tests\Fixtures\Arch\ToHaveDestructor\HasDestructor\HasDestructor;
|
||||
use Tests\Fixtures\Arch\ToHaveDestructor\HasNoDestructor\HasNoDestructor;
|
||||
|
||||
test('class has destructor')
|
||||
->expect('Tests\Fixtures\Arch\ToHaveDestructor\HasDestructor\HasDestructor')
|
||||
->expect(HasDestructor::class)
|
||||
->toHaveDestructor();
|
||||
|
||||
test('class has no destructor')
|
||||
->expect('Tests\Fixtures\Arch\ToHaveDestructor\HasNoDestructor\HasNoDestructor')
|
||||
->expect(HasNoDestructor::class)
|
||||
->not->toHaveDestructor();
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
// ...
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Pest\Exceptions\InvalidExpectationValue;
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
@@ -19,18 +21,18 @@ $array = [
|
||||
],
|
||||
];
|
||||
|
||||
test('pass', function () use ($array) {
|
||||
test('pass', function () use ($array): void {
|
||||
expect($array)->toHaveKebabCaseKeys();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('not-an-array')->toHaveKebabCaseKeys();
|
||||
})->throws(InvalidExpectationValue::class);
|
||||
|
||||
test('failures with message', function () use ($array) {
|
||||
test('failures with message', function () use ($array): void {
|
||||
expect($array)->not->toHaveKebabCaseKeys('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () use ($array) {
|
||||
test('not failures', function () use ($array): void {
|
||||
expect($array)->not->toHaveKebabCaseKeys();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -20,66 +20,66 @@ test('pass with value check')->expect($test_array)->toHaveKey('c', 'world');
|
||||
test('pass with value check and nested key')->expect($test_array)->toHaveKey('d.e', 'hello');
|
||||
test('pass with value check and plain key with dots')->expect($test_array)->toHaveKey('key.with.dots', false);
|
||||
|
||||
test('failures', function () use ($test_array) {
|
||||
test('failures', function () use ($test_array): void {
|
||||
expect($test_array)->toHaveKey('foo');
|
||||
})->throws(ExpectationFailedException::class, "Failed asserting that an array has the key 'foo'");
|
||||
|
||||
test('failures with custom message', function () use ($test_array) {
|
||||
test('failures with custom message', function () use ($test_array): void {
|
||||
expect($test_array)->toHaveKey('foo', message: 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('failures with custom message and Any matcher', function () use ($test_array) {
|
||||
test('failures with custom message and Any matcher', function () use ($test_array): void {
|
||||
expect($test_array)->toHaveKey('foo', expect()->any(), 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('failures with nested key', function () use ($test_array) {
|
||||
test('failures with nested key', function () use ($test_array): void {
|
||||
expect($test_array)->toHaveKey('d.bar');
|
||||
})->throws(ExpectationFailedException::class, "Failed asserting that an array has the key 'd.bar'");
|
||||
|
||||
test('failures with nested key and custom message', function () use ($test_array) {
|
||||
test('failures with nested key and custom message', function () use ($test_array): void {
|
||||
expect($test_array)->toHaveKey('d.bar', message: 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('failures with nested key and custom message with Any matcher', function () use ($test_array) {
|
||||
test('failures with nested key and custom message with Any matcher', function () use ($test_array): void {
|
||||
expect($test_array)->toHaveKey('d.bar', expect()->any(), 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('failures with plain key with dots', function () use ($test_array) {
|
||||
test('failures with plain key with dots', function () use ($test_array): void {
|
||||
expect($test_array)->toHaveKey('missing.key.with.dots');
|
||||
})->throws(ExpectationFailedException::class, "Failed asserting that an array has the key 'missing.key.with.dots'");
|
||||
|
||||
test('fails with wrong value', function () use ($test_array) {
|
||||
test('fails with wrong value', function () use ($test_array): void {
|
||||
expect($test_array)->toHaveKey('c', 'bar');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('fails with wrong value and nested key', function () use ($test_array) {
|
||||
test('fails with wrong value and nested key', function () use ($test_array): void {
|
||||
expect($test_array)->toHaveKey('d.e', 'foo');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('fails with wrong value and plain key with dots', function () use ($test_array) {
|
||||
test('fails with wrong value and plain key with dots', function () use ($test_array): void {
|
||||
expect($test_array)->toHaveKey('key.with.dots', true);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures', function () use ($test_array) {
|
||||
test('not failures', function () use ($test_array): void {
|
||||
expect($test_array)->not->toHaveKey('c');
|
||||
})->throws(ExpectationFailedException::class, "Expecting […] not to have key 'c'");
|
||||
|
||||
test('not failures with nested key', function () use ($test_array) {
|
||||
test('not failures with nested key', function () use ($test_array): void {
|
||||
expect($test_array)->not->toHaveKey('d.e');
|
||||
})->throws(ExpectationFailedException::class, "Expecting […] not to have key 'd.e'");
|
||||
|
||||
test('not failures with plain key with dots', function () use ($test_array) {
|
||||
test('not failures with plain key with dots', function () use ($test_array): void {
|
||||
expect($test_array)->not->toHaveKey('key.with.dots');
|
||||
})->throws(ExpectationFailedException::class, "Expecting […] not to have key 'key.with.dots'");
|
||||
|
||||
test('not failures with correct value', function () use ($test_array) {
|
||||
test('not failures with correct value', function () use ($test_array): void {
|
||||
expect($test_array)->not->toHaveKey('c', 'world');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures with correct value and with nested key', function () use ($test_array) {
|
||||
test('not failures with correct value and with nested key', function () use ($test_array): void {
|
||||
expect($test_array)->not->toHaveKey('d.e', 'hello');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures with correct value and with plain key with dots', function () use ($test_array) {
|
||||
test('not failures with correct value and with plain key with dots', function () use ($test_array): void {
|
||||
expect($test_array)->not->toHaveKey('key.with.dots', false);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -2,34 +2,34 @@
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
test('pass', function (): void {
|
||||
expect(['a' => 1, 'b', 'c' => 'world', 'foo' => ['bar' => 'baz']])->toHaveKeys(['a', 'c', 'foo.bar']);
|
||||
});
|
||||
|
||||
test('pass with multi-dimensional arrays', function () {
|
||||
test('pass with multi-dimensional arrays', function (): void {
|
||||
expect(['a' => 1, 'b', 'c' => 'world', 'foo' => ['bar' => ['bir' => 'biz']]])->toHaveKeys(['a', 'c', 'foo' => ['bar' => ['bir']]]);
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect(['a' => 1, 'b', 'c' => 'world', 'foo' => ['bar' => 'baz']])->toHaveKeys(['a', 'd', 'foo.bar', 'hello.world']);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect(['a' => 1, 'b', 'c' => 'world', 'foo' => ['bar' => 'baz']])->toHaveKeys(['a', 'd', 'foo.bar', 'hello.world'], 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('failures with multi-dimensional arrays', function () {
|
||||
test('failures with multi-dimensional arrays', function (): void {
|
||||
expect(['a' => 1, 'b', 'c' => 'world', 'foo' => ['bar' => ['bir' => 'biz']]])->toHaveKeys(['a', 'd', 'foo' => ['bar' => 'bir'], 'hello.world']);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with multi-dimensional arrays and custom message', function () {
|
||||
test('failures with multi-dimensional arrays and custom message', function (): void {
|
||||
expect(['a' => 1, 'b', 'c' => 'world', 'foo' => ['bar' => ['bir' => 'biz']]])->toHaveKeys(['a', 'd', 'foo' => ['bar' => 'bir'], 'hello.world'], 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect(['a' => 1, 'b', 'c' => 'world', 'foo' => ['bar' => 'baz']])->not->toHaveKeys(['foo.bar', 'c', 'z']);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures with multi-dimensional arrays', function () {
|
||||
test('not failures with multi-dimensional arrays', function (): void {
|
||||
expect(['a' => 1, 'b', 'c' => 'world', 'foo' => ['bar' => ['bir' => 'biz']]])->not->toHaveKeys(['foo' => ['bar' => 'bir'], 'c', 'z']);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
it('passes', function ($value) {
|
||||
it('passes', function ($value): void {
|
||||
expect($value)->toHaveLength(9);
|
||||
})->with([
|
||||
'Fortaleza',
|
||||
@@ -11,22 +13,22 @@ it('passes', function ($value) {
|
||||
(object) [1, 2, 3, 4, 5, 6, 7, 8, 9],
|
||||
]);
|
||||
|
||||
it('passes with array', function () {
|
||||
it('passes with array', function (): void {
|
||||
expect([1, 2, 3])->toHaveLength(3);
|
||||
});
|
||||
|
||||
it('passes with *not*', function () {
|
||||
it('passes with *not*', function (): void {
|
||||
expect('')->not->toHaveLength(1);
|
||||
});
|
||||
|
||||
it('properly fails with *not*', function () {
|
||||
it('properly fails with *not*', function (): void {
|
||||
expect('pest')->not->toHaveLength(4, 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
it('fails', function () {
|
||||
it('fails', function (): void {
|
||||
expect([1, 1.5, true, null])->toHaveLength(1);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
it('fails with message', function () {
|
||||
it('fails with message', function (): void {
|
||||
expect([1, 1.5, true, null])->toHaveLength(1, 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
use Pest\Arch\Exceptions\ArchExpectationFailedException;
|
||||
use Pest\Expectation;
|
||||
|
||||
it('passes', function () {
|
||||
it('passes', function (): void {
|
||||
expect(Expectation::class)->toHaveLineCountLessThan(2000);
|
||||
});
|
||||
|
||||
it('fails', function () {
|
||||
it('fails', function (): void {
|
||||
expect(Expectation::class)->toHaveLineCountLessThan(10);
|
||||
})->throws(ArchExpectationFailedException::class);
|
||||
|
||||
@@ -1,29 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Pest\Arch\Exceptions\ArchExpectationFailedException;
|
||||
use Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethod;
|
||||
use Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethodViaParent;
|
||||
use Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethodViaTrait;
|
||||
use Tests\Fixtures\Arch\ToHaveMethod\HasNoMethod\HasNoMethodClass;
|
||||
|
||||
test('class has method')
|
||||
->expect('Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethod')
|
||||
->expect(HasMethod::class)
|
||||
->toHaveMethod('foo');
|
||||
|
||||
test('opposite class has method')
|
||||
->throws(ArchExpectationFailedException::class)
|
||||
->expect('Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethod')
|
||||
->expect(HasMethod::class)
|
||||
->not->toHaveMethod('foo');
|
||||
|
||||
test('class has method via a parent class')
|
||||
->expect('Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethodViaParent')
|
||||
->expect(HasMethodViaParent::class)
|
||||
->toHaveMethod('foo');
|
||||
|
||||
test('class has method via a trait')
|
||||
->expect('Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethodViaTrait')
|
||||
->expect(HasMethodViaTrait::class)
|
||||
->toHaveMethod('foo');
|
||||
|
||||
test('failure when the class has no method')
|
||||
->throws(ArchExpectationFailedException::class)
|
||||
->expect('Tests\Fixtures\Arch\ToHaveMethod\HasNoMethod\HasNoMethodClass')
|
||||
->expect(HasNoMethodClass::class)
|
||||
->toHaveMethod('foo');
|
||||
|
||||
test('class has no method')
|
||||
->expect('Tests\Fixtures\Arch\ToHaveMethod\HasNoMethod\HasNoMethodClass')
|
||||
->expect(HasNoMethodClass::class)
|
||||
->not->toHaveMethod('foo');
|
||||
|
||||
@@ -1,29 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Pest\Arch\Exceptions\ArchExpectationFailedException;
|
||||
use Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethod;
|
||||
use Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethodViaParent;
|
||||
use Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethodViaTrait;
|
||||
use Tests\Fixtures\Arch\ToHaveMethod\HasNoMethod\HasNoMethodClass;
|
||||
|
||||
test('class has method')
|
||||
->expect('Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethod')
|
||||
->expect(HasMethod::class)
|
||||
->toHaveMethods(['foo']);
|
||||
|
||||
test('opposite class has method')
|
||||
->throws(ArchExpectationFailedException::class)
|
||||
->expect('Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethod')
|
||||
->expect(HasMethod::class)
|
||||
->not->toHaveMethods(['foo']);
|
||||
|
||||
test('class has method via a parent class')
|
||||
->expect('Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethodViaParent')
|
||||
->expect(HasMethodViaParent::class)
|
||||
->toHaveMethods(['foo']);
|
||||
|
||||
test('class has method via a trait')
|
||||
->expect('Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethodViaTrait')
|
||||
->expect(HasMethodViaTrait::class)
|
||||
->toHaveMethods(['foo']);
|
||||
|
||||
test('failure when the class has no method')
|
||||
->throws(ArchExpectationFailedException::class)
|
||||
->expect('Tests\Fixtures\Arch\ToHaveMethod\HasNoMethod\HasNoMethodClass')
|
||||
->expect(HasNoMethodClass::class)
|
||||
->toHaveMethods(['foo']);
|
||||
|
||||
test('class has no method')
|
||||
->expect('Tests\Fixtures\Arch\ToHaveMethod\HasNoMethod\HasNoMethodClass')
|
||||
->expect(HasNoMethodClass::class)
|
||||
->not->toHaveMethods(['foo']);
|
||||
|
||||
@@ -5,15 +5,15 @@ use Pest\Configuration;
|
||||
use Pest\Expectation;
|
||||
use Tests\Fixtures\Inheritance\ExampleTest;
|
||||
|
||||
it('passes', function () {
|
||||
it('passes', function (): void {
|
||||
expect(Expectation::class)->toHaveMethodsDocumented()
|
||||
->and(ExampleTest::class)->not->toHaveMethodsDocumented();
|
||||
});
|
||||
|
||||
it('fails 1', function () {
|
||||
it('fails 1', function (): void {
|
||||
expect(ExampleTest::class)->toHaveMethodsDocumented();
|
||||
})->throws(ArchExpectationFailedException::class);
|
||||
|
||||
it('fails 2', function () {
|
||||
it('fails 2', function (): void {
|
||||
expect(Configuration::class)->not->toHaveMethodsDocumented();
|
||||
})->throws(ArchExpectationFailedException::class);
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
use Pest\Arch\Exceptions\ArchExpectationFailedException;
|
||||
use Tests\Fixtures\Arch\ToHavePublicMethodsBesides\UserController;
|
||||
|
||||
test('pass', function () {
|
||||
test('pass', function (): void {
|
||||
expect(UserController::class)->not->toHavePrivateMethodsBesides(['privateMethod']);
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect(UserController::class)->not->toHavePrivateMethods();
|
||||
})->throws(ArchExpectationFailedException::class);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
test('pass', function (): void {
|
||||
$object = new stdClass;
|
||||
$object->name = 'John';
|
||||
$object->age = 21;
|
||||
@@ -15,7 +15,7 @@ test('pass', function () {
|
||||
]);
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
$object = new stdClass;
|
||||
$object->name = 'John';
|
||||
|
||||
@@ -27,7 +27,7 @@ test('failures', function () {
|
||||
]);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
$object = new stdClass;
|
||||
$object->name = 'John';
|
||||
|
||||
@@ -39,7 +39,7 @@ test('failures with custom message', function () {
|
||||
], 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
$object = new stdClass;
|
||||
$object->name = 'John';
|
||||
$object->age = 21;
|
||||
|
||||
@@ -5,15 +5,15 @@ use Pest\Expectation;
|
||||
use Pest\Factories\TestCaseFactory;
|
||||
use Tests\Fixtures\Inheritance\ExampleTest;
|
||||
|
||||
it('passes', function () {
|
||||
it('passes', function (): void {
|
||||
expect(Expectation::class)->toHavePropertiesDocumented()
|
||||
->and(ExampleTest::class)->not->toHavePropertiesDocumented();
|
||||
});
|
||||
|
||||
it('fails 1', function () {
|
||||
it('fails 1', function (): void {
|
||||
expect(ExampleTest::class)->toHavePropertiesDocumented();
|
||||
})->throws(ArchExpectationFailedException::class);
|
||||
|
||||
it('fails 2', function () {
|
||||
it('fails 2', function (): void {
|
||||
expect(TestCaseFactory::class)->not->toHavePropertiesDocumented();
|
||||
})->throws(ArchExpectationFailedException::class);
|
||||
|
||||
@@ -6,25 +6,25 @@ $obj = new stdClass;
|
||||
$obj->foo = 'bar';
|
||||
$obj->fooNull = null;
|
||||
|
||||
test('pass', function () use ($obj) {
|
||||
expect($obj)->toHaveProperty('foo');
|
||||
expect($obj)->toHaveProperty('foo', 'bar');
|
||||
expect($obj)->toHaveProperty('fooNull');
|
||||
expect($obj)->toHaveProperty('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) {
|
||||
test('failures', function () use ($obj): void {
|
||||
expect($obj)->toHaveProperty('bar');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with message', function () use ($obj) {
|
||||
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) {
|
||||
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) {
|
||||
test('not failures', function () use ($obj): void {
|
||||
expect($obj)->not->toHaveProperty('foo');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
use Pest\Arch\Exceptions\ArchExpectationFailedException;
|
||||
use Tests\Fixtures\Arch\ToHavePublicMethodsBesides\UserController;
|
||||
|
||||
test('pass', function () {
|
||||
test('pass', function (): void {
|
||||
expect(UserController::class)->not->toHaveProtectedMethodsBesides(['protectedMethod']);
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect(UserController::class)->not->toHaveProtectedMethods();
|
||||
})->throws(ArchExpectationFailedException::class);
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
use Pest\Arch\Exceptions\ArchExpectationFailedException;
|
||||
use Tests\Fixtures\Arch\ToHavePublicMethodsBesides\UserController;
|
||||
|
||||
test('pass', function () {
|
||||
test('pass', function (): void {
|
||||
expect(UserController::class)->not->toHavePublicMethodsBesides(['publicMethod']);
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect(UserController::class)->not->toHavePublicMethods();
|
||||
})->throws(ArchExpectationFailedException::class);
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Pest\Exceptions\InvalidExpectationValue;
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('failures with wrong type', function () {
|
||||
test('failures with wrong type', function (): void {
|
||||
expect('foo')->toHaveSameSize([1]);
|
||||
})->throws(InvalidExpectationValue::class, 'Invalid expectation value type. Expected [countable|iterable].');
|
||||
|
||||
test('pass', function () {
|
||||
test('pass', function (): void {
|
||||
expect([1, 2, 3])->toHaveSameSize([4, 5, 6]);
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect([1, 2, 3])->toHaveSameSize([1]);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with message', function () {
|
||||
test('failures with message', function (): void {
|
||||
expect([1, 2, 3])->toHaveSameSize([1], 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect([1, 2, 3])->not->toHaveSameSize([1]);
|
||||
});
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Pest\Exceptions\InvalidExpectationValue;
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
@@ -19,18 +21,18 @@ $array = [
|
||||
],
|
||||
];
|
||||
|
||||
test('pass', function () use ($array) {
|
||||
test('pass', function () use ($array): void {
|
||||
expect($array)->toHaveSnakeCaseKeys();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('not-an-array')->toHaveSnakeCaseKeys();
|
||||
})->throws(InvalidExpectationValue::class);
|
||||
|
||||
test('failures with message', function () use ($array) {
|
||||
test('failures with message', function () use ($array): void {
|
||||
expect($array)->not->toHaveSnakeCaseKeys('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () use ($array) {
|
||||
test('not failures', function () use ($array): void {
|
||||
expect($array)->not->toHaveSnakeCaseKeys();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Pest\Exceptions\InvalidExpectationValue;
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
@@ -19,18 +21,18 @@ $array = [
|
||||
],
|
||||
];
|
||||
|
||||
test('pass', function () use ($array) {
|
||||
test('pass', function () use ($array): void {
|
||||
expect($array)->toHaveStudlyCaseKeys();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('not-an-array')->toHaveStudlyCaseKeys();
|
||||
})->throws(InvalidExpectationValue::class);
|
||||
|
||||
test('failures with message', function () use ($array) {
|
||||
test('failures with message', function () use ($array): void {
|
||||
expect($array)->not->toHaveStudlyCaseKeys('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () use ($array) {
|
||||
test('not failures', function () use ($array): void {
|
||||
expect($array)->not->toHaveStudlyCaseKeys();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
test('pass', function (): void {
|
||||
expect('Hello World')->toMatch('/^hello wo.*$/i');
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('Hello World')->toMatch('/^hello$/i');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect('Hello World')->toMatch('/^hello$/i', 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect('Hello World')->not->toMatch('/^hello wo.*$/i');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
beforeEach(function () {
|
||||
beforeEach(function (): void {
|
||||
$this->user = [
|
||||
'id' => 1,
|
||||
'name' => 'Nuno',
|
||||
@@ -10,28 +10,28 @@ beforeEach(function () {
|
||||
];
|
||||
});
|
||||
|
||||
test('pass', function () {
|
||||
test('pass', function (): void {
|
||||
expect($this->user)->toMatchArray([
|
||||
'name' => 'Nuno',
|
||||
'email' => 'enunomaduro@gmail.com',
|
||||
]);
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect($this->user)->toMatchArray([
|
||||
'name' => 'Not the same name',
|
||||
'email' => 'enunomaduro@gmail.com',
|
||||
]);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect($this->user)->toMatchArray([
|
||||
'name' => 'Not the same name',
|
||||
'email' => 'enunomaduro@gmail.com',
|
||||
], 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect($this->user)->not->toMatchArray([
|
||||
'id' => 1,
|
||||
]);
|
||||
|
||||
@@ -3,18 +3,18 @@
|
||||
use PHPUnit\Framework\Constraint\IsTrue;
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
test('pass', function (): void {
|
||||
expect(true)->toMatchConstraint(new IsTrue);
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect(false)->toMatchConstraint(new IsTrue);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect(false)->toMatchConstraint(new IsTrue, 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect(true)->not->toMatchConstraint(new IsTrue);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
beforeEach(function () {
|
||||
beforeEach(function (): void {
|
||||
$this->user = (object) [
|
||||
'id' => 1,
|
||||
'name' => 'Nuno',
|
||||
@@ -10,14 +10,14 @@ beforeEach(function () {
|
||||
];
|
||||
});
|
||||
|
||||
test('pass', function () {
|
||||
test('pass', function (): void {
|
||||
expect($this->user)->toMatchObject([
|
||||
'name' => 'Nuno',
|
||||
'email' => 'enunomaduro@gmail.com',
|
||||
]);
|
||||
});
|
||||
|
||||
test('pass with class', function () {
|
||||
test('pass with class', function (): void {
|
||||
expect(new class
|
||||
{
|
||||
public $name = 'Nuno';
|
||||
@@ -29,21 +29,21 @@ test('pass with class', function () {
|
||||
]);
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect($this->user)->toMatchObject([
|
||||
'name' => 'Not the same name',
|
||||
'email' => 'enunomaduro@gmail.com',
|
||||
]);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect($this->user)->toMatchObject([
|
||||
'name' => 'Not the same name',
|
||||
'email' => 'enunomaduro@gmail.com',
|
||||
], 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect($this->user)->not->toMatchObject([
|
||||
'id' => 1,
|
||||
]);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use Pest\TestSuite;
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
beforeEach(function () {
|
||||
beforeEach(function (): void {
|
||||
$this->snapshotable = <<<'HTML'
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
@@ -15,7 +15,7 @@ beforeEach(function () {
|
||||
HTML;
|
||||
});
|
||||
|
||||
test('pass', function () {
|
||||
test('pass', function (): void {
|
||||
TestSuite::getInstance()->snapshots->save($this->snapshotable);
|
||||
|
||||
expect($this->snapshotable)->toMatchSnapshot();
|
||||
@@ -33,19 +33,19 @@ expect()->pipe('toMatchSnapshot', function (Closure $next) {
|
||||
return $next();
|
||||
});
|
||||
|
||||
test('pass using pipes', function () {
|
||||
test('pass using pipes', function (): void {
|
||||
expect('<input type="hidden" name="_token" value="'.random_int(1, 999).'" />')
|
||||
->toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('pass with `__toString`', function () {
|
||||
test('pass with `__toString`', function (): void {
|
||||
TestSuite::getInstance()->snapshots->save($this->snapshotable);
|
||||
|
||||
$object = new class($this->snapshotable)
|
||||
{
|
||||
public function __construct(protected string $snapshotable) {}
|
||||
|
||||
public function __toString()
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->snapshotable;
|
||||
}
|
||||
@@ -54,14 +54,14 @@ test('pass with `__toString`', function () {
|
||||
expect($object)->toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('pass with `toString`', function () {
|
||||
test('pass with `toString`', function (): void {
|
||||
TestSuite::getInstance()->snapshots->save($this->snapshotable);
|
||||
|
||||
$object = new class($this->snapshotable)
|
||||
{
|
||||
public function __construct(protected string $snapshotable) {}
|
||||
|
||||
public function toString()
|
||||
public function toString(): string
|
||||
{
|
||||
return $this->snapshotable;
|
||||
}
|
||||
@@ -70,7 +70,7 @@ test('pass with `toString`', function () {
|
||||
expect($object)->toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('pass with dataset', function ($data) {
|
||||
test('pass with dataset', function ($data): void {
|
||||
TestSuite::getInstance()->snapshots->save($this->snapshotable);
|
||||
[$filename] = TestSuite::getInstance()->snapshots->get();
|
||||
|
||||
@@ -79,8 +79,8 @@ test('pass with dataset', function ($data) {
|
||||
->and($this->snapshotable)->toMatchSnapshot();
|
||||
})->with(['my-datas-set-value']);
|
||||
|
||||
describe('within describe', function () {
|
||||
test('pass with dataset', function ($data) {
|
||||
describe('within describe', function (): void {
|
||||
test('pass with dataset', function ($data): void {
|
||||
TestSuite::getInstance()->snapshots->save($this->snapshotable);
|
||||
[$filename] = TestSuite::getInstance()->snapshots->get();
|
||||
|
||||
@@ -90,14 +90,14 @@ describe('within describe', function () {
|
||||
});
|
||||
})->with(['my-datas-set-value']);
|
||||
|
||||
test('pass with `toArray`', function () {
|
||||
test('pass with `toArray`', function (): void {
|
||||
TestSuite::getInstance()->snapshots->save(json_encode(['key' => $this->snapshotable], JSON_PRETTY_PRINT));
|
||||
|
||||
$object = new class($this->snapshotable)
|
||||
{
|
||||
public function __construct(protected string $snapshotable) {}
|
||||
|
||||
public function toArray()
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'key' => $this->snapshotable,
|
||||
@@ -108,7 +108,7 @@ test('pass with `toArray`', function () {
|
||||
expect($object)->toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('pass with array', function () {
|
||||
test('pass with array', function (): void {
|
||||
TestSuite::getInstance()->snapshots->save(json_encode(['key' => $this->snapshotable], JSON_PRETTY_PRINT));
|
||||
|
||||
expect([
|
||||
@@ -116,14 +116,14 @@ test('pass with array', function () {
|
||||
])->toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('pass with `toSnapshot`', function () {
|
||||
test('pass with `toSnapshot`', function (): void {
|
||||
TestSuite::getInstance()->snapshots->save(json_encode(['key' => $this->snapshotable], JSON_PRETTY_PRINT));
|
||||
|
||||
$object = new class($this->snapshotable)
|
||||
{
|
||||
public function __construct(protected string $snapshotable) {}
|
||||
|
||||
public function toSnapshot()
|
||||
public function toSnapshot(): string|false
|
||||
{
|
||||
return json_encode([
|
||||
'key' => $this->snapshotable,
|
||||
@@ -134,34 +134,30 @@ test('pass with `toSnapshot`', function () {
|
||||
expect($object)->toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
TestSuite::getInstance()->snapshots->save($this->snapshotable);
|
||||
|
||||
expect($this->snapshotable)->not->toMatchSnapshot();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('multiple snapshot expectations', function () {
|
||||
expect('foo bar 1')->toMatchSnapshot();
|
||||
|
||||
expect('foo bar 2')->toMatchSnapshot();
|
||||
test('multiple snapshot expectations', function (): void {
|
||||
expect('foo bar 1')->toMatchSnapshot()
|
||||
->and('foo bar 2')->toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('multiple snapshot expectations with datasets', function () {
|
||||
expect('foo bar 1')->toMatchSnapshot();
|
||||
|
||||
expect('foo bar 2')->toMatchSnapshot();
|
||||
test('multiple snapshot expectations with datasets', function (): void {
|
||||
expect('foo bar 1')->toMatchSnapshot()
|
||||
->and('foo bar 2')->toMatchSnapshot();
|
||||
})->with([1, 'foo', 'bar', 'baz']);
|
||||
|
||||
describe('describable', function () {
|
||||
test('multiple snapshot expectations with describe', function () {
|
||||
expect('foo bar 1')->toMatchSnapshot();
|
||||
|
||||
expect('foo bar 2')->toMatchSnapshot();
|
||||
describe('describable', function (): void {
|
||||
test('multiple snapshot expectations with describe', function (): void {
|
||||
expect('foo bar 1')->toMatchSnapshot()
|
||||
->and('foo bar 2')->toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
test('multiple snapshot expectations with repeat', function () {
|
||||
expect('foo bar 1')->toMatchSnapshot();
|
||||
|
||||
expect('foo bar 2')->toMatchSnapshot();
|
||||
test('multiple snapshot expectations with repeat', function (): void {
|
||||
expect('foo bar 1')->toMatchSnapshot()
|
||||
->and('foo bar 2')->toMatchSnapshot();
|
||||
})->repeat(10);
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
test('pass', function (): void {
|
||||
expect('username')->toStartWith('user');
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect('username')->toStartWith('password');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect('username')->toStartWith('password', 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
test('not failures', function (): void {
|
||||
expect('username')->not->toStartWith('user');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
@@ -4,118 +4,109 @@ use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
class CustomException extends Exception {}
|
||||
|
||||
test('passes', function () {
|
||||
expect(function () {
|
||||
test('passes', function (): void {
|
||||
expect(function (): void {
|
||||
throw new RuntimeException;
|
||||
})->toThrow(RuntimeException::class);
|
||||
expect(function () {
|
||||
throw new RuntimeException;
|
||||
})->toThrow(Exception::class);
|
||||
expect(function () {
|
||||
throw new RuntimeException;
|
||||
})->toThrow(function (RuntimeException $e) {});
|
||||
expect(function () {
|
||||
throw new RuntimeException('actual message');
|
||||
})->toThrow(function (Exception $e) {
|
||||
expect($e->getMessage())->toBe('actual message');
|
||||
});
|
||||
expect(function () {})->not->toThrow(Exception::class);
|
||||
expect(function () {
|
||||
throw new RuntimeException('actual message');
|
||||
})->toThrow('actual message');
|
||||
expect(function () {
|
||||
throw new Exception;
|
||||
})->not->toThrow(RuntimeException::class);
|
||||
expect(function () {
|
||||
throw new RuntimeException('actual message');
|
||||
})->toThrow(RuntimeException::class, 'actual message');
|
||||
expect(function () {
|
||||
throw new RuntimeException('actual message');
|
||||
})->toThrow(function (RuntimeException $e) {}, 'actual message');
|
||||
expect(function () {
|
||||
throw new CustomException('foo');
|
||||
})->toThrow(new CustomException('foo'));
|
||||
})->toThrow(RuntimeException::class)
|
||||
->toThrow(Exception::class)
|
||||
->toThrow(function (RuntimeException $e): void {})
|
||||
->and(function (): void {
|
||||
throw new RuntimeException('actual message');
|
||||
})->toThrow(function (Exception $e): void {
|
||||
expect($e->getMessage())->toBe('actual message');
|
||||
})
|
||||
->and(function (): void {})->not->toThrow(Exception::class)
|
||||
->and(function (): void {
|
||||
throw new RuntimeException('actual message');
|
||||
})->toThrow('actual message')
|
||||
->and(function (): void {
|
||||
throw new Exception;
|
||||
})->not->toThrow(RuntimeException::class)
|
||||
->and(function (): void {
|
||||
throw new RuntimeException('actual message');
|
||||
})->toThrow(RuntimeException::class, 'actual message')
|
||||
->toThrow(function (RuntimeException $e): void {}, 'actual message')
|
||||
->and(function (): void {
|
||||
throw new CustomException('foo');
|
||||
})->toThrow(new CustomException('foo'));
|
||||
});
|
||||
|
||||
test('failures 1', function () {
|
||||
expect(function () {})->toThrow(RuntimeException::class);
|
||||
test('failures 1', function (): void {
|
||||
expect(function (): void {})->toThrow(RuntimeException::class);
|
||||
})->throws(ExpectationFailedException::class, 'Exception "'.RuntimeException::class.'" not thrown.');
|
||||
|
||||
test('failures 2', function () {
|
||||
expect(function () {})->toThrow(function (RuntimeException $e) {});
|
||||
test('failures 2', function (): void {
|
||||
expect(function (): void {})->toThrow(function (RuntimeException $e): void {});
|
||||
})->throws(ExpectationFailedException::class, 'Exception "'.RuntimeException::class.'" not thrown.');
|
||||
|
||||
test('failures 3', function () {
|
||||
expect(function () {
|
||||
test('failures 3', function (): void {
|
||||
expect(function (): void {
|
||||
throw new Exception;
|
||||
})->toThrow(function (RuntimeException $e) {
|
||||
})->toThrow(function (RuntimeException $e): void {
|
||||
//
|
||||
});
|
||||
})->throws(ExpectationFailedException::class, 'Failed asserting that an instance of class Exception is an instance of class RuntimeException.');
|
||||
|
||||
test('failures 4', function () {
|
||||
expect(function () {
|
||||
test('failures 4', function (): void {
|
||||
expect(function (): void {
|
||||
throw new Exception('actual message');
|
||||
})
|
||||
->toThrow(function (Exception $e) {
|
||||
->toThrow(function (Exception $e): void {
|
||||
expect($e->getMessage())->toBe('expected message');
|
||||
});
|
||||
})->throws(ExpectationFailedException::class, 'Failed asserting that two strings are identical');
|
||||
|
||||
test('failures 5', function () {
|
||||
expect(function () {
|
||||
test('failures 5', function (): void {
|
||||
expect(function (): void {
|
||||
throw new Exception('actual message');
|
||||
})->toThrow('expected message');
|
||||
})->throws(ExpectationFailedException::class, 'Failed asserting that \'actual message\' [ASCII](length: 14) contains "expected message" [ASCII](length: 16).');
|
||||
|
||||
test('failures 6', function () {
|
||||
expect(function () {})->toThrow('actual message');
|
||||
test('failures 6', function (): void {
|
||||
expect(function (): void {})->toThrow('actual message');
|
||||
})->throws(ExpectationFailedException::class, 'Exception with message "actual message" not thrown');
|
||||
|
||||
test('failures 7', function () {
|
||||
expect(function () {
|
||||
test('failures 7', function (): void {
|
||||
expect(function (): void {
|
||||
throw new RuntimeException('actual message');
|
||||
})->toThrow(RuntimeException::class, 'expected message');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures 8', function () {
|
||||
expect(function () {
|
||||
test('failures 8', function (): void {
|
||||
expect(function (): void {
|
||||
throw new CustomException('actual message');
|
||||
})->toThrow(new CustomException('expected message'));
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
expect(function () {
|
||||
test('failures with custom message', function (): void {
|
||||
expect(function (): void {
|
||||
throw new RuntimeException('actual message');
|
||||
})->toThrow(RuntimeException::class, 'expected message', 'oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('not failures', function () {
|
||||
expect(function () {
|
||||
test('not failures', function (): void {
|
||||
expect(function (): void {
|
||||
throw new RuntimeException;
|
||||
})->not->toThrow(RuntimeException::class);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('closure missing parameter', function () {
|
||||
expect(function () {})->toThrow(function () {});
|
||||
test('closure missing parameter', function (): void {
|
||||
expect(function (): void {})->toThrow(function (): void {});
|
||||
})->throws(InvalidArgumentException::class, 'The given closure must have a single parameter type-hinted as the class string.');
|
||||
|
||||
test('closure missing type-hint', function () {
|
||||
expect(function () {})->toThrow(function ($e) {});
|
||||
test('closure missing type-hint', function (): void {
|
||||
expect(function (): void {})->toThrow(function ($e): void {});
|
||||
})->throws(InvalidArgumentException::class, 'The given closure\'s parameter must be type-hinted as the class string.');
|
||||
|
||||
it('can handle a non-defined exception', function () {
|
||||
expect(function () {
|
||||
it('can handle a non-defined exception', function (): void {
|
||||
expect(function (): void {
|
||||
throw new NonExistingException;
|
||||
})->toThrow(NonExistingException::class);
|
||||
})->throws(Error::class, 'Class "NonExistingException" not found');
|
||||
|
||||
it('can handle a class not found Error', function () {
|
||||
expect(function () {
|
||||
it('can handle a class not found Error', function (): void {
|
||||
expect(function (): void {
|
||||
throw new NonExistingException;
|
||||
})->toThrow('Class "NonExistingException" not found');
|
||||
|
||||
expect(function () {
|
||||
throw new NonExistingException;
|
||||
})->toThrow(Error::class, 'Class "NonExistingException" not found');
|
||||
})->toThrow('Class "NonExistingException" not found')
|
||||
->toThrow(Error::class, 'Class "NonExistingException" not found');
|
||||
});
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
<?php
|
||||
|
||||
use Pest\Arch\Exceptions\ArchExpectationFailedException;
|
||||
use Tests\Fixtures\Arch\ToUseStrictEquality\NotStrictEquality;
|
||||
use Tests\Fixtures\Arch\ToUseStrictEquality\StrictEquality;
|
||||
|
||||
test('missing strict equality')
|
||||
->throws(ArchExpectationFailedException::class)
|
||||
->expect('Tests\\Fixtures\\Arch\\ToUseStrictEquality\\NotStrictEquality')
|
||||
->expect(NotStrictEquality::class)
|
||||
->toUseStrictEquality();
|
||||
|
||||
test('has strict equality')
|
||||
->expect('Tests\\Fixtures\\Arch\\ToUseStrictEquality\\StrictEquality')
|
||||
->expect(StrictEquality::class)
|
||||
->toUseStrictEquality();
|
||||
|
||||
test('opposite missing strict equality')
|
||||
->throws(ArchExpectationFailedException::class)
|
||||
->expect('Tests\\Fixtures\\Arch\\ToUseStrictEquality\\StrictEquality')
|
||||
->expect(StrictEquality::class)
|
||||
->not->toUseStrictEquality();
|
||||
|
||||
test('opposite has strict equality')
|
||||
->expect('Tests\\Fixtures\\Arch\\ToUseStrictEquality\\NotStrictEquality')
|
||||
->expect(NotStrictEquality::class)
|
||||
->not->toUseStrictEquality();
|
||||
|
||||
@@ -7,11 +7,11 @@ use Tests\Fixtures\Arch\ToUseStrictTypes\HasNoStrictType;
|
||||
use Tests\Fixtures\Arch\ToUseStrictTypes\HasStrictType;
|
||||
use Tests\Fixtures\Arch\ToUseStrictTypes\HasStrictTypeWithCommentsAbove;
|
||||
|
||||
test('pass', function () {
|
||||
test('pass', function (): void {
|
||||
expect(HasStrictType::class)->toUseStrictTypes()
|
||||
->and(HasStrictTypeWithCommentsAbove::class)->toUseStrictTypes();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
test('failures', function (): void {
|
||||
expect(HasNoStrictType::class)->toUseStrictTypes();
|
||||
})->throws(ArchExpectationFailedException::class);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user