diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index ace047fcf23..9439e3615e4 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -201,6 +201,7 @@ 'no_whitespace_in_blank_line' => true, 'non_printable_character' => true, 'normalize_index_brace' => true, + 'nullable_type_declaration_for_default_null_value' => true, 'object_operator_without_whitespace' => true, 'octal_notation' => true, 'operator_linebreak' => [ diff --git a/src/Framework/Constraint/Constraint.php b/src/Framework/Constraint/Constraint.php index 7702281a4f8..c4f67cc56ea 100644 --- a/src/Framework/Constraint/Constraint.php +++ b/src/Framework/Constraint/Constraint.php @@ -78,7 +78,7 @@ protected function matches(mixed $other): bool * * @throws ExpectationFailedException */ - protected function fail(mixed $other, string $description, ComparisonFailure $comparisonFailure = null): never + protected function fail(mixed $other, string $description, ?ComparisonFailure $comparisonFailure = null): never { $failureDescription = sprintf( 'Failed asserting that %s.', diff --git a/src/Framework/Constraint/JsonMatches.php b/src/Framework/Constraint/JsonMatches.php index 0000c8ef5a7..dc3be3b4cef 100644 --- a/src/Framework/Constraint/JsonMatches.php +++ b/src/Framework/Constraint/JsonMatches.php @@ -68,7 +68,7 @@ protected function matches(mixed $other): bool * @throws ExpectationFailedException * @throws InvalidJsonException */ - protected function fail(mixed $other, string $description, ComparisonFailure $comparisonFailure = null): never + protected function fail(mixed $other, string $description, ?ComparisonFailure $comparisonFailure = null): never { if ($comparisonFailure === null) { [$error, $recodedOther] = Json::canonicalize($other); diff --git a/src/Framework/Exception/Exception.php b/src/Framework/Exception/Exception.php index 01531f5ec57..087729fb11b 100644 --- a/src/Framework/Exception/Exception.php +++ b/src/Framework/Exception/Exception.php @@ -40,7 +40,7 @@ class Exception extends RuntimeException implements \PHPUnit\Exception { protected array $serializableTrace; - public function __construct(string $message = '', int $code = 0, Throwable $previous = null) + public function __construct(string $message = '', int $code = 0, ?Throwable $previous = null) { parent::__construct($message, $code, $previous); diff --git a/src/Framework/Exception/ExpectationFailedException.php b/src/Framework/Exception/ExpectationFailedException.php index c1a4c043fd4..6d2b15013a3 100644 --- a/src/Framework/Exception/ExpectationFailedException.php +++ b/src/Framework/Exception/ExpectationFailedException.php @@ -25,7 +25,7 @@ final class ExpectationFailedException extends AssertionFailedError { protected ?ComparisonFailure $comparisonFailure = null; - public function __construct(string $message, ComparisonFailure $comparisonFailure = null, Exception $previous = null) + public function __construct(string $message, ?ComparisonFailure $comparisonFailure = null, ?Exception $previous = null) { $this->comparisonFailure = $comparisonFailure; diff --git a/src/Framework/MockObject/Generator/Generator.php b/src/Framework/MockObject/Generator/Generator.php index 0cc671c25f8..593cb8872c3 100644 --- a/src/Framework/MockObject/Generator/Generator.php +++ b/src/Framework/MockObject/Generator/Generator.php @@ -108,7 +108,7 @@ final class Generator * @throws RuntimeException * @throws UnknownTypeException */ - public function testDouble(string $type, bool $mockObject, bool $markAsMockObject, ?array $methods = [], array $arguments = [], string $mockClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true, bool $cloneArguments = true, bool $callOriginalMethods = false, object $proxyTarget = null, bool $allowMockingUnknownTypes = true, bool $returnValueGeneration = true): MockObject|Stub + public function testDouble(string $type, bool $mockObject, bool $markAsMockObject, ?array $methods = [], array $arguments = [], string $mockClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true, bool $cloneArguments = true, bool $callOriginalMethods = false, ?object $proxyTarget = null, bool $allowMockingUnknownTypes = true, bool $returnValueGeneration = true): MockObject|Stub { if ($type === Traversable::class) { $type = Iterator::class; @@ -240,7 +240,7 @@ public function testDoubleForInterfaceIntersection(array $interfaces, bool $mock * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5241 */ - public function mockObjectForAbstractClass(string $originalClassName, array $arguments = [], string $mockClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true, array $mockedMethods = null, bool $cloneArguments = true): MockObject + public function mockObjectForAbstractClass(string $originalClassName, array $arguments = [], string $mockClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true, ?array $mockedMethods = null, bool $cloneArguments = true): MockObject { if (class_exists($originalClassName, $callAutoload) || interface_exists($originalClassName, $callAutoload)) { @@ -302,7 +302,7 @@ interface_exists($originalClassName, $callAutoload)) { * * @deprecated https://github.com/sebastianbergmann/phpunit/issues/5243 */ - public function mockObjectForTrait(string $traitName, array $arguments = [], string $mockClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true, array $mockedMethods = null, bool $cloneArguments = true): MockObject + public function mockObjectForTrait(string $traitName, array $arguments = [], string $mockClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true, ?array $mockedMethods = null, bool $cloneArguments = true): MockObject { if (!trait_exists($traitName, $callAutoload)) { throw new UnknownTraitException($traitName); @@ -385,7 +385,7 @@ public function objectForTrait(string $traitName, string $traitClassName = '', b * * @see https://github.com/sebastianbergmann/phpunit/issues/5476 */ - public function generate(string $type, bool $mockObject, bool $markAsMockObject, array $methods = null, string $mockClassName = '', bool $callOriginalClone = true, bool $callAutoload = true, bool $cloneArguments = true, bool $callOriginalMethods = false): MockClass + public function generate(string $type, bool $mockObject, bool $markAsMockObject, ?array $methods = null, string $mockClassName = '', bool $callOriginalClone = true, bool $callAutoload = true, bool $cloneArguments = true, bool $callOriginalMethods = false): MockClass { if ($mockClassName !== '') { return $this->generateCodeForTestDoubleClass( @@ -571,7 +571,7 @@ private function userDefinedInterfaceMethods(string $interfaceName): array * @throws ReflectionException * @throws RuntimeException */ - private function getObject(MockType $mockClass, string $type = '', bool $callOriginalConstructor = false, array $arguments = [], bool $callOriginalMethods = false, object $proxyTarget = null, bool $returnValueGeneration = true): object + private function getObject(MockType $mockClass, string $type = '', bool $callOriginalConstructor = false, array $arguments = [], bool $callOriginalMethods = false, ?object $proxyTarget = null, bool $returnValueGeneration = true): object { $className = $mockClass->generate(); $object = $this->instantiate($className, $callOriginalConstructor, $arguments); diff --git a/src/Runner/PhptTestCase.php b/src/Runner/PhptTestCase.php index 4a6636df787..9ee6ed48471 100644 --- a/src/Runner/PhptTestCase.php +++ b/src/Runner/PhptTestCase.php @@ -84,7 +84,7 @@ final class PhptTestCase implements Reorderable, SelfDescribing, Test * * @throws Exception */ - public function __construct(string $filename, AbstractPhpProcess $phpUtil = null) + public function __construct(string $filename, ?AbstractPhpProcess $phpUtil = null) { if (!is_file($filename)) { throw new FileDoesNotExistException($filename); diff --git a/src/Util/PHP/AbstractPhpProcess.php b/src/Util/PHP/AbstractPhpProcess.php index 1a7b5a9d7a3..221508057a6 100644 --- a/src/Util/PHP/AbstractPhpProcess.php +++ b/src/Util/PHP/AbstractPhpProcess.php @@ -155,7 +155,7 @@ public function runTestJob(string $job, Test $test, string $processResultFile): /** * Returns the command based into the configurations. */ - public function getCommand(array $settings, string $file = null): string + public function getCommand(array $settings, ?string $file = null): string { $runtime = new Runtime;