Migrates to Pint

This commit is contained in:
Nuno Maduro
2022-09-16 10:45:53 +01:00
parent 579b975318
commit e9564febaf
94 changed files with 413 additions and 471 deletions

View File

@ -47,5 +47,11 @@ jobs:
- name: Install Dependencies
run: composer update --prefer-stable --no-interaction --no-progress --ansi
- name: Run PHPStan
run: vendor/bin/phpstan analyse --no-progress --debug --ansi
- name: Types
run: composer test:types
- name: Style
run: composer test:lint
- name: Recfato
run: composer test:refacto

View File

@ -34,11 +34,11 @@ jobs:
run: composer update --${{ matrix.dependency-version }} --no-interaction --no-progress --ansi
- name: Unit Tests
run: php bin/pest --colors=always --exclude-group=integration
run: composer test:unit
- name: Unit Tests
run: php bin/pest --colors=always --exclude-group=integration ${{ matrix.parallel }}
run: test:parallel
if: ${{ false }} # 2.x-dev is under development
- name: Integration Tests
run: php bin/pest --colors=always --group=integration -v
run: composer test:integration

View File

@ -1,31 +0,0 @@
<?php
$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . DIRECTORY_SEPARATOR . 'tests')
->in(__DIR__ . DIRECTORY_SEPARATOR . 'bin')
->in(__DIR__ . DIRECTORY_SEPARATOR . 'overrides')
->in(__DIR__ . DIRECTORY_SEPARATOR . 'stubs')
->in(__DIR__ . DIRECTORY_SEPARATOR . 'src')
->append(['.php-cs-fixer.dist.php']);
$rules = [
'@Symfony' => true,
'phpdoc_no_empty_return' => false,
'array_syntax' => ['syntax' => 'short'],
'yoda_style' => false,
'binary_operator_spaces' => [
'operators' => [
'=>' => 'align',
'=' => 'align',
],
],
'concat_space' => ['spacing' => 'one'],
'not_operator_with_space' => false,
];
$rules['increment_style'] = ['style' => 'post'];
return (new PhpCsFixer\Config())
->setUsingCache(true)
->setRules($rules)
->setFinder($finder);

View File

