This commit is contained in:
Nuno Maduro
2024-07-24 21:54:52 +01:00
parent 101e26749a
commit 45cce6ce93
57 changed files with 131 additions and 131 deletions

View File

@ -1,6 +1,6 @@
<?php
$state = new stdClass();
$state = new stdClass;
beforeEach(function () use ($state) {
$this->state = $state;

View File

@ -1,6 +1,6 @@
<?php
$foo = new \stdClass();
$foo = new \stdClass;
$foo->bar = 0;
beforeAll(function () use ($foo) {

View File

@ -7,7 +7,7 @@ use Symfony\Component\Console\Output\ConsoleOutput;
it('has plugin')->assertTrue(class_exists(CoveragePlugin::class));
it('adds coverage if --coverage exist', function () {
$plugin = new CoveragePlugin(new ConsoleOutput());
$plugin = new CoveragePlugin(new ConsoleOutput);
expect($plugin->coverage)->toBeFalse();
$arguments = $plugin->handleArguments([]);
@ -20,7 +20,7 @@ it('adds coverage if --coverage exist', function () {
})->skip(! \Pest\Support\Coverage::isAvailable() || ! function_exists('xdebug_info') || ! in_array('coverage', xdebug_info('mode'), true), 'Coverage is not available');
it('adds coverage if --min exist', function () {
$plugin = new CoveragePlugin(new ConsoleOutput());
$plugin = new CoveragePlugin(new ConsoleOutput);
expect($plugin->coverageMin)->toEqual(0.0)
->and($plugin->coverage)->toBeFalse();
@ -35,7 +35,7 @@ it('adds coverage if --min exist', function () {
});
it('generates coverage based on file input', function () {
expect(Coverage::getMissingCoverage(new class()
expect(Coverage::getMissingCoverage(new class
{
public function lineCoverageData(): array
{

View File

@ -46,7 +46,7 @@ test('it truncates the description', function () {
// it gets tested by the integration test
})->with([str_repeat('Fooo', 10)]);
$state = new stdClass();
$state = new stdClass;
$state->text = '';
$datasets = [[1], [2]];
@ -130,7 +130,7 @@ class Bar
}
$namedDatasets = [
new Bar(),
new Bar,
];
test('lazy named datasets', function ($text) {
@ -143,12 +143,12 @@ it('creates unique test case names', function (string $name, Plugin $plugin, boo
expect(true)->toBeTrue();
$counter++;
})->with([
['Name 1', new Plugin(), true],
['Name 1', new Plugin(), true],
['Name 1', new Plugin(), false],
['Name 2', new Plugin(), false],
['Name 2', new Plugin(), true],
['Name 1', new Plugin(), true],
['Name 1', new Plugin, true],
['Name 1', new Plugin, true],
['Name 1', new Plugin, false],
['Name 2', new Plugin, false],
['Name 2', new Plugin, true],
['Name 1', new Plugin, true],
]);
it('creates unique test case names - count', function () use (&$counter) {
@ -241,7 +241,7 @@ test('more than two datasets did the job right', function () use ($state) {
expect($state->text)->toBe('121212121212131423241314232411122122111221221112212213142324135136145146235236245246');
});
$wrapped_generator_state = new stdClass();
$wrapped_generator_state = new stdClass;
$wrapped_generator_state->text = '';
$wrapped_generator_function_datasets = [1, 2, 3, 4];

View File

@ -3,7 +3,7 @@
it('gives access the the underlying expectException', function () {
$this->expectException(InvalidArgumentException::class);
throw new InvalidArgumentException();
throw new InvalidArgumentException;
});
it('catch exceptions', function () {

View File

@ -1,29 +1,29 @@
<?php
it('can access methods', function () {
expect(new HasMethods())
expect(new HasMethods)
->name()->toBeString()->toEqual('Has Methods');
});
it('can access multiple methods', function () {
expect(new HasMethods())
expect(new HasMethods)
->name()->toBeString()->toEqual('Has Methods')
->quantity()->toBeInt()->toEqual(20);
});
it('works with not', function () {
expect(new HasMethods())
expect(new HasMethods)
->name()->not->toEqual('world')->toEqual('Has Methods')
->quantity()->toEqual(20)->not()->toEqual('bar')->not->toBeNull;
});
it('can accept arguments', function () {
expect(new HasMethods())
expect(new HasMethods)
->multiply(5, 4)->toBeInt->toEqual(20);
});
it('works with each', function () {
expect(new HasMethods())
expect(new HasMethods)
->attributes()->toBeArray->each->not()->toBeNull
->attributes()->each(function ($attribute) {
$attribute->not->toBeNull();
@ -31,14 +31,14 @@ it('works with each', function () {
});
it('works inside of each', function () {
expect(new HasMethods())
expect(new HasMethods)
->books()->each(function ($book) {
$book->title->not->toBeNull->cost->toBeGreaterThan(19);
});
});
it('works with sequence', function () {
expect(new HasMethods())
expect(new HasMethods)
->books()->sequence(
function ($book) {
$book->title->toEqual('Foo')->cost->toEqual(20);
@ -50,7 +50,7 @@ it('works with sequence', function () {
});
it('can compose complex expectations', function () {
expect(new HasMethods())
expect(new HasMethods)
->toBeObject()
->name()->toEqual('Has Methods')->not()->toEqual('bar')
->quantity()->not->toEqual('world')->toEqual(20)->toBeInt
@ -68,7 +68,7 @@ it('can compose complex expectations', function () {
});
it('can handle nested method calls', function () {
expect(new HasMethods())
expect(new HasMethods)
->newInstance()->newInstance()->name()->toEqual('Has Methods')->toBeString()
->newInstance()->name()->toEqual('Has Methods')->not->toBeInt
->name()->toEqual('Has Methods')
@ -76,14 +76,14 @@ it('can handle nested method calls', function () {
});
it('works with higher order tests')
->expect(new HasMethods())
->expect(new HasMethods)
->newInstance()->newInstance()->name()->toEqual('Has Methods')->toBeString()
->newInstance()->name()->toEqual('Has Methods')->not->toBeArray
->name()->toEqual('Has Methods')
->books()->each->toBeArray;
it('can use the scoped method to lock into the given level for expectations', function () {
expect(new HasMethods())
expect(new HasMethods)
->attributes()->scoped(fn ($attributes) => $attributes
->name->toBe('Has Methods')
->quantity->toBe(20)
@ -100,7 +100,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 () {
expect(new HasMethods())
expect(new HasMethods)
->jsonString()->json()->id->toBe(1)
->jsonString()->json()->name->toBe('Has Methods')->toBeString()
->jsonString()->json()->quantity->toBe(20)->toBeInt();
@ -152,6 +152,6 @@ class HasMethods
public function newInstance()
{
return new static();
return new static;
}
}

View File

@ -1,7 +1,7 @@
<?php
it('can access methods and properties', function () {
expect(new HasMethodsAndProperties())
expect(new HasMethodsAndProperties)
->name->toEqual('Has Methods and Properties')->not()->toEqual('bar')
->multiply(3, 4)->not->toBeString->toEqual(12)
->posts->each(function ($post) {
@ -19,7 +19,7 @@ it('can access methods and properties', function () {
});
it('can handle nested methods and properties', function () {
expect(new HasMethodsAndProperties())
expect(new HasMethodsAndProperties)
->meta->foo->bar->toBeString()->toEqual('baz')->not->toBeInt
->newInstance()->meta->foo->toBeArray()
->newInstance()->multiply(2, 2)->toEqual(4)->not->toEqual(5)
@ -27,14 +27,14 @@ it('can handle nested methods and properties', function () {
});
it('works with higher order tests')
->expect(new HasMethodsAndProperties())
->expect(new HasMethodsAndProperties)
->meta->foo->bar->toBeString()->toEqual('baz')->not->toBeInt
->newInstance()->meta->foo->toBeArray
->newInstance()->multiply(2, 2)->toEqual(4)->not->toEqual(5)
->newInstance()->books()->toBeArray();
it('can start a new higher order expectation using the and syntax', function () {
expect(new HasMethodsAndProperties())
expect(new HasMethodsAndProperties)
->toBeInstanceOf(HasMethodsAndProperties::class)
->meta->toBeArray
->and(['foo' => 'bar'])
@ -45,7 +45,7 @@ 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 in higher order tests')
->expect(new HasMethodsAndProperties())
->expect(new HasMethodsAndProperties)
->toBeInstanceOf(HasMethodsAndProperties::class)
->meta->toBeArray
->and(['foo' => 'bar'])
@ -53,7 +53,7 @@ it('can start a new higher order expectation using the and syntax in higher orde
->foo->toEqual('bar');
it('can start a new higher order expectation using the and syntax without nesting expectations', function () {
expect(new HasMethodsAndProperties())
expect(new HasMethodsAndProperties)
->toBeInstanceOf(HasMethodsAndProperties::class)
->meta
->sequence(
@ -101,6 +101,6 @@ class HasMethodsAndProperties
public function newInstance()
{
return new static();
return new static;
}
}

View File

@ -53,7 +53,7 @@ it('can compose complex expectations', function () {
});
it('works with objects', function () {
expect(new HasProperties())
expect(new HasProperties)
->name->toEqual('foo')->not->toEqual('world')
->posts->toHaveCount(2)->each(function ($post) {
$post->is_published->toBeTrue();
@ -69,13 +69,13 @@ it('works with objects', function () {
});
it('works with nested properties', function () {
expect(new HasProperties())
expect(new HasProperties)
->nested->foo->bar->toBeString()->toEqual('baz')
->posts->toBeArray()->toHaveCount(2);
});
it('works with higher order tests')
->expect(new HasProperties())
->expect(new HasProperties)
->nested->foo->bar->toBeString()->toEqual('baz')
->posts->toBeArray()->toHaveCount(2);

View File

@ -56,7 +56,7 @@ class State
}
}
$state = new State();
$state = new State;
/*
* Overrides toBe to assert two Characters are the same

View File

@ -5,8 +5,8 @@ use PHPUnit\Framework\ExpectationFailedException;
expect(true)->toBeTrue()->and(false)->toBeFalse();
test('strict comparisons', function () {
$nuno = new stdClass();
$dries = new stdClass();
$nuno = new stdClass;
$dries = new stdClass;
expect($nuno)->toBe($nuno)->not->toBe($dries);
});

View File

@ -8,8 +8,8 @@ test('passes', function () {
});
test('passes with DateTime and DateTimeImmutable', function () {
$now = new DateTime();
$past = (new DateTimeImmutable())->modify('-1 day');
$now = new DateTime;
$past = (new DateTimeImmutable)->modify('-1 day');
expect($now)->toBeGreaterThan($past);

View File

@ -8,8 +8,8 @@ test('passes', function () {
});
test('passes with DateTime and DateTimeImmutable', function () {
$now = new DateTime();
$past = (new DateTimeImmutable())->modify('-1 day');
$now = new DateTime;
$past = (new DateTimeImmutable)->modify('-1 day');
expect($now)->toBeGreaterThanOrEqual($now);

View File

@ -3,18 +3,18 @@
use PHPUnit\Framework\ExpectationFailedException;
test('pass', function () {
expect(new Exception())->toBeInstanceOf(Exception::class);
expect(new Exception())->not->toBeInstanceOf(RuntimeException::class);
expect(new Exception)->toBeInstanceOf(Exception::class);
expect(new Exception)->not->toBeInstanceOf(RuntimeException::class);
});
test('failures', function () {
expect(new Exception())->toBeInstanceOf(RuntimeException::class);
expect(new Exception)->toBeInstanceOf(RuntimeException::class);
})->throws(ExpectationFailedException::class);
test('failures with custom message', function () {
expect(new Exception())->toBeInstanceOf(RuntimeException::class, 'oh no!');
expect(new Exception)->toBeInstanceOf(RuntimeException::class, 'oh no!');
})->throws(ExpectationFailedException::class, 'oh no!');
test('not failures', function () {
expect(new Exception())->not->toBeInstanceOf(Exception::class);
expect(new Exception)->not->toBeInstanceOf(Exception::class);
})->throws(ExpectationFailedException::class);

View File

@ -8,8 +8,8 @@ test('passes', function () {
});
test('passes with DateTime and DateTimeImmutable', function () {
$now = new DateTime();
$past = (new DateTimeImmutable())->modify('-1 day');
$now = new DateTime;
$past = (new DateTimeImmutable)->modify('-1 day');
expect($past)->toBeLessThan($now);

View File

@ -8,8 +8,8 @@ test('passes', function () {
});
test('passes with DateTime and DateTimeImmutable', function () {
$now = new DateTime();
$past = (new DateTimeImmutable())->modify('-1 day');
$now = new DateTime;
$past = (new DateTimeImmutable)->modify('-1 day');
expect($now)->toBeLessThanOrEqual($now);

View File

@ -3,7 +3,7 @@
use PHPUnit\Framework\ExpectationFailedException;
beforeEach(function () {
$this->times = [new DateTimeImmutable(), new DateTimeImmutable()];
$this->times = [new DateTimeImmutable, new DateTimeImmutable];
});
test('pass', function () {

View File

@ -3,7 +3,7 @@
use PHPUnit\Framework\ExpectationFailedException;
test('pass', function () {
$object = new stdClass();
$object = new stdClass;
$object->name = 'John';
$object->age = 21;
@ -16,7 +16,7 @@ test('pass', function () {
});
test('failures', function () {
$object = new stdClass();
$object = new stdClass;
$object->name = 'John';
expect($object)
@ -28,7 +28,7 @@ test('failures', function () {
})->throws(ExpectationFailedException::class);
test('failures with custom message', function () {
$object = new stdClass();
$object = new stdClass;
$object->name = 'John';
expect($object)
@ -40,7 +40,7 @@ test('failures with custom message', function () {
})->throws(ExpectationFailedException::class, 'oh no!');
test('not failures', function () {
$object = new stdClass();
$object = new stdClass;
$object->name = 'John';
$object->age = 21;

View File

@ -2,7 +2,7 @@
use PHPUnit\Framework\ExpectationFailedException;
$obj = new stdClass();
$obj = new stdClass;
$obj->foo = 'bar';
$obj->fooNull = null;

View File

@ -4,17 +4,17 @@ use PHPUnit\Framework\Constraint\IsTrue;
use PHPUnit\Framework\ExpectationFailedException;
test('pass', function () {
expect(true)->toMatchConstraint(new IsTrue());
expect(true)->toMatchConstraint(new IsTrue);
});
test('failures', function () {
expect(false)->toMatchConstraint(new IsTrue());
expect(false)->toMatchConstraint(new IsTrue);
})->throws(ExpectationFailedException::class);
test('failures with custom message', function () {
expect(false)->toMatchConstraint(new IsTrue(), 'oh no!');
expect(false)->toMatchConstraint(new IsTrue, 'oh no!');
})->throws(ExpectationFailedException::class, 'oh no!');
test('not failures', function () {
expect(true)->not->toMatchConstraint(new IsTrue());
expect(true)->not->toMatchConstraint(new IsTrue);
})->throws(ExpectationFailedException::class);

View File

@ -18,7 +18,7 @@ test('pass', function () {
});
test('pass with class', function () {
expect(new class()
expect(new class
{
public $name = 'Nuno';

View File

@ -6,13 +6,13 @@ class CustomException extends Exception {}
test('passes', function () {
expect(function () {
throw new RuntimeException();
throw new RuntimeException;
})->toThrow(RuntimeException::class);
expect(function () {
throw new RuntimeException();
throw new RuntimeException;
})->toThrow(Exception::class);
expect(function () {
throw new RuntimeException();
throw new RuntimeException;
})->toThrow(function (RuntimeException $e) {});
expect(function () {
throw new RuntimeException('actual message');
@ -24,7 +24,7 @@ test('passes', function () {
throw new RuntimeException('actual message');
})->toThrow('actual message');
expect(function () {
throw new Exception();
throw new Exception;
})->not->toThrow(RuntimeException::class);
expect(function () {
throw new RuntimeException('actual message');
@ -47,7 +47,7 @@ test('failures 2', function () {
test('failures 3', function () {
expect(function () {
throw new Exception();
throw new Exception;
})->toThrow(function (RuntimeException $e) {
//
});
@ -92,7 +92,7 @@ test('failures with custom message', function () {
test('not failures', function () {
expect(function () {
throw new RuntimeException();
throw new RuntimeException;
})->not->toThrow(RuntimeException::class);
})->throws(ExpectationFailedException::class);
@ -106,16 +106,16 @@ test('closure missing type-hint', function () {
it('can handle a non-defined exception', function () {
expect(function () {
throw new NonExistingException();
throw new NonExistingException;
})->toThrow(NonExistingException::class);
})->throws(Error::class, 'Class "NonExistingException" not found');
it('can handle a class not found Error', function () {
expect(function () {
throw new NonExistingException();
throw new NonExistingException;
})->toThrow('Class "NonExistingException" not found');
expect(function () {
throw new NonExistingException();
throw new NonExistingException;
})->toThrow(Error::class, 'Class "NonExistingException" not found');
});

View File

@ -3,7 +3,7 @@
use PHPUnit\Framework\ExpectationFailedException;
beforeEach(function () {
$this->unlessObject = new stdClass();
$this->unlessObject = new stdClass;
$this->unlessObject->trueValue = true;
$this->unlessObject->foo = 'foo';
});

View File

@ -3,7 +3,7 @@
use PHPUnit\Framework\ExpectationFailedException;
beforeEach(function () {
$this->whenObject = new stdClass();
$this->whenObject = new stdClass;
$this->whenObject->trueValue = true;
$this->whenObject->foo = 'foo';
});

View File

@ -1,6 +1,6 @@
<?php
$state = new stdClass();
$state = new stdClass;
$state->text = '';
test('uses dataset', function ($value) use ($state) {
$state->text .= $value;

View File

@ -1,6 +1,6 @@
<?php
$state = new stdClass();
$state = new stdClass;
$state->text = '';
test('uses dataset', function ($value) use ($state) {
$state->text .= $value;

View File

@ -4,7 +4,7 @@ dataset('numbers.array', [
1, 2, 3, 4, 5, 'ScopedDatasets/ScopedDatasets.php',
]);
$state = new stdClass();
$state = new stdClass;
$state->text = '';
test('uses dataset', function ($value) use ($state) {
$state->text .= $value;

View File

@ -1,6 +1,6 @@
<?php
$state = new stdClass();
$state = new stdClass;
$state->text = '';
test('uses dataset', function ($value) use ($state) {
$state->text .= $value;

View File

@ -1,6 +1,6 @@
<?php
$state = new stdClass();
$state = new stdClass;
$state->text = '';
test('uses dataset', function ($value) use ($state) {
$state->text .= $value;

View File

@ -2,7 +2,7 @@
use function PHPUnit\Framework\assertFalse;
$foo = new stdClass();
$foo = new stdClass;
$foo->beforeAll = false;
$foo->beforeEach = false;
$foo->afterEach = false;