mirror of
https://github.com/pestphp/pest.git
synced 2026-07-24 10:30:03 +02:00
fix: package lock fingerprint
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Pest\PendingCalls\UsesCall;
|
||||
|
||||
it('proxies to uses call', function () {
|
||||
it('proxies to uses call', function (): void {
|
||||
$in = pest()->in();
|
||||
|
||||
expect($in)->toBeInstanceOf(UsesCall::class);
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Pest\Configuration\Printer;
|
||||
|
||||
it('creates a printer instance', function () {
|
||||
it('creates a printer instance', function (): void {
|
||||
$theme = pest()->printer();
|
||||
|
||||
expect($theme)->toBeInstanceOf(Printer::class);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use Pest\Console\Help;
|
||||
use Symfony\Component\Console\Output\BufferedOutput;
|
||||
|
||||
it('outputs the help information when --help is used', function () {
|
||||
it('outputs the help information when --help is used', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$plugin = new Help($output);
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use Pest\Repositories\DatasetsRepository;
|
||||
|
||||
it('show only the names of named datasets in their description', function () {
|
||||
it('show only the names of named datasets in their description', function (): void {
|
||||
$descriptions = array_keys(DatasetsRepository::resolve([
|
||||
[
|
||||
'one' => [1],
|
||||
@@ -14,7 +14,7 @@ it('show only the names of named datasets in their description', function () {
|
||||
->and($descriptions[1])->toBe('dataset "two"');
|
||||
});
|
||||
|
||||
it('show the actual dataset of non-named datasets in their description', function () {
|
||||
it('show the actual dataset of non-named datasets in their description', function (): void {
|
||||
$descriptions = array_keys(DatasetsRepository::resolve([
|
||||
[
|
||||
[1],
|
||||
@@ -22,11 +22,11 @@ it('show the actual dataset of non-named datasets in their description', functio
|
||||
],
|
||||
], __FILE__));
|
||||
|
||||
expect($descriptions[0])->toBe('(1)');
|
||||
expect($descriptions[1])->toBe('([2])');
|
||||
expect($descriptions[0])->toBe('(1)')
|
||||
->and($descriptions[1])->toBe('([2])');
|
||||
});
|
||||
|
||||
it('show only the names of multiple named datasets in their description', function () {
|
||||
it('show only the names of multiple named datasets in their description', function (): void {
|
||||
$descriptions = array_keys(DatasetsRepository::resolve([
|
||||
[
|
||||
'one' => [1],
|
||||
@@ -38,13 +38,13 @@ it('show only the names of multiple named datasets in their description', functi
|
||||
],
|
||||
], __FILE__));
|
||||
|
||||
expect($descriptions[0])->toBe('dataset "one" / dataset "three"');
|
||||
expect($descriptions[1])->toBe('dataset "one" / dataset "four"');
|
||||
expect($descriptions[2])->toBe('dataset "two" / dataset "three"');
|
||||
expect($descriptions[3])->toBe('dataset "two" / dataset "four"');
|
||||
expect($descriptions[0])->toBe('dataset "one" / dataset "three"')
|
||||
->and($descriptions[1])->toBe('dataset "one" / dataset "four"')
|
||||
->and($descriptions[2])->toBe('dataset "two" / dataset "three"')
|
||||
->and($descriptions[3])->toBe('dataset "two" / dataset "four"');
|
||||
});
|
||||
|
||||
it('show the actual dataset of multiple non-named datasets in their description', function () {
|
||||
it('show the actual dataset of multiple non-named datasets in their description', function (): void {
|
||||
$descriptions = array_keys(DatasetsRepository::resolve([
|
||||
[
|
||||
[1],
|
||||
@@ -56,13 +56,13 @@ it('show the actual dataset of multiple non-named datasets in their description'
|
||||
],
|
||||
], __FILE__));
|
||||
|
||||
expect($descriptions[0])->toBe('(1) / (3)');
|
||||
expect($descriptions[1])->toBe('(1) / ([4])');
|
||||
expect($descriptions[2])->toBe('([2]) / (3)');
|
||||
expect($descriptions[3])->toBe('([2]) / ([4])');
|
||||
expect($descriptions[0])->toBe('(1) / (3)')
|
||||
->and($descriptions[1])->toBe('(1) / ([4])')
|
||||
->and($descriptions[2])->toBe('([2]) / (3)')
|
||||
->and($descriptions[3])->toBe('([2]) / ([4])');
|
||||
});
|
||||
|
||||
it('show the correct description for mixed named and not-named datasets', function () {
|
||||
it('show the correct description for mixed named and not-named datasets', function (): void {
|
||||
$descriptions = array_keys(DatasetsRepository::resolve([
|
||||
[
|
||||
'one' => [1],
|
||||
@@ -74,13 +74,13 @@ it('show the correct description for mixed named and not-named datasets', functi
|
||||
],
|
||||
], __FILE__));
|
||||
|
||||
expect($descriptions[0])->toBe('dataset "one" / (3)');
|
||||
expect($descriptions[1])->toBe('dataset "one" / dataset "four"');
|
||||
expect($descriptions[2])->toBe('([2]) / (3)');
|
||||
expect($descriptions[3])->toBe('([2]) / dataset "four"');
|
||||
expect($descriptions[0])->toBe('dataset "one" / (3)')
|
||||
->and($descriptions[1])->toBe('dataset "one" / dataset "four"')
|
||||
->and($descriptions[2])->toBe('([2]) / (3)')
|
||||
->and($descriptions[3])->toBe('([2]) / dataset "four"');
|
||||
});
|
||||
|
||||
it('shows the correct description for long texts with newlines', function () {
|
||||
it('shows the correct description for long texts with newlines', function (): void {
|
||||
$descriptions = array_keys(DatasetsRepository::resolve([
|
||||
[
|
||||
['some very \nlong text with \n newlines'],
|
||||
@@ -90,7 +90,7 @@ it('shows the correct description for long texts with newlines', function () {
|
||||
expect($descriptions[0])->toBe('(\'some very long text with …wlines\')');
|
||||
});
|
||||
|
||||
it('shows the correct description for arrays with many elements', function () {
|
||||
it('shows the correct description for arrays with many elements', function (): void {
|
||||
$descriptions = array_keys(DatasetsRepository::resolve([
|
||||
[
|
||||
[[1, 2, 3, 4, 5]],
|
||||
@@ -100,7 +100,7 @@ it('shows the correct description for arrays with many elements', function () {
|
||||
expect($descriptions[0])->toBe('([1, 2, 3, …])');
|
||||
});
|
||||
|
||||
it('shows the correct description of datasets with html', function () {
|
||||
it('shows the correct description of datasets with html', function (): void {
|
||||
$descriptions = array_keys(DatasetsRepository::resolve([
|
||||
[
|
||||
'<div class="flex items-center"></div>',
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Pest\Expectations\OppositeExpectation;
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use NunoMaduro\Collision\Contracts\RenderableOnCollisionEditor;
|
||||
use PHPUnit\Event\Code\ThrowableBuilder;
|
||||
use Whoops\Exception\Frame;
|
||||
|
||||
test('collision editor can be added to the stack trace', function () {
|
||||
test('collision editor can be added to the stack trace', function (): void {
|
||||
$exception = new class extends Exception implements RenderableOnCollisionEditor
|
||||
{
|
||||
public function __construct()
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use Pest\Plugins\Concerns\HandleArguments;
|
||||
|
||||
test('method hasArgument', function (string $argument, bool $expectedResult) {
|
||||
test('method hasArgument', function (string $argument, bool $expectedResult): void {
|
||||
$obj = new class
|
||||
{
|
||||
use HandleArguments;
|
||||
@@ -25,7 +25,7 @@ test('method hasArgument', function (string $argument, bool $expectedResult) {
|
||||
['--undefined-argument', false],
|
||||
]);
|
||||
|
||||
test('popArgument preserves duplicate values when removing a missing argument', function () {
|
||||
test('popArgument preserves duplicate values when removing a missing argument', function (): void {
|
||||
$obj = new class
|
||||
{
|
||||
use HandleArguments;
|
||||
@@ -37,7 +37,7 @@ test('popArgument preserves duplicate values when removing a missing argument',
|
||||
expect($result)->toBe($arguments);
|
||||
});
|
||||
|
||||
test('popArgument preserves duplicate values when removing an existing argument', function () {
|
||||
test('popArgument preserves duplicate values when removing an existing argument', function (): void {
|
||||
$obj = new class
|
||||
{
|
||||
use HandleArguments;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use Pest\Plugins\Environment;
|
||||
|
||||
test('environment is set to CI when --ci option is used', function () {
|
||||
test('environment is set to CI when --ci option is used', function (): void {
|
||||
$previousName = Environment::name();
|
||||
|
||||
$plugin = new Environment;
|
||||
@@ -14,7 +14,7 @@ test('environment is set to CI when --ci option is used', function () {
|
||||
Environment::name($previousName);
|
||||
});
|
||||
|
||||
test('environment is set to Local when --ci option is not used', function () {
|
||||
test('environment is set to Local when --ci option is not used', function (): void {
|
||||
$plugin = new Environment;
|
||||
|
||||
$plugin->handleArguments(['foo', 'bar', 'baz']);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use Pest\Plugins\Retry;
|
||||
|
||||
it('orders by defects and stop on defects if when --retry is used ', function () {
|
||||
it('orders by defects and stop on defects if when --retry is used ', function (): void {
|
||||
$retry = new Retry;
|
||||
|
||||
$arguments = $retry->handleArguments(['--retry']);
|
||||
|
||||
@@ -5,8 +5,8 @@ use Pest\Plugins\Shard;
|
||||
use Symfony\Component\Console\Input\ArgvInput;
|
||||
use Symfony\Component\Console\Output\BufferedOutput;
|
||||
|
||||
describe('getShard', function () {
|
||||
it('parses valid shard format', function (string $format, int $expectedIndex, int $expectedTotal) {
|
||||
describe('getShard', function (): void {
|
||||
it('parses valid shard format', function (string $format, int $expectedIndex, int $expectedTotal): void {
|
||||
$input = new ArgvInput(['test', '--shard', $format]);
|
||||
|
||||
$result = Shard::getShard($input);
|
||||
@@ -25,7 +25,7 @@ describe('getShard', function () {
|
||||
['5/100', 5, 100],
|
||||
]);
|
||||
|
||||
it('throws exception for invalid format', function (array $arguments) {
|
||||
it('throws exception for invalid format', function (array $arguments): void {
|
||||
$input = new ArgvInput($arguments);
|
||||
|
||||
Shard::getShard($input);
|
||||
@@ -38,7 +38,7 @@ describe('getShard', function () {
|
||||
[['test', '--shard', '1.5/2']],
|
||||
])->throws(InvalidOption::class);
|
||||
|
||||
it('throws exception for invalid index or total values', function (array $arguments) {
|
||||
it('throws exception for invalid index or total values', function (array $arguments): void {
|
||||
$input = new ArgvInput($arguments);
|
||||
|
||||
Shard::getShard($input);
|
||||
@@ -50,8 +50,8 @@ describe('getShard', function () {
|
||||
])->throws(InvalidOption::class);
|
||||
});
|
||||
|
||||
describe('buildFilterArgument', function () {
|
||||
it('generates compact filter for single test', function () {
|
||||
describe('buildFilterArgument', function (): void {
|
||||
it('generates compact filter for single test', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
@@ -63,7 +63,7 @@ describe('buildFilterArgument', function () {
|
||||
expect($filter)->toBe('Tests\\\\Unit\\\\ExampleTest');
|
||||
});
|
||||
|
||||
it('generates compact filter for multiple tests with common prefix', function () {
|
||||
it('generates compact filter for multiple tests with common prefix', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
@@ -78,7 +78,7 @@ describe('buildFilterArgument', function () {
|
||||
expect($filter)->toBe('Tests\\\\Unit\\\\Foo\\\\(BarTest|BazTest)');
|
||||
});
|
||||
|
||||
it('generates compact filter for tests with different namespaces', function () {
|
||||
it('generates compact filter for tests with different namespaces', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
@@ -93,7 +93,7 @@ describe('buildFilterArgument', function () {
|
||||
expect($filter)->toBe('Tests\\\\(Unit\\\\FooTest|Feature\\\\BarTest)');
|
||||
});
|
||||
|
||||
it('returns empty string for empty test list', function () {
|
||||
it('returns empty string for empty test list', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
@@ -102,10 +102,10 @@ describe('buildFilterArgument', function () {
|
||||
|
||||
$filter = $method->invoke($shard, []);
|
||||
|
||||
expect($filter)->toBe('');
|
||||
expect($filter)->toBeEmpty();
|
||||
});
|
||||
|
||||
it('generates compact filter for deeply nested namespaces', function () {
|
||||
it('generates compact filter for deeply nested namespaces', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
@@ -121,7 +121,7 @@ describe('buildFilterArgument', function () {
|
||||
expect($filter)->toBe('Tests\\\\Unit\\\\Plugins\\\\Concerns\\\\(Foo|Bar|Baz)');
|
||||
});
|
||||
|
||||
it('handles mix of nested and flat namespaces', function () {
|
||||
it('handles mix of nested and flat namespaces', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
@@ -142,8 +142,8 @@ describe('buildFilterArgument', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('ensureFilterLengthIsSafe', function () {
|
||||
it('accepts filter within length limit', function () {
|
||||
describe('ensureFilterLengthIsSafe', function (): void {
|
||||
it('accepts filter within length limit', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
@@ -157,7 +157,7 @@ describe('ensureFilterLengthIsSafe', function () {
|
||||
expect(true)->toBeTrue();
|
||||
});
|
||||
|
||||
it('throws exception when filter exceeds default limit', function () {
|
||||
it('throws exception when filter exceeds default limit', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
@@ -169,7 +169,7 @@ describe('ensureFilterLengthIsSafe', function () {
|
||||
$method->invoke($shard, $filter);
|
||||
})->throws(InvalidOption::class, 'The generated filter for this shard is too long');
|
||||
|
||||
it('respects custom limit from environment variable', function () {
|
||||
it('respects custom limit from environment variable', function (): void {
|
||||
putenv('PEST_SHARD_MAX_FILTER_LENGTH=1000');
|
||||
|
||||
$output = new BufferedOutput;
|
||||
@@ -191,7 +191,7 @@ describe('ensureFilterLengthIsSafe', function () {
|
||||
}
|
||||
});
|
||||
|
||||
it('accepts filter within custom limit', function () {
|
||||
it('accepts filter within custom limit', function (): void {
|
||||
putenv('PEST_SHARD_MAX_FILTER_LENGTH=1000');
|
||||
|
||||
$output = new BufferedOutput;
|
||||
@@ -213,8 +213,8 @@ describe('ensureFilterLengthIsSafe', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('handleArguments', function () {
|
||||
it('returns original arguments when shard option is not present', function () {
|
||||
describe('handleArguments', function (): void {
|
||||
it('returns original arguments when shard option is not present', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
@@ -225,7 +225,7 @@ describe('handleArguments', function () {
|
||||
expect($result)->toBe($arguments);
|
||||
});
|
||||
|
||||
it('removes parallel arguments from test discovery', function () {
|
||||
it('removes parallel arguments from test discovery', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
@@ -240,8 +240,8 @@ describe('handleArguments', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseListTestsOutput', function () {
|
||||
it('parses Tests\\ namespaced classes from --list-tests output', function () {
|
||||
describe('parseListTestsOutput', function (): void {
|
||||
it('parses Tests\\ namespaced classes from --list-tests output', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
@@ -262,7 +262,7 @@ OUT;
|
||||
]);
|
||||
});
|
||||
|
||||
it('deduplicates repeated class names from multiple test methods', function () {
|
||||
it('deduplicates repeated class names from multiple test methods', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
@@ -278,18 +278,18 @@ OUT;
|
||||
expect($method->invoke($shard, $listOutput))->toBe(['Tests\\Same']);
|
||||
});
|
||||
|
||||
it('returns an empty list for output with no matching lines', function () {
|
||||
it('returns an empty list for output with no matching lines', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
$reflection = new ReflectionClass($shard);
|
||||
$method = $reflection->getMethod('parseListTestsOutput');
|
||||
|
||||
expect($method->invoke($shard, ''))->toBe([])
|
||||
->and($method->invoke($shard, 'some random text'))->toBe([]);
|
||||
expect($method->invoke($shard, ''))->toBeEmpty()
|
||||
->and($method->invoke($shard, 'some random text'))->toBeEmpty();
|
||||
});
|
||||
|
||||
it('parses non-Tests namespaced classes', function () {
|
||||
it('parses non-Tests namespaced classes', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
@@ -309,7 +309,7 @@ OUT;
|
||||
]);
|
||||
});
|
||||
|
||||
it('parses unnamespaced top-level classes', function () {
|
||||
it('parses unnamespaced top-level classes', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
@@ -319,7 +319,7 @@ OUT;
|
||||
expect($method->invoke($shard, ' - P\FooTest::test_bar'))->toBe(['FooTest']);
|
||||
});
|
||||
|
||||
it('strips the P\\ Pest prefix but keeps the rest of the FQCN', function () {
|
||||
it('strips the P\\ Pest prefix but keeps the rest of the FQCN', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
@@ -337,7 +337,7 @@ OUT;
|
||||
]);
|
||||
});
|
||||
|
||||
it('ignores junk lines that lack the " - …::" framing', function () {
|
||||
it('ignores junk lines that lack the " - …::" framing', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
@@ -356,8 +356,8 @@ OUT;
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildListTestsCommand', function () {
|
||||
it('builds the list-tests command with the forwarded --test-directory', function () {
|
||||
describe('buildListTestsCommand', function (): void {
|
||||
it('builds the list-tests command with the forwarded --test-directory', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
@@ -375,7 +375,7 @@ describe('buildListTestsCommand', function () {
|
||||
]);
|
||||
});
|
||||
|
||||
it('strips --parallel and -p when building the list-tests command', function () {
|
||||
it('strips --parallel and -p when building the list-tests command', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
@@ -393,7 +393,7 @@ describe('buildListTestsCommand', function () {
|
||||
]);
|
||||
});
|
||||
|
||||
it('forwards --test-directory even when input arguments include one', function () {
|
||||
it('forwards --test-directory even when input arguments include one', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
@@ -405,7 +405,7 @@ describe('buildListTestsCommand', function () {
|
||||
expect($command)->toContain('--test-directory=suites');
|
||||
});
|
||||
|
||||
it('strips --processes=N when building the list-tests command', function () {
|
||||
it('strips --processes=N when building the list-tests command', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
@@ -423,7 +423,7 @@ describe('buildListTestsCommand', function () {
|
||||
]);
|
||||
});
|
||||
|
||||
it('strips --processes N (space-separated) when building the list-tests command', function () {
|
||||
it('strips --processes N (space-separated) when building the list-tests command', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
@@ -438,8 +438,8 @@ describe('buildListTestsCommand', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('addOutput', function () {
|
||||
it('displays shard information after test execution', function () {
|
||||
describe('addOutput', function (): void {
|
||||
it('displays shard information after test execution', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
@@ -462,7 +462,7 @@ describe('addOutput', function () {
|
||||
->and($outputText)->toContain('out of 100');
|
||||
});
|
||||
|
||||
it('uses singular form for single test file', function () {
|
||||
it('uses singular form for single test file', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
@@ -482,7 +482,7 @@ describe('addOutput', function () {
|
||||
->and($outputText)->not->toContain('1 files');
|
||||
});
|
||||
|
||||
it('returns original exit code when shard is not set', function () {
|
||||
it('returns original exit code when shard is not set', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
use Pest\Plugins\Tia\ContentHash;
|
||||
|
||||
describe('of()', function () {
|
||||
it('returns false when file does not exist', function () {
|
||||
describe('of()', function (): void {
|
||||
it('returns false when file does not exist', function (): void {
|
||||
expect(ContentHash::of('/path/that/does/not/exist.php'))->toBeFalse();
|
||||
});
|
||||
|
||||
it('hashes an existing file', function () {
|
||||
it('hashes an existing file', function (): void {
|
||||
$path = tempnam(sys_get_temp_dir(), 'pest_').'.php';
|
||||
file_put_contents($path, "<?php echo 'hi';");
|
||||
|
||||
@@ -19,70 +19,70 @@ describe('of()', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('PHP files', function () {
|
||||
it('produces the same hash regardless of whitespace differences', function () {
|
||||
describe('PHP files', function (): void {
|
||||
it('produces the same hash regardless of whitespace differences', function (): void {
|
||||
$a = ContentHash::ofContent('a.php', "<?php \$foo = 1;\n\necho \$foo;");
|
||||
$b = ContentHash::ofContent('a.php', '<?php $foo=1; echo $foo;');
|
||||
|
||||
expect($a)->toBe($b);
|
||||
});
|
||||
|
||||
it('ignores single-line comments', function () {
|
||||
it('ignores single-line comments', function (): void {
|
||||
$a = ContentHash::ofContent('a.php', "<?php\n// this is a comment\n\$foo = 1;");
|
||||
$b = ContentHash::ofContent('a.php', "<?php\n\$foo = 1;");
|
||||
|
||||
expect($a)->toBe($b);
|
||||
});
|
||||
|
||||
it('ignores hash-style comments', function () {
|
||||
it('ignores hash-style comments', function (): void {
|
||||
$a = ContentHash::ofContent('a.php', "<?php\n# hash comment\n\$foo = 1;");
|
||||
$b = ContentHash::ofContent('a.php', "<?php\n\$foo = 1;");
|
||||
|
||||
expect($a)->toBe($b);
|
||||
});
|
||||
|
||||
it('ignores multi-line comments', function () {
|
||||
it('ignores multi-line comments', function (): void {
|
||||
$a = ContentHash::ofContent('a.php', "<?php\n/* a multi\n line comment */\n\$foo = 1;");
|
||||
$b = ContentHash::ofContent('a.php', "<?php\n\$foo = 1;");
|
||||
|
||||
expect($a)->toBe($b);
|
||||
});
|
||||
|
||||
it('ignores doc comments', function () {
|
||||
it('ignores doc comments', function (): void {
|
||||
$a = ContentHash::ofContent('a.php', "<?php\n/**\n * @return int\n */\nfunction foo() { return 1; }");
|
||||
$b = ContentHash::ofContent('a.php', "<?php\nfunction foo() { return 1; }");
|
||||
|
||||
expect($a)->toBe($b);
|
||||
});
|
||||
|
||||
it('detects code changes', function () {
|
||||
it('detects code changes', function (): void {
|
||||
$a = ContentHash::ofContent('a.php', '<?php $foo = 1;');
|
||||
$b = ContentHash::ofContent('a.php', '<?php $foo = 2;');
|
||||
|
||||
expect($a)->not->toBe($b);
|
||||
});
|
||||
|
||||
it('preserves whitespace inside string literals', function () {
|
||||
it('preserves whitespace inside string literals', function (): void {
|
||||
$a = ContentHash::ofContent('a.php', "<?php \$foo = 'hello world';");
|
||||
$b = ContentHash::ofContent('a.php', "<?php \$foo = 'helloworld';");
|
||||
|
||||
expect($a)->not->toBe($b);
|
||||
});
|
||||
|
||||
it('treats variable renames as a change', function () {
|
||||
it('treats variable renames as a change', function (): void {
|
||||
$a = ContentHash::ofContent('a.php', '<?php $foo = 1;');
|
||||
$b = ContentHash::ofContent('a.php', '<?php $bar = 1;');
|
||||
|
||||
expect($a)->not->toBe($b);
|
||||
});
|
||||
|
||||
it('falls back to a raw hash for unparseable PHP', function () {
|
||||
it('falls back to a raw hash for unparseable PHP', function (): void {
|
||||
$hash = ContentHash::ofContent('a.php', 'not valid php at all');
|
||||
|
||||
expect($hash)->toBeString()->not->toBeEmpty();
|
||||
});
|
||||
|
||||
it('is case-insensitive on the file extension', function () {
|
||||
it('is case-insensitive on the file extension', function (): void {
|
||||
$a = ContentHash::ofContent('a.PHP', "<?php\n// comment\n\$foo = 1;");
|
||||
$b = ContentHash::ofContent('a.php', "<?php\n\$foo = 1;");
|
||||
|
||||
@@ -90,43 +90,43 @@ describe('PHP files', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Blade files', function () {
|
||||
it('strips blade comments', function () {
|
||||
describe('Blade files', function (): void {
|
||||
it('strips blade comments', function (): void {
|
||||
$a = ContentHash::ofContent('a.blade.php', '<div>{{-- a comment --}}Hello</div>');
|
||||
$b = ContentHash::ofContent('a.blade.php', '<div>Hello</div>');
|
||||
|
||||
expect($a)->toBe($b);
|
||||
});
|
||||
|
||||
it('strips multi-line blade comments', function () {
|
||||
it('strips multi-line blade comments', function (): void {
|
||||
$a = ContentHash::ofContent('a.blade.php', "<div>\n{{--\n multi\n line\n--}}\nHello\n</div>");
|
||||
$b = ContentHash::ofContent('a.blade.php', '<div> Hello </div>');
|
||||
|
||||
expect($a)->toBe($b);
|
||||
});
|
||||
|
||||
it('collapses whitespace', function () {
|
||||
it('collapses whitespace', function (): void {
|
||||
$a = ContentHash::ofContent('a.blade.php', "<div>\n Hello\n World\n</div>");
|
||||
$b = ContentHash::ofContent('a.blade.php', '<div> Hello World </div>');
|
||||
|
||||
expect($a)->toBe($b);
|
||||
});
|
||||
|
||||
it('detects content changes', function () {
|
||||
it('detects content changes', function (): void {
|
||||
$a = ContentHash::ofContent('a.blade.php', '<div>Hello</div>');
|
||||
$b = ContentHash::ofContent('a.blade.php', '<div>Goodbye</div>');
|
||||
|
||||
expect($a)->not->toBe($b);
|
||||
});
|
||||
|
||||
it('keeps blade directives intact', function () {
|
||||
it('keeps blade directives intact', function (): void {
|
||||
$a = ContentHash::ofContent('a.blade.php', '@if($user)Hi @endif');
|
||||
$b = ContentHash::ofContent('a.blade.php', '@if($user)Bye @endif');
|
||||
|
||||
expect($a)->not->toBe($b);
|
||||
});
|
||||
|
||||
it('does not use the PHP tokenizer for blade files', function () {
|
||||
it('does not use the PHP tokenizer for blade files', function (): void {
|
||||
$a = ContentHash::ofContent('a.blade.php', '<?php // not stripped ?> hello');
|
||||
$b = ContentHash::ofContent('a.blade.php', '<?php ?> hello');
|
||||
|
||||
@@ -134,78 +134,78 @@ describe('Blade files', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('JavaScript-like files', function () {
|
||||
it('strips line comments', function () {
|
||||
describe('JavaScript-like files', function (): void {
|
||||
it('strips line comments', function (): void {
|
||||
$a = ContentHash::ofContent('a.js', "// a comment\nconst foo = 1;");
|
||||
$b = ContentHash::ofContent('a.js', 'const foo = 1;');
|
||||
|
||||
expect($a)->toBe($b);
|
||||
});
|
||||
|
||||
it('strips block comments on their own lines', function () {
|
||||
it('strips block comments on their own lines', function (): void {
|
||||
$a = ContentHash::ofContent('a.js', "/* block */\nconst foo = 1;");
|
||||
$b = ContentHash::ofContent('a.js', 'const foo = 1;');
|
||||
|
||||
expect($a)->toBe($b);
|
||||
});
|
||||
|
||||
it('collapses whitespace', function () {
|
||||
it('collapses whitespace', function (): void {
|
||||
$a = ContentHash::ofContent('a.js', "const foo = 1;\n\nconst bar = 2;");
|
||||
$b = ContentHash::ofContent('a.js', 'const foo = 1; const bar = 2;');
|
||||
|
||||
expect($a)->toBe($b);
|
||||
});
|
||||
|
||||
it('detects code changes', function () {
|
||||
it('detects code changes', function (): void {
|
||||
$a = ContentHash::ofContent('a.js', 'const foo = 1;');
|
||||
$b = ContentHash::ofContent('a.js', 'const foo = 2;');
|
||||
|
||||
expect($a)->not->toBe($b);
|
||||
});
|
||||
|
||||
it('does not strip inline trailing comments', function () {
|
||||
it('does not strip inline trailing comments', function (): void {
|
||||
$a = ContentHash::ofContent('a.js', 'const foo = 1; // inline');
|
||||
$b = ContentHash::ofContent('a.js', 'const foo = 1;');
|
||||
|
||||
expect($a)->not->toBe($b);
|
||||
});
|
||||
|
||||
it('applies the same rules to .ts files', function () {
|
||||
it('applies the same rules to .ts files', function (): void {
|
||||
$a = ContentHash::ofContent('a.ts', "// comment\nconst foo: number = 1;");
|
||||
$b = ContentHash::ofContent('a.ts', 'const foo: number = 1;');
|
||||
|
||||
expect($a)->toBe($b);
|
||||
});
|
||||
|
||||
it('applies the same rules to .tsx files', function () {
|
||||
it('applies the same rules to .tsx files', function (): void {
|
||||
$a = ContentHash::ofContent('a.tsx', "// comment\nconst Foo = () => <div/>;");
|
||||
$b = ContentHash::ofContent('a.tsx', 'const Foo = () => <div/>;');
|
||||
|
||||
expect($a)->toBe($b);
|
||||
});
|
||||
|
||||
it('applies the same rules to .jsx files', function () {
|
||||
it('applies the same rules to .jsx files', function (): void {
|
||||
$a = ContentHash::ofContent('a.jsx', "// comment\nconst Foo = () => <div/>;");
|
||||
$b = ContentHash::ofContent('a.jsx', 'const Foo = () => <div/>;');
|
||||
|
||||
expect($a)->toBe($b);
|
||||
});
|
||||
|
||||
it('applies the same rules to .vue files', function () {
|
||||
it('applies the same rules to .vue files', function (): void {
|
||||
$a = ContentHash::ofContent('a.vue', "<script>\n// comment\nexport default {}\n</script>");
|
||||
$b = ContentHash::ofContent('a.vue', '<script> export default {} </script>');
|
||||
|
||||
expect($a)->toBe($b);
|
||||
});
|
||||
|
||||
it('applies the same rules to .svelte files', function () {
|
||||
it('applies the same rules to .svelte files', function (): void {
|
||||
$a = ContentHash::ofContent('a.svelte', "<script>\n// comment\nlet foo = 1;\n</script>");
|
||||
$b = ContentHash::ofContent('a.svelte', '<script> let foo = 1; </script>');
|
||||
|
||||
expect($a)->toBe($b);
|
||||
});
|
||||
|
||||
it('applies the same rules to .mjs, .cjs, and .mts files', function () {
|
||||
it('applies the same rules to .mjs, .cjs, and .mts files', function (): void {
|
||||
foreach (['mjs', 'cjs', 'mts'] as $ext) {
|
||||
$a = ContentHash::ofContent("a.$ext", "// comment\nexport const foo = 1;");
|
||||
$b = ContentHash::ofContent("a.$ext", 'export const foo = 1;');
|
||||
@@ -215,29 +215,29 @@ describe('JavaScript-like files', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('unknown extensions', function () {
|
||||
it('hashes the raw content for unknown extensions', function () {
|
||||
describe('unknown extensions', function (): void {
|
||||
it('hashes the raw content for unknown extensions', function (): void {
|
||||
$a = ContentHash::ofContent('a.txt', 'hello world');
|
||||
$b = ContentHash::ofContent('a.txt', 'hello world');
|
||||
|
||||
expect($a)->toBe($b);
|
||||
});
|
||||
|
||||
it('does not normalise whitespace for unknown extensions', function () {
|
||||
it('does not normalise whitespace for unknown extensions', function (): void {
|
||||
$a = ContentHash::ofContent('a.txt', 'hello world');
|
||||
$b = ContentHash::ofContent('a.txt', 'hello world');
|
||||
|
||||
expect($a)->not->toBe($b);
|
||||
});
|
||||
|
||||
it('does not strip comments for unknown extensions', function () {
|
||||
it('does not strip comments for unknown extensions', function (): void {
|
||||
$a = ContentHash::ofContent('a.txt', "// not a comment here\nhello");
|
||||
$b = ContentHash::ofContent('a.txt', 'hello');
|
||||
|
||||
expect($a)->not->toBe($b);
|
||||
});
|
||||
|
||||
it('hashes files with no extension as raw content', function () {
|
||||
it('hashes files with no extension as raw content', function (): void {
|
||||
$a = ContentHash::ofContent('Makefile', "all:\n\techo hi");
|
||||
$b = ContentHash::ofContent('Makefile', "all:\n\techo hi");
|
||||
|
||||
@@ -245,14 +245,14 @@ describe('unknown extensions', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('output format', function () {
|
||||
it('returns a 32-character hex xxh128 hash', function () {
|
||||
describe('output format', function (): void {
|
||||
it('returns a 32-character hex xxh128 hash', function (): void {
|
||||
$hash = ContentHash::ofContent('a.php', '<?php $foo = 1;');
|
||||
|
||||
expect($hash)->toMatch('/^[a-f0-9]{32}$/');
|
||||
});
|
||||
|
||||
it('returns a stable hash for empty content', function () {
|
||||
it('returns a stable hash for empty content', function (): void {
|
||||
$a = ContentHash::ofContent('a.php', '');
|
||||
$b = ContentHash::ofContent('a.php', '');
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use Pest\Plugins\Tia;
|
||||
|
||||
test('does not throw when an integer --random-order-seed is passed as a separate argv element', function () {
|
||||
test('does not throw when an integer --random-order-seed is passed as a separate argv element', function (): void {
|
||||
// Mirrors the parallel worker argv (see bin/worker.php), where
|
||||
// `--random-order-seed` and its value arrive as separate items and the
|
||||
// seed value is an int rather than a string. Regression test for the
|
||||
@@ -13,7 +13,7 @@ test('does not throw when an integer --random-order-seed is passed as a separate
|
||||
expect(Tia::isEnabledForRun($arguments))->toBeFalse();
|
||||
});
|
||||
|
||||
test('still detects --tia when an integer argument is present', function () {
|
||||
test('still detects --tia when an integer argument is present', function (): void {
|
||||
$arguments = ['--tia', '--random-order-seed', 1782350398];
|
||||
|
||||
expect(Tia::isEnabledForRun($arguments))->toBeTrue();
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
use Pest\Plugins\Tia\Lockfiles\PackageLock;
|
||||
|
||||
$lock = (fn (array $packages, ?string $name = null): string => json_encode([
|
||||
'name' => $name ?? 'app',
|
||||
'lockfileVersion' => 3,
|
||||
'packages' => $packages,
|
||||
]));
|
||||
|
||||
it('applies only to package-lock.json', function (): void {
|
||||
$handler = new PackageLock;
|
||||
|
||||
expect($handler->applies('package-lock.json'))->toBeTrue()
|
||||
->and($handler->applies('pnpm-lock.yaml'))->toBeFalse()
|
||||
->and($handler->applies('yarn.lock'))->toBeFalse();
|
||||
});
|
||||
|
||||
it('returns null for contents that are not an npm lockfile', function (): void {
|
||||
$handler = new PackageLock;
|
||||
|
||||
expect($handler->fingerprint('not json'))->toBeNull()
|
||||
->and($handler->fingerprint('{"lockfileVersion":1}'))->toBeNull();
|
||||
});
|
||||
|
||||
it('is stable when the directory-derived top-level name changes', function () use ($lock): void {
|
||||
$handler = new PackageLock;
|
||||
$packages = ['node_modules/react' => ['version' => '19.0.0']];
|
||||
|
||||
expect($handler->fingerprint($lock($packages, 'app-a')))
|
||||
->toBe($handler->fingerprint($lock($packages, 'app-b')));
|
||||
});
|
||||
|
||||
it('ignores platform-specific native binaries added or dropped per OS', function () use ($lock): void {
|
||||
$handler = new PackageLock;
|
||||
|
||||
$mac = $lock([
|
||||
'node_modules/react' => ['version' => '19.0.0'],
|
||||
'node_modules/@rollup/rollup-darwin-arm64' => [
|
||||
'version' => '4.9.5', 'os' => ['darwin'], 'cpu' => ['arm64'], 'optional' => true,
|
||||
],
|
||||
], 'app');
|
||||
|
||||
$linux = $lock([
|
||||
'node_modules/react' => ['version' => '19.0.0'],
|
||||
'node_modules/@rollup/rollup-linux-x64-gnu' => [
|
||||
'version' => '4.52.1', 'os' => ['linux'], 'cpu' => ['x64'], 'optional' => true,
|
||||
],
|
||||
], 'app');
|
||||
|
||||
expect($handler->fingerprint($mac))->toBe($handler->fingerprint($linux));
|
||||
});
|
||||
|
||||
it('ignores libc-constrained variants', function () use ($lock): void {
|
||||
$handler = new PackageLock;
|
||||
|
||||
$gnu = $lock([
|
||||
'node_modules/lightningcss-linux-x64-gnu' => [
|
||||
'version' => '1.32.0', 'os' => ['linux'], 'cpu' => ['x64'], 'libc' => ['glibc'], 'optional' => true,
|
||||
],
|
||||
]);
|
||||
|
||||
expect($handler->fingerprint($gnu))->toBe($handler->fingerprint($lock([])));
|
||||
});
|
||||
|
||||
it('ignores runtime deps bundled beneath a platform-specific package', function () use ($lock): void {
|
||||
$handler = new PackageLock;
|
||||
|
||||
$withoutBundled = $lock([
|
||||
'node_modules/react' => ['version' => '19.0.0'],
|
||||
'node_modules/@rolldown/binding-wasm32-wasi' => [
|
||||
'version' => '1.0.0', 'cpu' => ['wasm32'], 'optional' => true,
|
||||
],
|
||||
]);
|
||||
|
||||
$withBundled = $lock([
|
||||
'node_modules/react' => ['version' => '19.0.0'],
|
||||
'node_modules/@rolldown/binding-wasm32-wasi' => [
|
||||
'version' => '1.0.0', 'cpu' => ['wasm32'], 'optional' => true,
|
||||
],
|
||||
'node_modules/@rolldown/binding-wasm32-wasi/node_modules/@emnapi/core' => ['version' => '1.4.0'],
|
||||
]);
|
||||
|
||||
expect($handler->fingerprint($withoutBundled))->toBe($handler->fingerprint($withBundled));
|
||||
});
|
||||
|
||||
it('detects a real dependency version change', function () use ($lock): void {
|
||||
$handler = new PackageLock;
|
||||
|
||||
$before = $lock(['node_modules/react' => ['version' => '19.0.0']]);
|
||||
$after = $lock(['node_modules/react' => ['version' => '19.1.0']]);
|
||||
|
||||
expect($handler->fingerprint($before))->not->toBe($handler->fingerprint($after));
|
||||
});
|
||||
|
||||
it('detects an added or removed non-platform dependency', function () use ($lock): void {
|
||||
$handler = new PackageLock;
|
||||
|
||||
$before = $lock(['node_modules/react' => ['version' => '19.0.0']]);
|
||||
$after = $lock([
|
||||
'node_modules/react' => ['version' => '19.0.0'],
|
||||
'node_modules/vue' => ['version' => '3.5.0'],
|
||||
]);
|
||||
|
||||
expect($handler->fingerprint($before))->not->toBe($handler->fingerprint($after));
|
||||
});
|
||||
|
||||
it('is independent of package ordering', function () use ($lock): void {
|
||||
$handler = new PackageLock;
|
||||
|
||||
$a = $lock([
|
||||
'node_modules/a' => ['version' => '1.0.0'],
|
||||
'node_modules/b' => ['version' => '2.0.0'],
|
||||
]);
|
||||
$b = $lock([
|
||||
'node_modules/b' => ['version' => '2.0.0'],
|
||||
'node_modules/a' => ['version' => '1.0.0'],
|
||||
]);
|
||||
|
||||
expect($handler->fingerprint($a))->toBe($handler->fingerprint($b));
|
||||
});
|
||||
@@ -259,34 +259,34 @@ function tiaAliasResults(): array
|
||||
return $cache = ['roots' => $roots, 'aliases' => $aliases];
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
beforeEach(function (): void {
|
||||
if ((new ExecutableFinder)->find('node') === null) {
|
||||
$this->markTestSkipped('node is not available.');
|
||||
}
|
||||
});
|
||||
|
||||
it('strips JSONC down to something JSON.parse accepts', function (string $name) {
|
||||
it('strips JSONC down to something JSON.parse accepts', function (string $name): void {
|
||||
$result = tiaStripResults()[$name];
|
||||
[, $expected] = tiaStripFixtures()[$name];
|
||||
|
||||
expect($result['ok'])->toBeTrue(
|
||||
"[{$name}] did not parse after stripping: ".($result['error'] ?? 'unknown').PHP_EOL.
|
||||
'stripped: '.$result['stripped'],
|
||||
);
|
||||
expect($result['parsed'])->toEqual($expected);
|
||||
)
|
||||
->and($result['parsed'])->toEqual($expected);
|
||||
})->with(array_keys(tiaStripFixtures()));
|
||||
|
||||
it('never touches comment-looking sequences inside string values', function () {
|
||||
it('never touches comment-looking sequences inside string values', function (): void {
|
||||
expect(tiaStripResults()['url-in-string']['stripped'])->toContain('https://example.com//x')
|
||||
->and(tiaStripResults()['glob-in-string']['stripped'])->toContain('resources/js/**/*.ts')
|
||||
->and(tiaStripResults()['block-both-in-string']['stripped'])->toContain('x/*y*/z');
|
||||
});
|
||||
|
||||
it('removes the comment body entirely', function () {
|
||||
it('removes the comment body entirely', function (): void {
|
||||
expect(tiaStripResults()['block-secret']['stripped'])->not->toContain('SECRET');
|
||||
});
|
||||
|
||||
it('builds the expected alias map from a tsconfig', function (string $name) {
|
||||
it('builds the expected alias map from a tsconfig', function (string $name): void {
|
||||
$results = tiaAliasResults();
|
||||
[, $expectedRelative] = tiaAliasFixtures()[$name];
|
||||
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
<?php
|
||||
|
||||
pest()->presets()->custom('myFramework', function (array $userNamespaces) {
|
||||
return [
|
||||
expect($userNamespaces)->toBe(['Pest']),
|
||||
];
|
||||
});
|
||||
pest()->presets()->custom('myFramework', fn (array $userNamespaces): array => [
|
||||
expect($userNamespaces)->toBe(['Pest']),
|
||||
]);
|
||||
|
||||
test('preset invalid name', function () {
|
||||
test('preset invalid name', function (): void {
|
||||
$this->preset()->myAnotherFramework();
|
||||
})->throws(InvalidArgumentException::class, 'The preset [myAnotherFramework] does not exist. The available presets are [php, laravel, strict, security, relaxed, myFramework].');
|
||||
|
||||
|
||||
+23
-21
@@ -1,49 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Pest\Support\Arr;
|
||||
|
||||
describe('last', function () {
|
||||
it('should return false for an empty arary', function () {
|
||||
describe('last', function (): void {
|
||||
it('should return false for an empty arary', function (): void {
|
||||
expect(Arr::last([]))->toBeFalse();
|
||||
});
|
||||
|
||||
it('should return the last element for an array with a single element', function () {
|
||||
it('should return the last element for an array with a single element', function (): void {
|
||||
expect(Arr::last([1]))->toBe(1);
|
||||
});
|
||||
|
||||
it('should return the last element for an array without changing the internal pointer', function () {
|
||||
it('should return the last element for an array without changing the internal pointer', function (): void {
|
||||
$array = [1, 2, 3];
|
||||
|
||||
expect(Arr::last($array))->toBe(3);
|
||||
expect(current($array))->toBe(1);
|
||||
expect(Arr::last($array))->toBe(3)
|
||||
->and(current($array))->toBe(1);
|
||||
|
||||
next($array);
|
||||
expect(current($array))->toBe(2);
|
||||
expect(Arr::last($array))->toBe(3);
|
||||
expect(current($array))->toBe(2);
|
||||
expect(current($array))->toBe(2)
|
||||
->and(Arr::last($array))->toBe(3)
|
||||
->and(current($array))->toBe(2);
|
||||
});
|
||||
|
||||
it('should return the last element for an associative array without changing the internal pointer', function () {
|
||||
it('should return the last element for an associative array without changing the internal pointer', function (): void {
|
||||
$array = ['first' => 1, 'second' => 2, 'third' => 3];
|
||||
|
||||
expect(Arr::last($array))->toBe(3);
|
||||
expect(current($array))->toBe(1);
|
||||
expect(Arr::last($array))->toBe(3)
|
||||
->and(current($array))->toBe(1);
|
||||
|
||||
next($array);
|
||||
expect(current($array))->toBe(2);
|
||||
expect(Arr::last($array))->toBe(3);
|
||||
expect(current($array))->toBe(2);
|
||||
expect(current($array))->toBe(2)
|
||||
->and(Arr::last($array))->toBe(3)
|
||||
->and(current($array))->toBe(2);
|
||||
});
|
||||
|
||||
it('should return the last element for an mixed key array without changing the internal pointer', function () {
|
||||
it('should return the last element for an mixed key array without changing the internal pointer', function (): void {
|
||||
$array = ['first' => 1, 2, 'third' => 3];
|
||||
|
||||
expect(Arr::last($array))->toBe(3);
|
||||
expect(current($array))->toBe(1);
|
||||
expect(Arr::last($array))->toBe(3)
|
||||
->and(current($array))->toBe(1);
|
||||
|
||||
next($array);
|
||||
expect(current($array))->toBe(2);
|
||||
expect(Arr::last($array))->toBe(3);
|
||||
expect(current($array))->toBe(2);
|
||||
expect(current($array))->toBe(2)
|
||||
->and(Arr::last($array))->toBe(3)
|
||||
->and(current($array))->toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,10 +2,8 @@
|
||||
|
||||
use Pest\Support\Backtrace;
|
||||
|
||||
it('gets file name from called file', function () {
|
||||
$a = function () {
|
||||
return Backtrace::file();
|
||||
};
|
||||
it('gets file name from called file', function (): void {
|
||||
$a = (fn (): string => Backtrace::file());
|
||||
|
||||
expect($a())->toBe(__FILE__);
|
||||
});
|
||||
|
||||
@@ -6,37 +6,37 @@ use Pest\TestSuite;
|
||||
|
||||
pest()->group('container');
|
||||
|
||||
beforeEach(function () {
|
||||
beforeEach(function (): void {
|
||||
$this->container = new Container;
|
||||
});
|
||||
|
||||
it('exists')
|
||||
->assertTrue(class_exists(Container::class));
|
||||
|
||||
it('gets an instance', function () {
|
||||
it('gets an instance', function (): void {
|
||||
$this->container->add(Container::class, $this->container);
|
||||
expect($this->container->get(Container::class))->toBe($this->container);
|
||||
});
|
||||
|
||||
test('autowire', function () {
|
||||
test('autowire', function (): void {
|
||||
expect($this->container->get(Container::class))->toBeInstanceOf(Container::class);
|
||||
});
|
||||
|
||||
it('creates an instance and resolves parameters', function () {
|
||||
it('creates an instance and resolves parameters', function (): void {
|
||||
$this->container->add(Container::class, $this->container);
|
||||
$instance = $this->container->get(ClassWithDependency::class);
|
||||
|
||||
expect($instance)->toBeInstanceOf(ClassWithDependency::class);
|
||||
});
|
||||
|
||||
it('creates an instance and resolves also sub parameters', function () {
|
||||
it('creates an instance and resolves also sub parameters', function (): void {
|
||||
$this->container->add(Container::class, $this->container);
|
||||
$instance = $this->container->get(ClassWithSubDependency::class);
|
||||
|
||||
expect($instance)->toBeInstanceOf(ClassWithSubDependency::class);
|
||||
});
|
||||
|
||||
it('can resolve builtin value types', function () {
|
||||
it('can resolve builtin value types', function (): void {
|
||||
$this->container->add('rootPath', getcwd());
|
||||
$this->container->add('testPath', 'tests');
|
||||
|
||||
@@ -44,7 +44,7 @@ it('can resolve builtin value types', function () {
|
||||
expect($instance)->toBeInstanceOf(TestSuite::class);
|
||||
});
|
||||
|
||||
it('cannot resolve a parameter without type', function () {
|
||||
it('cannot resolve a parameter without type', function (): void {
|
||||
$this->container->get(ClassWithoutTypeParameter::class);
|
||||
})->throws(ShouldNotHappen::class);
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Pest\Support\DatasetInfo;
|
||||
|
||||
it('can check if dataset is defined inside a Datasets directory', function (string $file, bool $inside) {
|
||||
it('can check if dataset is defined inside a Datasets directory', function (string $file, bool $inside): void {
|
||||
expect(DatasetInfo::isInsideADatasetsDirectory($file))->toBe($inside);
|
||||
})->with([
|
||||
['file' => '/var/www/Datasets/project/tests/Datasets/Nested/Numbers.php', 'inside' => true],
|
||||
@@ -17,7 +19,7 @@ it('can check if dataset is defined inside a Datasets directory', function (stri
|
||||
['file' => '/var/www/project/tests/Features/Datasets.php', 'inside' => false],
|
||||
]);
|
||||
|
||||
it('can check if dataset is defined inside a Datasets.php file', function (string $file, bool $inside) {
|
||||
it('can check if dataset is defined inside a Datasets.php file', function (string $file, bool $inside): void {
|
||||
expect(DatasetInfo::isADatasetsFile($file))->toBe($inside);
|
||||
})->with([
|
||||
['file' => '/var/www/project/tests/Datasets/Numbers.php', 'inside' => false],
|
||||
@@ -27,7 +29,7 @@ it('can check if dataset is defined inside a Datasets.php file', function (strin
|
||||
['file' => '/var/www/project/tests/Features/Datasets.php', 'inside' => true],
|
||||
]);
|
||||
|
||||
it('computes the dataset scope', function (string $file, string $scope) {
|
||||
it('computes the dataset scope', function (string $file, string $scope): void {
|
||||
expect(DatasetInfo::scope($file))->toBe($scope);
|
||||
})->with([
|
||||
['file' => '/var/www/Datasets/project/tests/Datasets/Nested/Numbers.php', 'scope' => '/var/www/Datasets/project/tests'],
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
use Pest\Support\ExceptionTrace;
|
||||
|
||||
it('ensures the given closures reports the correct class name', function () {
|
||||
$closure = function () {
|
||||
it('ensures the given closures reports the correct class name', function (): void {
|
||||
$closure = function (): void {
|
||||
throw new Exception('Call to undefined method P\Tests\IntentionallyNotExisting::testBasic().');
|
||||
};
|
||||
|
||||
@@ -13,7 +13,7 @@ it('ensures the given closures reports the correct class name', function () {
|
||||
'Call to undefined method Tests\IntentionallyNotExisting::testBasic().',
|
||||
);
|
||||
|
||||
it('ensures the given closures reports the correct class name and suggests the [pest()] function', function () {
|
||||
it('ensures the given closures reports the correct class name and suggests the [pest()] function', function (): void {
|
||||
$this->get();
|
||||
})->throws(
|
||||
Error::class,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use Pest\Support\HigherOrderMessage;
|
||||
|
||||
test('undefined method exceptions', function () {
|
||||
test('undefined method exceptions', function (): void {
|
||||
$message = new HigherOrderMessage(
|
||||
__FILE__,
|
||||
1,
|
||||
@@ -10,7 +10,7 @@ test('undefined method exceptions', function () {
|
||||
[]
|
||||
);
|
||||
|
||||
expect(fn () => $message->call($this))->toThrow(function (ReflectionException $exception) {
|
||||
expect(fn () => $message->call($this))->toThrow(function (ReflectionException $exception): void {
|
||||
expect($exception)
|
||||
->getMessage()->toBe('Call to undefined method PHPUnit\Framework\TestCase::foqwdqwd()')
|
||||
->getLine()->toBe(1)
|
||||
|
||||
@@ -2,16 +2,16 @@
|
||||
|
||||
use Pest\Support\Reflection;
|
||||
|
||||
it('gets file name from closure', function () {
|
||||
$fileName = Reflection::getFileNameFromClosure(function () {});
|
||||
it('gets file name from closure', function (): void {
|
||||
$fileName = Reflection::getFileNameFromClosure(function (): void {});
|
||||
|
||||
expect($fileName)->toBe(__FILE__);
|
||||
});
|
||||
|
||||
it('gets property values', function () {
|
||||
it('gets property values', function (): void {
|
||||
$class = new class
|
||||
{
|
||||
private $foo = 'bar';
|
||||
private string $foo = 'bar';
|
||||
};
|
||||
|
||||
$value = Reflection::getPropertyValue($class, 'foo');
|
||||
@@ -51,24 +51,24 @@ class Qwe extends Asd
|
||||
}
|
||||
}
|
||||
|
||||
it('gets properties from classes', function () {
|
||||
it('gets properties from classes', function (): void {
|
||||
$reflectionClass = new ReflectionClass(Qwe::class);
|
||||
|
||||
$properties = Reflection::getPropertiesFromReflectionClass($reflectionClass);
|
||||
|
||||
$properties = array_map(fn ($property) => $property->getName(), $properties);
|
||||
$properties = array_map(fn (ReflectionProperty $property) => $property->getName(), $properties);
|
||||
|
||||
expect($properties)->toBe([
|
||||
'bar',
|
||||
]);
|
||||
});
|
||||
|
||||
it('gets methods from classes', function () {
|
||||
it('gets methods from classes', function (): void {
|
||||
$reflectionClass = new ReflectionClass(Qwe::class);
|
||||
|
||||
$methods = Reflection::getMethodsFromReflectionClass($reflectionClass);
|
||||
|
||||
$methods = array_map(fn ($method) => $method->getName(), $methods);
|
||||
$methods = array_map(fn (ReflectionMethod $method) => $method->getName(), $methods);
|
||||
|
||||
expect($methods)->toBe([
|
||||
'getBar',
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Pest\Support\Str;
|
||||
|
||||
it('evaluates the code', function ($evaluatable, $expected) {
|
||||
it('evaluates the code', function (string $evaluatable, $expected): void {
|
||||
$code = Str::evaluable($evaluatable);
|
||||
|
||||
expect($code)->toBe($expected);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
it('may start with P', function (string $real, string $toBePrinted) {
|
||||
it('may start with P', function (string $real, string $toBePrinted): void {
|
||||
$printed = preg_replace('/P\\\/', '', $real, 1);
|
||||
|
||||
expect($printed)->toBe($toBePrinted);
|
||||
|
||||
@@ -6,7 +6,7 @@ use Pest\Exceptions\TestClosureMustNotBeStatic;
|
||||
use Pest\Factories\TestCaseMethodFactory;
|
||||
use Pest\TestSuite;
|
||||
|
||||
it('does not allow to add the same test description twice', function () {
|
||||
it('does not allow to add the same test description twice', function (): void {
|
||||
$testSuite = new TestSuite(getcwd(), 'tests');
|
||||
$method = new TestCaseMethodFactory('foo', null);
|
||||
$method->description = 'bar';
|
||||
@@ -18,10 +18,10 @@ it('does not allow to add the same test description twice', function () {
|
||||
sprintf('A test with the description `%s` already exists in the filename `%s`.', 'bar', 'foo'),
|
||||
);
|
||||
|
||||
it('does not allow static closures', function () {
|
||||
it('does not allow static closures', function (): void {
|
||||
$testSuite = new TestSuite(getcwd(), 'tests');
|
||||
|
||||
$method = new TestCaseMethodFactory('foo', static function () {});
|
||||
$method = new TestCaseMethodFactory('foo', static function (): void {});
|
||||
$method->description = 'bar';
|
||||
|
||||
$testSuite->tests->set($method);
|
||||
@@ -30,10 +30,10 @@ it('does not allow static closures', function () {
|
||||
'Test closure must not be static. Please remove the [static] keyword from the [bar] method in [foo].',
|
||||
);
|
||||
|
||||
it('alerts users about tests with arguments but no input', function () {
|
||||
it('alerts users about tests with arguments but no input', function (): void {
|
||||
$testSuite = new TestSuite(getcwd(), 'tests');
|
||||
|
||||
$method = new TestCaseMethodFactory('foo', function (int $arg) {});
|
||||
$method = new TestCaseMethodFactory('foo', function (int $arg): void {});
|
||||
|
||||
$method->description = 'bar';
|
||||
|
||||
@@ -43,7 +43,7 @@ it('alerts users about tests with arguments but no input', function () {
|
||||
sprintf('A test with the description [%s] has [%d] argument(s) ([%s]) and no dataset(s) provided in [%s]', 'bar', 1, 'int $arg', 'foo'),
|
||||
);
|
||||
|
||||
it('can return an array of all test suite filenames', function () {
|
||||
it('can return an array of all test suite filenames', function (): void {
|
||||
$testSuite = new TestSuite(getcwd(), 'tests');
|
||||
|
||||
$method = new TestCaseMethodFactory('a', null);
|
||||
|
||||
Reference in New Issue
Block a user