chore: coding style changes

This commit is contained in:
nuno maduro
2026-08-07 14:52:56 +01:00
parent eb88513baf
commit 42d9b777bf
221 changed files with 139 additions and 3086 deletions
+11 -22
View File
@@ -10,13 +10,9 @@ it('expects on each item', function (): void {
expect([1, 1, 1])
->each()
->toEqual(1)
->and(static::getCount())->toBe(3); // + 1 assertion
expect([1, 1, 1])
->each
->toEqual(1);
expect(static::getCount())->toBe(7);
->and(static::getCount())->toBe(3)
->and([1, 1, 1])->each->toEqual(1)
->and(static::getCount())->toBe(7);
});
it('chains expectations on each item', function (): void {
@@ -24,14 +20,8 @@ it('chains expectations on each item', function (): void {
->each()
->toBeInt()
->toEqual(1)
->and(static::getCount())->toBe(6); // + 1 assertion
expect([2, 2, 2])
->each
->toBeInt
->toEqual(2);
expect(static::getCount())->toBe(13);
->and(static::getCount())->toBe(6)->and([2, 2, 2])->each->toBeInt->toEqual(2)
->and(static::getCount())->toBe(13);
});
test('opposite expectations on each item', function (): void {
@@ -60,18 +50,17 @@ test('chained opposite and non-opposite expectations', function (): void {
it('can add expectations via "and"', function (): void {
expect([1, 2, 3])
->each()
->toBeInt // + 3
->toBeInt
->and([4, 5, 6])
->each
->toBeLessThan(7) // + 3
->toBeLessThan(7)
->not
->toBeLessThan(3)
->toBeGreaterThan(3) // + 3
->toBeGreaterThan(3)
->and('Hello World')
->toBeString // + 1
->toEqual('Hello World'); // + 1
expect(static::getCount())->toBe(14);
->toBeString
->toEqual('Hello World')
->and(static::getCount())->toBe(14);
});
it('accepts callables', function (): void {
+3 -20
View File
@@ -12,7 +12,7 @@ class Number
public function __construct(
public int $value
) {
// ..
//
}
}
@@ -21,7 +21,7 @@ class Char
public function __construct(
public string $value
) {
// ..
//
}
}
@@ -30,7 +30,7 @@ class Symbol
public function __construct(
public string $value
) {
// ..
//
}
}
@@ -58,9 +58,6 @@ class State
$state = new State;
/*
* Overrides toBe to assert two Characters are the same
*/
expect()->pipe('toBe', function ($next, $expected) use ($state): void {
$state->runCount['char']++;
@@ -70,17 +67,12 @@ expect()->pipe('toBe', function ($next, $expected) use ($state): void {
assertInstanceOf(Char::class, $expected);
assertEquals($this->value->value, $expected->value);
// returning nothing stops pipeline execution
return;
}
// calling $next(); let the pipeline to keep running
$next();
});
/*
* Overrides toBe to assert two Number objects are the same
*/
expect()->intercept('toBe', Number::class, function ($expected) use ($state): void {
$state->runCount['number']++;
$state->appliedCount['number']++;
@@ -89,17 +81,11 @@ expect()->intercept('toBe', Number::class, function ($expected) use ($state): vo
assertEquals($this->value->value, $expected->value);
});
/*
* 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): void {
$state->runCount['wildcard']++;
$state->appliedCount['wildcard']++;
});
/*
* Overrides toBe to assert to Symbols are the same
*/
expect()->pipe('toBe', function ($next, $expected) use ($state): void {
$state->runCount['symbol']++;
@@ -114,9 +100,6 @@ expect()->pipe('toBe', function ($next, $expected) use ($state): void {
$next();
});
/*
* Overrides toBe to allow ignoring case when checking strings
*/
expect()->intercept('toBe', fn ($value) => is_string($value), function ($expected, $ignoreCase = false): void {
if ($ignoreCase) {
assertEqualsIgnoringCase($expected, $this->value);
+5 -5
View File
@@ -6,11 +6,11 @@ use Pest\Exceptions\InvalidExpectationValue;
use PHPUnit\Framework\ExpectationFailedException;
test('pass', function (): void {
expect('Zm9v')->toBeBase64() // 'foo' (no padding)
->and('Zm9vYg==')->toBeBase64() // 'foob' (with padding)
->and('Zm9vYmE=')->toBeBase64() // 'fooba' (with padding)
->and('Zm9vYmFy')->toBeBase64() // 'foobar' (no padding)
->and('')->toBeBase64(); // empty string
expect('Zm9v')->toBeBase64()
->and('Zm9vYg==')->toBeBase64()
->and('Zm9vYmE=')->toBeBase64()
->and('Zm9vYmFy')->toBeBase64()
->and('')->toBeBase64();
});
test('failures', function (): void {
+4 -4
View File
@@ -6,10 +6,10 @@ use Pest\Exceptions\InvalidExpectationValue;
use PHPUnit\Framework\ExpectationFailedException;
test('pass', function (): void {
expect('example.com')->toBeDomain() // standard domain
->and('sub.example.com')->toBeDomain() // subdomain
->and('my-host.io')->toBeDomain() // with hyphen
->and('example.co.uk')->toBeDomain(); // multi-level TLD
expect('example.com')->toBeDomain()
->and('sub.example.com')->toBeDomain()
->and('my-host.io')->toBeDomain()
->and('example.co.uk')->toBeDomain();
});
test('failures', function (): void {
+5 -5
View File
@@ -6,11 +6,11 @@ use Pest\Exceptions\InvalidExpectationValue;
use PHPUnit\Framework\ExpectationFailedException;
test('pass', function (): void {
expect('abcdef')->toBeHexadecimal() // lowercase
->and('ABCDEF')->toBeHexadecimal() // uppercase
->and('aBcDeF')->toBeHexadecimal() // mixed case
->and('1234567890')->toBeHexadecimal() // numeric
->and('deadbeef')->toBeHexadecimal(); // alphanumeric
expect('abcdef')->toBeHexadecimal()
->and('ABCDEF')->toBeHexadecimal()
->and('aBcDeF')->toBeHexadecimal()
->and('1234567890')->toBeHexadecimal()
->and('deadbeef')->toBeHexadecimal();
});
test('failures', function (): void {
+4 -4
View File
@@ -6,10 +6,10 @@ use Pest\Exceptions\InvalidExpectationValue;
use PHPUnit\Framework\ExpectationFailedException;
test('pass', function (): void {
expect('example')->toBeHostname() // single label
->and('example.com')->toBeHostname() // multiple labels
->and('sub.example.com')->toBeHostname() // subdomain
->and('my-host')->toBeHostname(); // with hyphen
expect('example')->toBeHostname()
->and('example.com')->toBeHostname()
->and('sub.example.com')->toBeHostname()
->and('my-host')->toBeHostname();
});
test('failures', function (): void {
+2 -2
View File
@@ -6,8 +6,8 @@ use Pest\Exceptions\InvalidExpectationValue;
use PHPUnit\Framework\ExpectationFailedException;
test('pass', function (): void {
expect('00:1a:2b:3c:4d:5e')->toBeMacAddress() // colon-separated
->and('00-1a-2b-3c-4d-5e')->toBeMacAddress() // hyphen-separated
expect('00:1a:2b:3c:4d:5e')->toBeMacAddress()
->and('00-1a-2b-3c-4d-5e')->toBeMacAddress()
->and('ff:ff:ff:ff:ff:ff')->toBeMacAddress();
});
+8 -8
View File
@@ -10,14 +10,14 @@ test('failures with wrong type', function (): void {
})->throws(InvalidExpectationValue::class, 'Invalid expectation value type. Expected [string].');
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
expect('ca0a8228-cdf6-41db-b34b-c2f31485796c')->toBeUuid(); // version 4
expect('a35477ae-bfb1-5f2e-b5a4-4711594d855f')->toBeUuid(); // version 5
expect('1ee43263-cf5a-6fd8-8f47-846993788c86')->toBeUuid(); // version 6
expect('018a2bef-09f2-728c-becb-c3f569d91486')->toBeUuid(); // version 7
expect('00112233-4455-8677-8899-aabbccddeeff')->toBeUuid(); // version 8
expect('3cafb226-4326-11ee-a516-846993788c86')->toBeUuid()
->and('0000415c-4326-21ee-a700-846993788c86')->toBeUuid()
->and('3f703955-aaba-3e70-a3cb-baff6aa3b28f')->toBeUuid()
->and('ca0a8228-cdf6-41db-b34b-c2f31485796c')->toBeUuid()
->and('a35477ae-bfb1-5f2e-b5a4-4711594d855f')->toBeUuid()
->and('1ee43263-cf5a-6fd8-8f47-846993788c86')->toBeUuid()
->and('018a2bef-09f2-728c-becb-c3f569d91486')->toBeUuid()
->and('00112233-4455-8677-8899-aabbccddeeff')->toBeUuid();
});
test('failures', function (): void {
@@ -1,5 +1,3 @@
<?php
declare(strict_types=1);
// ...
@@ -2,12 +2,10 @@
use Pest\Arch\Exceptions\ArchExpectationFailedException;
use Pest\Configuration;
use Pest\Expectation;
use Tests\Fixtures\Inheritance\ExampleTest;
it('passes', function (): void {
expect(Expectation::class)->toHaveMethodsDocumented()
->and(ExampleTest::class)->not->toHaveMethodsDocumented();
expect(ExampleTest::class)->not->toHaveMethodsDocumented();
});
it('fails 1', function (): void {
+3 -9
View File
@@ -41,15 +41,11 @@ it('skips with falsy', function (): void {
expect($this->unlessObject)
->unless(
1,
function ($value) {
return $value->trueValue->toBeFalse(); // fails
}
fn ($value) => $value->trueValue->toBeFalse()
)
->unless(
true,
function ($value) {
return $value->trueValue->toBeFalse(); // fails
}
fn ($value) => $value->trueValue->toBeFalse()
)
->foo->toEqual('foo')
->and(static::getCount())->toBe(1);
@@ -69,9 +65,7 @@ it('skips with falsy closure condition', function (): void {
expect($this->unlessObject)
->unless(
fn (): string => '1',
function ($value) {
return $value->trueValue->toBeFalse(); // fails
}
fn ($value) => $value->trueValue->toBeFalse()
)
->foo->toEqual('foo')
->and(static::getCount())->toBe(1);
+3 -9
View File
@@ -41,15 +41,11 @@ it('skips with falsy', function (): void {
expect($this->whenObject)
->when(
0,
function ($value) {
return $value->trueValue->toBeFalse(); // fails
}
fn ($value) => $value->trueValue->toBeFalse()
)
->when(
false,
function ($value) {
return $value->trueValue->toBeFalse(); // fails
}
fn ($value) => $value->trueValue->toBeFalse()
)
->foo->toEqual('foo')
->and(static::getCount())->toBe(1);
@@ -69,9 +65,7 @@ it('skips with falsy closure condition', function (): void {
expect($this->whenObject)
->when(
fn (): string => '0',
function ($value) {
return $value->trueValue->toBeFalse(); // fails
}
fn ($value) => $value->trueValue->toBeFalse()
)
->foo->toEqual('foo')
->and(static::getCount())->toBe(1);