@ -51,7 +51,13 @@
"illuminate/console": "^9.30.1",
"illuminate/support": "^9.30.1",
"laravel/dusk": "^6.25.1",
"pestphp/pest-dev-tools": "dev-master"
"ergebnis/phpstan-rules": "^1.0.0",
"laravel/pint": "^1.2.0",
"phpstan/phpstan": "^1.8.5",
"phpstan/phpstan-strict-rules": "^1.4.3",
"symfony/var-dumper": "^6.2.0",
"thecodingmachine/phpstan-strict-rules": "^1.0.0",
"rector/rector": "^0.14.2"
},
"minimum-stability": "dev",
"prefer-stable": true,
@ -66,8 +72,10 @@
"bin/pest"
],
"scripts": {
"lint": "PHP_CS_FIXER_IGNORE_ENV=true php-cs-fixer fix -v",
"test:lint": "PHP_CS_FIXER_IGNORE_ENV=true php-cs-fixer fix -v --dry-run",
"lint": "pint --test",
"refactor": "rector",
"test:lint": "pint --test",
"test:refactor": "rector --dry-run",
"test:types": "phpstan analyse --ansi --memory-limit=-1 --debug",
"test:unit": "php bin/pest --colors=always --exclude-group=integration",
"test:parallel": "exit 1",
@ -77,7 +85,8 @@
"@test:lint",
"@test:types",
"@test:unit",
"@test:integration"
"@test:integration",
"@test:refactor"
]
},
"extra": {

View File

@ -37,22 +37,16 @@
namespace PHPUnit\Runner\Filter;
use function end;
use Exception;
use function implode;
use Pest\Contracts\HasPrintableTestCaseName;
use PHPUnit\Framework\SelfDescribing;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestSuite;
use function preg_match;
use RecursiveFilterIterator;
use RecursiveIterator;
use function sprintf;
use function str_replace;
@ -62,7 +56,9 @@ use function str_replace;
final class NameFilterIterator extends RecursiveFilterIterator
{
private ?string $filter = null;
private ?int $filterMin = null;
private ?int $filterMax = null;
/**

View File

@ -43,14 +43,12 @@ use function array_values;
use function basename;
use function class_exists;
use function get_declared_classes;
use Pest\Contracts\HasPrintableTestCaseName;
use Pest\TestCases\IgnorableTest;
use Pest\TestSuite;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use ReflectionException;
use function substr;
/**

28
rector.php Normal file
View File

@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__.'/bin',
__DIR__.'/src',
]);
$rectorConfig->rules([
InlineConstructorDefaultToPropertyRector::class,
]);
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_81,
SetList::CODE_QUALITY,
SetList::DEAD_CODE,
SetList::EARLY_RETURN,
SetList::TYPE_DECLARATION,
SetList::PRIVATIZATION,
]);
};

View File

@ -5,9 +5,7 @@ declare(strict_types=1);
namespace Pest\Bootstrappers;
use Pest\Support\Str;
use function Pest\testDirectory;
use Pest\TestSuite;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;

View File

@ -17,7 +17,6 @@ trait Expectable
* Creates a new Expectation.
*
* @param TValue $value
*
* @return Expectation<TValue>
*/
public function expect(mixed $value): Expectation

View File

@ -18,7 +18,6 @@ trait Retrievable
*
* @param array<string, TRetrievableValue>|object $value
* @param TRetrievableValue|null $default
*
* @return TRetrievableValue|null
*/
private function retrieve(string $key, mixed $value, mixed $default = null): mixed

View File

@ -13,7 +13,6 @@ interface HandlesArguments
* Adds arguments before of the Test Suite execution.
*
* @param array<int, string> $arguments
*
* @return array<int, string>
*/
public function handleArguments(array $arguments): array;

View File

@ -51,7 +51,6 @@ final class Expectation
* @template TAndValue
*
* @param TAndValue $value
*
* @return self<TAndValue>
*/
public function and(mixed $value): Expectation
@ -158,7 +157,6 @@ final class Expectation
* @template TSequenceValue
*
* @param (callable(self<TValue>, self<string|int>): void)|TSequenceValue ...$callbacks
*
* @return self<TValue>
*/
public function sequence(mixed ...$callbacks): Expectation
@ -203,7 +201,6 @@ final class Expectation
*
* @param (callable(): TMatchSubject)|TMatchSubject $subject
* @param array<TMatchSubject, (callable(self<TValue>): mixed)|TValue> $expressions
*
* @return self<TValue>
*/
public function match(mixed $subject, array $expressions): Expectation
@ -242,7 +239,6 @@ final class Expectation
*
* @param (callable(): bool)|bool $condition
* @param callable(Expectation<TValue>): mixed $callback
*
* @return self<TValue>
*/
public function unless(callable|bool $condition, callable $callback): Expectation
@ -261,7 +257,6 @@ final class Expectation
*
* @param (callable(): bool)|bool $condition
* @param callable(self<TValue>): mixed $callback
*
* @return self<TValue>
*/
public function when(callable|bool $condition, callable $callback): Expectation
@ -283,7 +278,6 @@ final class Expectation
* Dynamically calls methods on the class or creates a new higher order expectation.
*
* @param array<int, mixed> $parameters
*
* @return Expectation<TValue>|HigherOrderExpectation<Expectation<TValue>, TValue>
*/
public function __call(string $method, array $parameters): Expectation|HigherOrderExpectation

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Pest\Expectations;
use function expect;
use Pest\Expectation;
/**
@ -34,7 +33,6 @@ final class EachExpectation
* @template TAndValue
*
* @param TAndValue $value
*
* @return Expectation<TAndValue>
*/
public function and(mixed $value): Expectation
@ -58,7 +56,6 @@ final class EachExpectation
* Dynamically calls methods on the class with the given arguments on each item.
*
* @param array<int|string, mixed> $arguments
*
* @return self<TValue>
*/
public function __call(string $name, array $arguments): EachExpectation

View File

@ -58,7 +58,6 @@ final class HigherOrderExpectation
* @template TExpectValue
*
* @param TExpectValue $value
*
* @return Expectation<TExpectValue>
*/
public function expect(mixed $value): Expectation
@ -72,7 +71,6 @@ final class HigherOrderExpectation
* @template TExpectValue
*
* @param TExpectValue $value
*
* @return Expectation<TExpectValue>
*/
public function and(mixed $value): Expectation
@ -85,7 +83,6 @@ final class HigherOrderExpectation
* the HigherOrderExpectation chain.
*
* @param Closure(Expectation<TValue>): void $expectation
*
* @return HigherOrderExpectation<TOriginalValue, TOriginalValue>
*/
public function scoped(Closure $expectation): self
@ -109,7 +106,6 @@ final class HigherOrderExpectation
* Dynamically calls methods on the class with the given arguments.
*
* @param array<int, mixed> $arguments
*
* @return self<TOriginalValue, mixed>|self<TOriginalValue, TValue>
*/
public function __call(string $name, array $arguments): self
@ -166,7 +162,6 @@ final class HigherOrderExpectation
* Performs the given assertion with the current expectation.
*
* @param array<int, mixed> $arguments
*
* @return self<TOriginalValue, TValue>
*/
private function performAssertion(string $name, array $arguments): self

View File

@ -31,7 +31,6 @@ final class OppositeExpectation
* Asserts that the value array not has the provided $keys.
*
* @param array<int, int|string|array<int-string, mixed>> $keys
*
* @return Expectation<TValue>
*/
public function toHaveKeys(array $keys): Expectation
@ -57,7 +56,6 @@ final class OppositeExpectation
* Handle dynamic method calls into the original expectation.
*
* @param array<int, mixed> $arguments
*
* @return Expectation<TValue>|Expectation<mixed>|never
*/
public function __call(string $name, array $arguments): Expectation
@ -92,7 +90,6 @@ final class OppositeExpectation
* Creates a new expectation failed exception with a nice readable message.
*
* @param array<int, mixed> $arguments
*
* @return never
*/
private function throwExpectationFailedException(string $name, array $arguments = []): void

View File

@ -16,7 +16,6 @@ final class CoversNothing
* Adds annotations regarding the "depends" feature.
*
* @param array<int, string> $annotations
*
* @return array<int, string>
*/
public function __invoke(TestCaseMethodFactory $method, array $annotations): array

View File

@ -16,7 +16,6 @@ final class Depends
* Adds annotations regarding the "depends" feature.
*
* @param array<int, string> $annotations
*
* @return array<int, string>
*/
public function __invoke(TestCaseMethodFactory $method, array $annotations): array

View File

@ -15,7 +15,6 @@ final class Groups
* Adds annotations regarding the "groups" feature.
*
* @param array<int, string> $annotations
*
* @return array<int, string>
*/
public function __invoke(TestCaseMethodFactory $method, array $annotations): array

View File

@ -20,7 +20,6 @@ abstract class Attribute
/**
* @param array<int, string> $attributes
*
* @return array<int, string>
*/
public function __invoke(TestCaseMethodFactory $method, array $attributes): array // @phpstan-ignore-line

View File

@ -24,7 +24,6 @@ final class Covers extends Attribute
* Adds attributes regarding the "covers" feature.
*
* @param array<int, string> $attributes
*
* @return array<int, string>
*/
public function __invoke(TestCaseMethodFactory $method, array $attributes): array

View File

@ -20,7 +20,6 @@ if (!function_exists('expect')) {
* @template TValue
*
* @param TValue $value
*
* @return Expectation<TValue>
*/
function expect(mixed $value = null): Expectation

View File

@ -8,9 +8,7 @@ use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use Pest\Exceptions\InvalidConsoleArgument;
use function Pest\testDirectory;
use Pest\TestSuite;
/**

View File

@ -8,9 +8,7 @@ use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Pest\Console\Thanks;
use Pest\Exceptions\InvalidConsoleArgument;
use function Pest\testDirectory;
use Pest\TestSuite;
/**

View File

@ -8,9 +8,7 @@ use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Pest\Exceptions\InvalidConsoleArgument;
use Pest\Support\Str;
use function Pest\testDirectory;
use Pest\TestSuite;
/**

View File

@ -194,7 +194,6 @@ final class Expectation
* Asserts that the value starts with $expected.
*
* @param non-empty-string $expected
*
*@return Expectation<TValue>
*/
public function toStartWith(string $expected): Expectation
@ -212,7 +211,6 @@ final class Expectation
* Asserts that the value ends with $expected.
*
* @param non-empty-string $expected
*
*@return Expectation<TValue>
*/
public function toEndWith(string $expected): Expectation
@ -298,7 +296,6 @@ final class Expectation
* Asserts that the value contains the provided properties $names.
*
* @param iterable<array-key, string> $names
*
*@return Expectation<TValue>
*/
public function toHaveProperties(iterable $names): Expectation
@ -357,7 +354,6 @@ final class Expectation
* Asserts that the value is one of the given values.
*
* @param iterable<int|string, mixed> $values
*
* @return Expectation<TValue>
*/
public function toBeIn(iterable $values): Expectation
@ -383,7 +379,6 @@ final class Expectation
* Asserts that the value is an instance of $class.
*
* @param class-string $class
*
* @return Expectation<TValue>
*/
public function toBeInstanceOf(string $class): Expectation
@ -596,7 +591,6 @@ final class Expectation
* Asserts that the value array has the provided $keys.
*
* @param array<int, int|string|array<int-string, mixed>> $keys
*
* @return Expectation<TValue>
*/
public function toHaveKeys(array $keys): Expectation
@ -711,7 +705,6 @@ final class Expectation
* Asserts that the value array matches the given array subset.
*
* @param iterable<int|string, mixed> $array
*
* @return Expectation<TValue>
*/
public function toMatchArray(iterable $array): Expectation
@ -744,7 +737,6 @@ final class Expectation
* of the properties of an given object.
*
* @param iterable<string, mixed> $object
*
* @return Expectation<TValue>
*/
public function toMatchObject(iterable $object): Expectation
@ -801,7 +793,6 @@ final class Expectation
/**
* @param class-string $class
*
* @return Expectation<TValue>
*/
public function toContainOnlyInstancesOf(string $class): Expectation
@ -819,7 +810,6 @@ final class Expectation
* Asserts that executing value throws an exception.
*
* @param (Closure(Throwable): mixed)|string $exception
*
* @return Expectation<TValue>
*/
public function toThrow(callable|string $exception, string $exceptionMessage = null): Expectation

View File

@ -18,7 +18,6 @@ final class HandleArguments
* Transform the input arguments by passing it to the relevant plugins.
*
* @param array<int, string> $argv
*
* @return array<int, string>
*/
public function __invoke(array $argv): array

View File

@ -23,7 +23,6 @@ trait HandleArguments
* Adds the given argument and value to the list of arguments.
*
* @param array<int, string> $arguments
*
* @return array<int, string>
*/
public function pushArgument(string $argument, array $arguments): array
@ -37,7 +36,6 @@ trait HandleArguments
* Pops the given argument from the arguments.
*
* @param array<int, string> $arguments
*
* @return array<int, string>
*/
public function popArgument(string $argument, array $arguments): array

View File

@ -5,9 +5,7 @@ declare(strict_types=1);
namespace Pest\Plugins;
use Pest\Contracts\Plugins\HandlesArguments;
use function Pest\version;
use Symfony\Component\Console\Output\OutputInterface;
/**

View File

@ -9,9 +9,7 @@ use Pest\Exceptions\DatasetAlreadyExist;
use Pest\Exceptions\DatasetDoesNotExist;
use Pest\Exceptions\ShouldNotHappen;
use SebastianBergmann\Exporter\Exporter;
use function sprintf;
use Traversable;
/**
@ -84,7 +82,6 @@ final class DatasetsRepository
* Resolves the current dataset to an array value.
*
* @param array<Closure|iterable<int|string, mixed>|string> $dataset
*
* @return array<string, mixed>|null
*/
public static function resolve(string $description, array $dataset): array|null
@ -137,7 +134,6 @@ final class DatasetsRepository
/**
* @param array<Closure|iterable<int|string, mixed>|string> $datasets
*
* @return array<array<mixed>>
*/
private static function processDatasets(array $datasets): array
@ -180,7 +176,6 @@ final class DatasetsRepository
/**
* @param array<array<mixed>> $combinations
*
* @return array<array<array<mixed>>>
*/
private static function getDatasetsCombinations(array $combinations): array

View File

@ -65,7 +65,6 @@ final class Arr
* Flatten a multi-dimensional associative array with dots.
*
* @param array<array-key, mixed> $array
*
* @return array<int|string, mixed>
*/
public static function dot(array $array, string $prepend = ''): array

View File

@ -36,7 +36,6 @@ final class Container
* Gets a dependency from the container.
*
* @param class-string $id
*
* @return mixed
*/
public function get(string $id)

View File

@ -11,7 +11,6 @@ use SebastianBergmann\CodeCoverage\Node\File;
use SebastianBergmann\Environment\Runtime;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Terminal;
use function Termwind\render;
use function Termwind\renderUsing;
@ -147,7 +146,6 @@ final class Coverage
* ```
*
* @param File $file
*
* @return array<int, string>
*/
public static function getMissingCoverage($file): array

View File

@ -26,7 +26,6 @@ final class HigherOrderCallables
* Create a new expectation. Callable values will be executed prior to returning the new expectation.
*
* @param (Closure():TValue)|TValue $value
*
* @return Expectation<TValue>
*/
public function expect(mixed $value): Expectation
@ -43,7 +42,6 @@ final class HigherOrderCallables
* Create a new expectation. Callable values will be executed prior to returning the new expectation.
*
* @param callable|TValue $value
*
* @return Expectation<(callable(): mixed)|TValue>
*/
public function and(mixed $value)

View File

@ -61,7 +61,6 @@ final class HigherOrderTapProxy
* Dynamically pass method calls to the target.
*
* @param array<int, mixed> $arguments
*
* @return mixed
*/
public function __call(string $methodName, array $arguments)

View File

@ -23,7 +23,6 @@ final class Reflection
* Calls the given method with args on the given object.
*
* @param array<int, mixed> $args
*
* @return mixed
*/
public static function call(object $object, string $method, array $args = [])
@ -53,7 +52,6 @@ final class Reflection
* Bind a callable to the TestCase and return the result.
*
* @param array<int, mixed> $args
*
* @return mixed
*/
public static function bindCallable(callable $callable, array $args = [])

View File

@ -35,7 +35,8 @@ 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
{
return [

View File

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

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Tests\CustomTestCase;
use function PHPUnit\Framework\assertTrue;
use PHPUnit\Framework\TestCase;
abstract class CustomTestCase extends TestCase

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Tests\CustomTestCase;
use function PHPUnit\Framework\assertTrue;
use PHPUnit\Framework\TestCase;
class ExecutedTest extends TestCase

View File

@ -1,9 +1,7 @@
<?php
use Pest\Plugins\Version;
use function Pest\version;
use Symfony\Component\Console\Output\BufferedOutput;
it('outputs the version when --version is used', function () {

View File

@ -10,7 +10,8 @@ it('gets file name from closure', function () {
});
it('gets property values', function () {
$class = new class() {
$class = new class()
{
private $foo = 'bar';
};