mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
Adjust style
This commit is contained in:
@ -10,9 +10,7 @@ use Tests\Fixtures\Covers\CoversTrait;
|
||||
|
||||
$runCounter = 0;
|
||||
|
||||
function testCoversFunction()
|
||||
{
|
||||
}
|
||||
function testCoversFunction() {}
|
||||
|
||||
it('uses the correct PHPUnit attribute for class', function () {
|
||||
$attributes = (new ReflectionClass($this))->getAttributes();
|
||||
|
||||
@ -3,8 +3,7 @@
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect(function () {
|
||||
})->toBeCallable();
|
||||
expect(function () {})->toBeCallable();
|
||||
expect(null)->not->toBeCallable();
|
||||
});
|
||||
|
||||
|
||||
@ -4,13 +4,9 @@ use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
$object = new class
|
||||
{
|
||||
public function foo(): void
|
||||
{
|
||||
}
|
||||
public function foo(): void {}
|
||||
|
||||
public function bar(): void
|
||||
{
|
||||
}
|
||||
public function bar(): void {}
|
||||
};
|
||||
|
||||
test('pass', function () use ($object) {
|
||||
|
||||
@ -43,9 +43,7 @@ test('pass with `__toString`', function () {
|
||||
|
||||
$object = new class($this->snapshotable)
|
||||
{
|
||||
public function __construct(protected string $snapshotable)
|
||||
{
|
||||
}
|
||||
public function __construct(protected string $snapshotable) {}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
@ -61,9 +59,7 @@ test('pass with `toString`', function () {
|
||||
|
||||
$object = new class($this->snapshotable)
|
||||
{
|
||||
public function __construct(protected string $snapshotable)
|
||||
{
|
||||
}
|
||||
public function __construct(protected string $snapshotable) {}
|
||||
|
||||
public function toString()
|
||||
{
|
||||
@ -97,9 +93,7 @@ test('pass with `toArray`', function () {
|
||||
|
||||
$object = new class($this->snapshotable)
|
||||
{
|
||||
public function __construct(protected string $snapshotable)
|
||||
{
|
||||
}
|
||||
public function __construct(protected string $snapshotable) {}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
@ -125,9 +119,7 @@ test('pass with `toSnapshot`', function () {
|
||||
|
||||
$object = new class($this->snapshotable)
|
||||
{
|
||||
public function __construct(protected string $snapshotable)
|
||||
{
|
||||
}
|
||||
public function __construct(protected string $snapshotable) {}
|
||||
|
||||
public function toSnapshot()
|
||||
{
|
||||
|
||||
@ -2,9 +2,7 @@
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
class CustomException extends Exception
|
||||
{
|
||||
}
|
||||
class CustomException extends Exception {}
|
||||
|
||||
test('passes', function () {
|
||||
expect(function () {
|
||||
@ -15,15 +13,13 @@ test('passes', function () {
|
||||
})->toThrow(Exception::class);
|
||||
expect(function () {
|
||||
throw new RuntimeException();
|
||||
})->toThrow(function (RuntimeException $e) {
|
||||
});
|
||||
})->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 () {})->not->toThrow(Exception::class);
|
||||
expect(function () {
|
||||
throw new RuntimeException('actual message');
|
||||
})->toThrow('actual message');
|
||||
@ -35,22 +31,18 @@ test('passes', function () {
|
||||
})->toThrow(RuntimeException::class, 'actual message');
|
||||
expect(function () {
|
||||
throw new RuntimeException('actual message');
|
||||
})->toThrow(function (RuntimeException $e) {
|
||||
}, 'actual message');
|
||||
})->toThrow(function (RuntimeException $e) {}, 'actual message');
|
||||
expect(function () {
|
||||
throw new CustomException('foo');
|
||||
})->toThrow(new CustomException('foo'));
|
||||
});
|
||||
|
||||
test('failures 1', function () {
|
||||
expect(function () {
|
||||
})->toThrow(RuntimeException::class);
|
||||
expect(function () {})->toThrow(RuntimeException::class);
|
||||
})->throws(ExpectationFailedException::class, 'Exception "'.RuntimeException::class.'" not thrown.');
|
||||
|
||||
test('failures 2', function () {
|
||||
expect(function () {
|
||||
})->toThrow(function (RuntimeException $e) {
|
||||
});
|
||||
expect(function () {})->toThrow(function (RuntimeException $e) {});
|
||||
})->throws(ExpectationFailedException::class, 'Exception "'.RuntimeException::class.'" not thrown.');
|
||||
|
||||
test('failures 3', function () {
|
||||
@ -77,8 +69,7 @@ test('failures 5', function () {
|
||||
})->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');
|
||||
expect(function () {})->toThrow('actual message');
|
||||
})->throws(ExpectationFailedException::class, 'Exception with message "actual message" not thrown');
|
||||
|
||||
test('failures 7', function () {
|
||||
@ -106,15 +97,11 @@ test('not failures', function () {
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('closure missing parameter', function () {
|
||||
expect(function () {
|
||||
})->toThrow(function () {
|
||||
});
|
||||
expect(function () {})->toThrow(function () {});
|
||||
})->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) {
|
||||
});
|
||||
expect(function () {})->toThrow(function ($e) {});
|
||||
})->throws(InvalidArgumentException::class, 'The given closure\'s parameter must be type-hinted as the class string.');
|
||||
|
||||
it('can handle a non-defined exception', function () {
|
||||
|
||||
Reference in New Issue
Block a user