From 3984249f28c77a90ee64a9f82e9b1cbebe130a6e Mon Sep 17 00:00:00 2001 From: Martin Kluska Date: Sun, 7 Apr 2024 12:32:21 +0200 Subject: [PATCH] feat(phpstan): Update phpstan to max level and use our reusable larastrict/conventions package BC: some expectations now contains correct typehint --- .github/workflows/check-code.yml | 2 +- README.md | 18 ++++++ composer.json | 45 +++++++++------ ecs.php | 28 +++------- phpstan-baseline.neon | 55 +++++++++++++++++++ phpstan.neon | 25 +-------- rector.php | 48 ++++------------ src/Cache/Commands/FlushCacheCommand.php | 2 +- src/Config/Laravel/AppConfig.php | 29 ++++++++-- src/Context/Services/ContextEventsService.php | 2 +- src/Core/Actions/PipeAction.php | 2 +- src/Core/Services/ImplementsService.php | 2 +- src/Database/Models/Casts/FloatCast.php | 3 +- .../Queries/AbstractEloquentQuery.php | 2 +- .../Queries/ChunkedModelQueryResult.php | 7 ++- src/Docker/Config/DockerConfig.php | 9 ++- src/Http/Resources/JsonResource.php | 2 +- src/Http/Resources/JsonResourceCollection.php | 6 +- src/Log/Channels/ConsoleOutputChannel.php | 42 +++++++++++++- src/Log/Handlers/ConsoleOutputHandler.php | 8 ++- src/Log/Managers/ConsoleOutputManager.php | 15 ++--- src/Providers/AbstractBaseServiceProvider.php | 2 +- src/Queue/Actions/RunJobAction.php | 2 +- src/Queue/Actions/RunOrQueueJobAction.php | 4 +- .../Actions/GetNamespaceForStubsAction.php | 11 ++-- src/Testing/Actions/ParsePhpDocAction.php | 2 +- .../Assert/AbstractExpectationCallsMap.php | 2 +- .../Assert/AssertExpectationManager.php | 2 +- .../Commands/MakeExpectationCommand.php | 11 ++-- src/Testing/Concerns/CreateRequest.php | 2 +- .../Auth/Access/GateAbilitiesExpectation.php | 2 +- .../Auth/Access/GateAllowsExpectation.php | 2 +- .../Auth/Access/GateAnyExpectation.php | 2 +- .../Auth/Access/GateCheckExpectation.php | 2 +- .../Auth/Access/GateDeniesExpectation.php | 2 +- .../Auth/Access/GateHasExpectation.php | 2 +- .../Auth/Access/GateInspectExpectation.php | 4 +- .../Contracts/Auth/GuardCheckExpectation.php | 4 +- .../Contracts/Auth/GuardGuestExpectation.php | 4 +- .../Auth/GuardHasUserExpectation.php | 2 +- .../Contracts/Auth/GuardIdExpectation.php | 2 +- .../Contracts/Auth/GuardUserExpectation.php | 5 +- .../Auth/GuardValidateExpectation.php | 2 +- ...DispatcherHasCommandHandlerExpectation.php | 2 +- .../Cache/RepositoryAddExpectation.php | 4 +- .../Cache/RepositoryForeverExpectation.php | 4 +- .../Cache/RepositoryForgetExpectation.php | 2 +- .../Cache/RepositoryGetStoreExpectation.php | 5 +- .../Cache/RepositoryPutExpectation.php | 4 +- .../Debug/ExceptionHandlerAssert.php | 13 ----- .../ExceptionHandlerRenderExpectation.php | 3 +- ...xceptionHandlerShouldReportExpectation.php | 2 +- .../Contracts/Events/DispatcherAssert.php | 49 +---------------- .../Events/DispatcherDispatchExpectation.php | 2 +- .../DispatcherHasListenersExpectation.php | 2 +- .../Events/DispatcherUntilExpectation.php | 7 ++- .../ResponseFactoryDownloadExpectation.php | 3 +- .../ResponseFactoryFileExpectation.php | 3 +- .../ResponseFactoryJsonExpectation.php | 3 +- .../ResponseFactoryJsonpExpectation.php | 3 +- .../ResponseFactoryMakeExpectation.php | 3 +- .../ResponseFactoryNoContentExpectation.php | 3 +- ...esponseFactoryRedirectGuestExpectation.php | 3 +- ...onseFactoryRedirectToActionExpectation.php | 3 +- .../ResponseFactoryRedirectToExpectation.php | 3 +- ...seFactoryRedirectToIntendedExpectation.php | 3 +- ...ponseFactoryRedirectToRouteExpectation.php | 3 +- ...sponseFactoryStreamDownloadExpectation.php | 3 +- .../ResponseFactoryStreamExpectation.php | 3 +- .../ResponseFactoryViewExpectation.php | 3 +- .../TranslatorChoiceExpectation.php | 2 +- .../TranslatorGetLocaleExpectation.php | 2 +- .../View/FactoryComposerExpectation.php | 2 +- .../View/FactoryCreatorExpectation.php | 2 +- .../View/FactoryExistsExpectation.php | 2 +- .../Contracts/View/FactoryFileExpectation.php | 4 +- .../Contracts/View/FactoryMakeExpectation.php | 4 +- .../Contracts/View/ViewGetDataExpectation.php | 2 +- .../Contracts/View/ViewNameExpectation.php | 2 +- .../Contracts/View/ViewRenderExpectation.php | 2 +- src/Testing/Laravel/Routing/UrlGenerator.php | 3 + src/Testing/Laravel/TestingContainer.php | 2 +- src/Testing/PHPUnit/ResourceTestCase.php | 9 ++- src/User/Http/Middlewares/Authenticate.php | 4 +- src/Validation/Rules/NumberRule.php | 4 ++ .../Config/NotUsingPipeConfig.php | 4 +- .../Config/Valid/Config/ValidConfig.php | 4 +- .../Docker/DockerServiceProviderTest.php | 2 +- .../NoConfig/Config/NoConfigConfig.php | 4 +- .../Queue/Actions/RunJobActionTest.php | 2 +- .../TestActionContractAssert.php.stub | 2 +- .../TestReturnActionContractAssert.php.stub | 2 +- ...stReturnUnionActionContractAssert.php.stub | 2 +- .../one.TestActionContractAssert.php.stub | 2 +- ...ne.TestReturnActionContractAssert.php.stub | 2 +- ...stReturnUnionActionContractAssert.php.stub | 2 +- .../two.TestActionContractAssert.php.stub | 2 +- ...wo.TestReturnActionContractAssert.php.stub | 2 +- ...stReturnUnionActionContractAssert.php.stub | 2 +- .../Contracts/Auth/GuardAssertTest.php | 4 +- .../Contracts/Cache/RepositoryAssertTest.php | 24 ++++---- .../Laravel/Contracts/View/ViewAssertTest.php | 4 +- .../Testing/TestServiceProviderTest.php | 15 +++-- .../Http/Resources/ResourceArrayResource.php | 2 +- .../BootViewComposersPipeTest.php | 4 +- .../Testing/Laravel/TestingContainerTest.php | 2 +- 106 files changed, 388 insertions(+), 313 deletions(-) diff --git a/.github/workflows/check-code.yml b/.github/workflows/check-code.yml index 145c60a8..8b747fe2 100644 --- a/.github/workflows/check-code.yml +++ b/.github/workflows/check-code.yml @@ -29,7 +29,7 @@ jobs: name: "Run tests" strategy: matrix: - phpVersion: [ "8.1", "8.2" ] + phpVersion: [ "8.2", "8.3" ] uses: wrk-flow/reusable-workflows/.github/workflows/php-tests.yml@7562253bdc3769847417e3476b501e7126f5d2c0 with: gistID: ${{ vars.GIST_ID }} diff --git a/README.md b/README.md index 24189e66..14afd0c9 100644 --- a/README.md +++ b/README.md @@ -24,3 +24,21 @@ Want more tools or want to help? Check [wrk-flow.com](https://wrk-flow.com) or [ - Make caching more reusable and testable -> `CacheMeService` - Move business logic to `Actions` or `Services` - Setup Laravel for great docker experience. + +## Acknowledgement + +This project owes its existence to the generous support of several other impactful projects: + +- **[Canvastera](https://canvastera.com)** - Empowering users to craft multimedia posters and share them worldwide. (EDU/Hobby) +- **[Azzurro Travel Agency](https://azzurro.cz)** - Specializing in holidays in Italy. +- **[Redtag Studio](https://redtag.studio)** - Crafting digital products for your enjoyment. + +Explore more of our open-source initiatives: + +- **[Larastrict](https://larastrict.com)** - Enhancing the Laravel Framework with a suite of convenient tools and packages. +- **[StrictPHP](https://strictphp.com)** - Enabling strictness in PHP projects through a curated set of packages and conventions, fostering the development of robust production-grade applications. +- **[WrkFlow](https://wrk-flow.com)** - Streamlining development workflows with a comprehensive set of tools designed to boost efficiency. + +## License + +Open-source software licensed under the [MIT License](LICENSE.md). Feel free to use and modify it according to your needs. diff --git a/composer.json b/composer.json index d7cee153..06366301 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,13 @@ "name": "wrkflow/larastrict", "type": "project", "description": "Package to improve Laravel framework with features to support more strict typed Laravel.", - "keywords": ["framework", "laravel", "php", "strictphp", "strict"], + "keywords": [ + "framework", + "laravel", + "php", + "strictphp", + "strict" + ], "license": "MIT", "homepage": "https://github.com/wrk-flow/larastrict", "authors": [ @@ -18,31 +24,33 @@ "psr/simple-cache": "^3.0" }, "require-dev": { - "mockery/mockery": "^1.5.0", - "nette/php-generator": "v4.0.5", - "nikic/php-parser": "v4.15.2", - "nunomaduro/larastan": "2.2.9", - "orchestra/testbench": "^v7.13.0", - "phpstan/phpdoc-parser": "^1.13", - "phpstan/phpstan": "1.9.4", - "phpstan/phpstan-deprecation-rules": "^1.0.0", + "larastrict/conventions": "v0.1.0", + "mockery/mockery": "^1.6", + "nette/php-generator": "^v4.1", + "orchestra/testbench": "^v7", "phpstan/phpstan-mockery": "^1.1.0", - "phpstan/phpstan-phpunit": "^1.1.1", - "phpunit/phpunit": "^9.5.27", - "rector/rector": "0.15.1", - "symplify/easy-coding-standard": "11.1.20" + "phpstan/phpdoc-parser": "^1.13" }, "scripts": { "post-autoload-dump": [ "@php ./vendor/bin/testbench package:discover --ansi" ], - "check": "composer lint && composer test && composer lint:stan", + "analyse": "./vendor/bin/phpstan", + "check": [ + "@lint", + "@test", + "@analyse" + ], + "lint": [ + "@lint:fix", + "@lint:upgrade" + ], "lint:check": "./vendor/bin/ecs", "lint:fix": "./vendor/bin/ecs --fix", "lint:stan": "./vendor/bin/phpstan", - "lint:upgrade:check": "vendor/bin/rector process --dry-run", "lint:upgrade": "vendor/bin/rector process", - "lint": "composer lint:upgrade && composer lint:fix && composer lint:stan", + "lint:upgrade:check": "vendor/bin/rector process --dry-run", + "lint:stan:b": "./vendor/bin/phpstan -b", "test": "./vendor/bin/phpunit", "test:stubs": "STUBS_GENERATE=true ./vendor/bin/phpunit", "test:coverage": "./vendor/bin/phpunit --coverage-text" @@ -75,7 +83,10 @@ "config": { "optimize-autoloader": true, "preferred-install": "dist", - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "phpstan/extension-installer": true + } }, "minimum-stability": "dev", "prefer-stable": true diff --git a/ecs.php b/ecs.php index c116b813..33799139 100644 --- a/ecs.php +++ b/ecs.php @@ -7,27 +7,13 @@ use Symplify\EasyCodingStandard\Config\ECSConfig; use Symplify\EasyCodingStandard\ValueObject\Set\SetList; -return static function (ECSConfig $containerConfigurator): void { - $containerConfigurator->import(SetList::PSR_12); - $containerConfigurator->import(SetList::SYMPLIFY); - $containerConfigurator->import(SetList::COMMON); - $containerConfigurator->import(SetList::CLEAN_CODE); - - $containerConfigurator->ruleWithConfiguration(ClassAttributesSeparationFixer::class, [ - 'elements' => [ - 'const' => 'only_if_meta', - 'property' => 'one', - 'method' => 'one', - ], - ]); - - $containerConfigurator->parallel(); - $containerConfigurator->paths( - [__DIR__ . '/src', __DIR__ . '/tests', __DIR__ . '/ecs.php', __DIR__ . '/rector.php'] - ); - $containerConfigurator->skip([ - YodaStyleFixer::class, +return ECSConfig::configure() + ->withRootFiles() + ->withPaths([__DIR__ . '/src', __DIR__ . '/tests']) + ->withSets([ + __DIR__ . '/vendor/larastrict/conventions/extension-ecs.php' + ]) + ->withSkip([ // We want to leave the relative constant path usage __DIR__ . '/tests/Feature/Testing/Commands/MakeExpectationCommand/*.php', ]); -}; diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 882c4abb..c9967170 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,5 +1,25 @@ parameters: ignoreErrors: + - + message: "#^Parameter \\$createState of method LaraStrict\\\\Context\\\\Services\\\\ContextService\\:\\:get\\(\\) expects Closure\\(mixed, mixed, mixed, mixed, mixed, mixed\\)\\: LaraStrict\\\\Context\\\\Values\\\\BoolContextValue, Closure\\(Illuminate\\\\Contracts\\\\Container\\\\Container\\)\\: LaraStrict\\\\Context\\\\Values\\\\BoolContextValue given\\.$#" + count: 1 + path: src/Context/Services/ContextService.php + + - + message: "#^Parameter \\#1 \\$ of closure expects TModel of Illuminate\\\\Database\\\\Eloquent\\\\Model, mixed given\\.$#" + count: 1 + path: src/Database/Queries/ChunkedModelQueryResult.php + + - + message: "#^Parameter \\#1 \\$ of closure expects array\\, array\\, mixed\\> given\\.$#" + count: 1 + path: src/Database/Queries/ChunkedModelQueryResult.php + + - + message: "#^Parameter \\#2 \\$callback of method Illuminate\\\\Database\\\\Eloquent\\\\Builder\\\\:\\:chunk\\(\\) expects callable\\(Illuminate\\\\Database\\\\Eloquent\\\\Collection\\, int\\)\\: mixed, Closure\\(Illuminate\\\\Database\\\\Eloquent\\\\Collection\\\\)\\: void given\\.$#" + count: 1 + path: src/Database/Queries/ChunkedModelQueryResult.php + - message: "#^Access to an undefined property LaraStrict\\\\Http\\\\Resources\\\\JsonResource\\:\\:\\$preserveKeys\\.$#" count: 1 @@ -15,6 +35,16 @@ parameters: count: 1 path: src/Http/Resources/JsonResourceCollection.php + - + message: "#^Method LaraStrict\\\\Log\\\\Channels\\\\ConsoleOutputChannel\\:\\:getLevel\\(\\) should return 100\\|200\\|250\\|300\\|400\\|500\\|550\\|600\\|'ALERT'\\|'alert'\\|'CRITICAL'\\|'critical'\\|'DEBUG'\\|'debug'\\|'EMERGENCY'\\|'emergency'\\|'ERROR'\\|'error'\\|'INFO'\\|'info'\\|'NOTICE'\\|'notice'\\|'WARNING'\\|'warning' but returns int\\|string\\.$#" + count: 1 + path: src/Log/Channels/ConsoleOutputChannel.php + + - + message: "#^Parameter \\$getValue of method LaraStrict\\\\Cache\\\\Contracts\\\\CacheMeServiceContract\\:\\:get\\(\\) expects Closure\\(mixed, mixed, mixed, mixed, mixed, mixed\\)\\: LaraStrict\\\\Providers\\\\Entities\\\\AppServiceProviderEntity, Closure\\(Illuminate\\\\Contracts\\\\Foundation\\\\Application\\)\\: LaraStrict\\\\Providers\\\\Entities\\\\AppServiceProviderEntity given\\.$#" + count: 1 + path: src/Providers/Actions/GetAppServiceProviderForClassAction.php + - message: "#^Cannot cast array\\|string to string\\.$#" count: 1 @@ -25,12 +55,37 @@ parameters: count: 1 path: src/Testing/Actions/ParsePhpDocAction.php + - + message: "#^Method Tests\\\\LaraStrict\\\\Feature\\\\Context\\\\Services\\\\IsContext\\:\\:is\\(\\) should return Closure\\(mixed, mixed, mixed, mixed, mixed\\)\\: bool but returns Closure\\(bool\\)\\: bool\\.$#" + count: 1 + path: tests/Feature/Context/Services/IsContext.php + + - + message: "#^Parameter \\$createState of method LaraStrict\\\\Context\\\\Contracts\\\\ContextServiceContract\\:\\:get\\(\\) expects Closure\\(mixed, mixed, mixed, mixed, mixed, mixed\\)\\: Tests\\\\LaraStrict\\\\Feature\\\\Context\\\\Services\\\\TestValue, Closure\\(string\\)\\: Tests\\\\LaraStrict\\\\Feature\\\\Context\\\\Services\\\\TestValue given\\.$#" + count: 1 + path: tests/Feature/Context/Services/TestDependencyContext.php + - message: "#^Call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertTrue\\(\\) with false and 'Hook should be…' will always evaluate to false\\.$#" count: 1 path: tests/Feature/Testing/Commands/MakeExpectationCommandRealTest.php + - + message: "#^Call to method LaraStrict\\\\Testing\\\\Laravel\\\\Contracts\\\\View\\\\FactoryAssert\\:\\:exists\\(\\) with 'test' will always evaluate to false\\.$#" + count: 2 + path: tests/Feature/Testing/Laravel/Contracts/View/FactoryAssertTest.php + - message: "#^Method Tests\\\\LaraStrict\\\\Feature\\\\Translations\\\\InvalidServiceProviderTranslations\\:\\:getProviderClass\\(\\) should return class\\-string\\ but returns string\\.$#" count: 1 path: tests/Feature/Translations/InvalidServiceProviderTranslations.php + + - + message: "#^Parameter \\$createState of method LaraStrict\\\\Testing\\\\Context\\\\Contracts\\\\ContextServiceContractAssert\\:\\:get\\(\\) expects Closure\\(mixed, mixed, mixed, mixed, mixed, mixed\\)\\: Tests\\\\LaraStrict\\\\Feature\\\\Context\\\\Services\\\\TestValue, Closure\\(string\\)\\: Tests\\\\LaraStrict\\\\Feature\\\\Context\\\\Services\\\\TestValue given\\.$#" + count: 2 + path: tests/Unit/Testing/Context/Contracts/ContextServiceContractAssertTest.php + + - + message: "#^Parameter \\$is of method LaraStrict\\\\Testing\\\\Context\\\\Contracts\\\\ContextServiceContractAssert\\:\\:is\\(\\) expects Closure\\(mixed, mixed, mixed, mixed, mixed, mixed\\)\\: bool, Closure\\(string\\)\\: true given\\.$#" + count: 1 + path: tests/Unit/Testing/Context/Contracts/ContextServiceContractAssertTest.php diff --git a/phpstan.neon b/phpstan.neon index ab1461dd..3d5d55a6 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,35 +1,16 @@ includes: - - vendor/nunomaduro/larastan/extension.neon - - vendor/phpstan/phpstan-phpunit/extension.neon - - vendor/phpstan/phpstan-phpunit/rules.neon - - vendor/phpstan/phpstan-deprecation-rules/rules.neon - - vendor/phpstan/phpstan-mockery/extension.neon - phpstan-baseline.neon parameters: - reportUnmatchedIgnoredErrors: true + level: max - parallel: - processTimeout: 600.0 + # Due the tests between Laravel versions + reportUnmatchedIgnoredErrors: true paths: - src - tests - # The level 8 is the highest level - level: 8 - - # it is impossible to map toArray() - checkMissingIterableValueType: false - excludePaths: - 'tests/Feature/Testing/Commands/MakeExpectationCommand/*.php' - ignoreErrors: - # CastsAttributes template was added in Laravel 9.49 (remove when we drop L9 support) - - - message: "#^PHPDoc tag @implements contains generic type Illuminate\\\\Contracts\\\\Database\\\\Eloquent\\\\CastsAttributes\\ but interface Illuminate\\\\Contracts\\\\Database\\\\Eloquent\\\\CastsAttributes is not generic\\.$#" - count: 1 - path: src/Database/Models/Casts/FloatCast.php - reportUnmatched: false - diff --git a/rector.php b/rector.php index 7f351a69..2cc2be7b 100644 --- a/rector.php +++ b/rector.php @@ -2,48 +2,22 @@ declare(strict_types=1); -use Rector\CodeQuality\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector; use Rector\CodingStyle\Rector\ArrowFunction\StaticArrowFunctionRector; -use Rector\CodingStyle\Rector\ClassConst\VarConstantCommentRector; -use Rector\CodingStyle\Rector\ClassMethod\UnSpreadOperatorRector; -use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector; use Rector\Config\RectorConfig; -use Rector\Core\ValueObject\PhpVersion; -use Rector\Set\ValueObject\LevelSetList; -use Rector\Set\ValueObject\SetList; -use Rector\Strict\Rector\AbstractFalsyScalarRuleFixerRector; -use Rector\Strict\Rector\BooleanNot\BooleanInBooleanNotRuleFixerRector; -return static function (RectorConfig $config): void { - $config->paths([__DIR__ . '/src', __DIR__ . '/tests']); - $config->phpVersion(PhpVersion::PHP_81); +// SKIP laravel +$laravelClasses = [ + __DIR__ . '/src/Testing/Laravel/TestingApplication.php', + __DIR__ . '/src/Testing/Laravel/TestingContainer.php', + __DIR__ . '/src/Testing/Laravel/Filesystem/Filesystem.php', +]; - // Define what rule sets will be applied - $config->import(LevelSetList::UP_TO_PHP_81); - $config->import(SetList::CODE_QUALITY); - $config->import(SetList::CODING_STYLE); - $config->importNames(); - - $config->ruleWithConfiguration( - BooleanInBooleanNotRuleFixerRector::class, - [ - AbstractFalsyScalarRuleFixerRector::TREAT_AS_NON_EMPTY => false, - ] - ); - - // SKIP laravel - $laravelClasses = [ - __DIR__ . '/src/Testing/Laravel/TestingApplication.php', - __DIR__ . '/src/Testing/Laravel/TestingContainer.php', - __DIR__ . '/src/Testing/Laravel/Filesystem/Filesystem.php', - ]; - $config->skip([ - UnSpreadOperatorRector::class => $laravelClasses, - ReturnTypeFromStrictScalarReturnExprRector::class => $laravelClasses, - VarConstantCommentRector::class, - NewlineAfterStatementRector::class, +return RectorConfig::configure() + ->withSets([__DIR__.'/vendor/larastrict/conventions/extension-rector.php']) + ->withRootFiles() + ->withPaths([__DIR__ . '/src', __DIR__ . '/tests']) + ->withSkip([ StaticArrowFunctionRector::class => [__DIR__ . '/src/Log/Managers/ConsoleOutputManager.php'], // We want to leave the relative constant path usage __DIR__ . '/tests/Feature/Testing/Commands/MakeExpectationCommand/*.php', ]); -}; diff --git a/src/Cache/Commands/FlushCacheCommand.php b/src/Cache/Commands/FlushCacheCommand.php index 9b9e4758..7e50177a 100644 --- a/src/Cache/Commands/FlushCacheCommand.php +++ b/src/Cache/Commands/FlushCacheCommand.php @@ -17,7 +17,7 @@ public function handle(CacheMeService $cacheMeService): void { $tagOrKey = $this->argument('tagOrKey'); - if (is_string($tagOrKey) === false) { + if (! is_string($tagOrKey)) { $this->info('Only string value is supported'); return; } diff --git a/src/Config/Laravel/AppConfig.php b/src/Config/Laravel/AppConfig.php index 61ad3dbf..11913aef 100644 --- a/src/Config/Laravel/AppConfig.php +++ b/src/Config/Laravel/AppConfig.php @@ -24,32 +24,48 @@ class AppConfig extends AbstractConfig implements AppConfigContract */ public function getVersion(): string { - return (string) ($this->get(self::KeyVersion, null, true) ?? 'DEV.' . time()); + $value = ($this->get(self::KeyVersion, null, true) ?? 'DEV.' . time()); + assert(is_string($value) || is_numeric($value)); + return (string) $value; } public function getKey(): string { - return $this->get(self::KeyKey); + $value = $this->get(self::KeyKey); + assert(is_string($value)); + return $value; } public function getUrl(): string { - return $this->get(self::KeyUrl, emptyToDefault: true); + $value = $this->get(self::KeyUrl, emptyToDefault: true); + assert(is_string($value)); + return $value; } public function getAssetUrl(): ?string { - return $this->get(self::KeyAssetUrl, null, true); + $value = $this->get(self::KeyAssetUrl, null, true); + if ($value === null) { + return null; + } + + assert(is_string($value)); + return $value; } public function getName(): string { - return $this->get(self::KeyName, emptyToDefault: true); + $value = $this->get(self::KeyName, emptyToDefault: true); + assert(is_string($value)); + return $value; } public function isInDebugMode(): bool { - return (bool) $this->get(self::KeyDebug, false, true); + $value = $this->get(self::KeyDebug, false, true); + assert(is_bool($value) || is_numeric($value) || is_string($value)); + return (bool) $value; } public function getEnvironment(): EnvironmentType|string @@ -63,6 +79,7 @@ public function getEnvironment(): EnvironmentType|string if (is_int($env)) { $env = 'production'; } + assert(is_string($env)); $envType = EnvironmentType::tryFrom($env); diff --git a/src/Context/Services/ContextEventsService.php b/src/Context/Services/ContextEventsService.php index 9aa7a792..505c544b 100644 --- a/src/Context/Services/ContextEventsService.php +++ b/src/Context/Services/ContextEventsService.php @@ -45,7 +45,7 @@ function ($event) use ($createContext, $getStateToStore): void { 'event' => $event, ]); - if ($value === null) { + if (($value instanceof ContextValueContract) === false) { return; } diff --git a/src/Core/Actions/PipeAction.php b/src/Core/Actions/PipeAction.php index ee5517d7..327a0826 100644 --- a/src/Core/Actions/PipeAction.php +++ b/src/Core/Actions/PipeAction.php @@ -27,6 +27,6 @@ public function execute(array $closures, Closure $default = null): mixed } } - return $default === null ? null : $default(); + return $default instanceof Closure ? $default() : null; } } diff --git a/src/Core/Services/ImplementsService.php b/src/Core/Services/ImplementsService.php index 88ab5e1f..86066ba9 100644 --- a/src/Core/Services/ImplementsService.php +++ b/src/Core/Services/ImplementsService.php @@ -21,7 +21,7 @@ public function get(object $object): array if (array_key_exists($className, $this->classImplementsCache) === false) { $classImplements = class_implements($object); - $this->classImplementsCache[$className] = is_array($classImplements) ? $classImplements : []; + $this->classImplementsCache[$className] = $classImplements; } return $this->classImplementsCache[$className]; diff --git a/src/Database/Models/Casts/FloatCast.php b/src/Database/Models/Casts/FloatCast.php index 8a45eb45..84abcf44 100644 --- a/src/Database/Models/Casts/FloatCast.php +++ b/src/Database/Models/Casts/FloatCast.php @@ -29,11 +29,12 @@ public function __construct( public function get($model, string $key, $value, array $attributes) { - if ($value === null || $value === '') { + if ($value === null || $value === '' || ! is_numeric($value) || ! is_string($value)) { return $this->nonNull ? 0.0 : null; } return (float) $value; + } public function set($model, string $key, $value, array $attributes): ?string diff --git a/src/Database/Queries/AbstractEloquentQuery.php b/src/Database/Queries/AbstractEloquentQuery.php index 2c9cad77..55c75e04 100644 --- a/src/Database/Queries/AbstractEloquentQuery.php +++ b/src/Database/Queries/AbstractEloquentQuery.php @@ -165,7 +165,7 @@ protected function findOrFail(string|int $key, array $scopes = [], Closure $cust return $model; } catch (ModelNotFoundException $modelNotFoundException) { - if ($customException === null) { + if (! $customException instanceof Closure) { throw $modelNotFoundException; } diff --git a/src/Database/Queries/ChunkedModelQueryResult.php b/src/Database/Queries/ChunkedModelQueryResult.php index 3136342e..52e58910 100644 --- a/src/Database/Queries/ChunkedModelQueryResult.php +++ b/src/Database/Queries/ChunkedModelQueryResult.php @@ -11,6 +11,7 @@ /** * @template TModel of \Illuminate\Database\Eloquent\Model + * @todo deprecate in favor of Generator */ class ChunkedModelQueryResult { @@ -98,9 +99,9 @@ public function onEntry(Closure $closure, ?int $count = null): int $this->onChunk( function (Collection $collection) use ($closure, &$processed): void { foreach ($collection as $entry) { - $wrappedEntry = $this->onEntryTransform === null - ? $entry - : call_user_func($this->onEntryTransform, $entry); + $wrappedEntry = $this->onEntryTransform instanceof Closure + ? call_user_func($this->onEntryTransform, $entry) + : $entry; $closure($wrappedEntry); ++$processed; diff --git a/src/Docker/Config/DockerConfig.php b/src/Docker/Config/DockerConfig.php index 92a68677..7079aa39 100644 --- a/src/Docker/Config/DockerConfig.php +++ b/src/Docker/Config/DockerConfig.php @@ -14,7 +14,10 @@ class DockerConfig extends AbstractProviderConfig public function isInDockerEnvironment(): bool { - return $this->get(keyOrPath: self::KeyInDockerEnvironment); + $bool = $this->get(keyOrPath: self::KeyInDockerEnvironment); + assert(is_bool($bool) || is_string($bool) || is_int($bool)); + + return (bool) $bool; } public function setIsInDockerEnvironment(bool $value): void @@ -24,7 +27,9 @@ public function setIsInDockerEnvironment(bool $value): void public function getDockerOutputProcess(): string { - return $this->get(keyOrPath: self::KeyOutputProcess); + $value = $this->get(keyOrPath: self::KeyOutputProcess); + assert(is_string($value)); + return $value; } protected function getServiceProvider(): string diff --git a/src/Http/Resources/JsonResource.php b/src/Http/Resources/JsonResource.php index 939661d5..a281c539 100644 --- a/src/Http/Resources/JsonResource.php +++ b/src/Http/Resources/JsonResource.php @@ -36,7 +36,7 @@ static function (JsonResourceCollection $collection) { protected function getContainer(): Container { - if ($this->container === null) { + if (! $this->container instanceof \Illuminate\Contracts\Container\Container) { return LaravelContainer::getInstance(); } diff --git a/src/Http/Resources/JsonResourceCollection.php b/src/Http/Resources/JsonResourceCollection.php index ebd88ab9..6f63ed0f 100644 --- a/src/Http/Resources/JsonResourceCollection.php +++ b/src/Http/Resources/JsonResourceCollection.php @@ -20,8 +20,10 @@ public function setContainer(?Container $container): self public function toArray($request) { - return $this->collection->map(function (JsonResource $resource) use ($request) { - if ($this->container !== null) { + return $this->collection->map(function (mixed $resource) use ($request) { + assert($resource instanceof JsonResource); + + if ($this->container instanceof Container) { $resource->setContainer($this->container); } diff --git a/src/Log/Channels/ConsoleOutputChannel.php b/src/Log/Channels/ConsoleOutputChannel.php index 23306047..e48bcaf2 100644 --- a/src/Log/Channels/ConsoleOutputChannel.php +++ b/src/Log/Channels/ConsoleOutputChannel.php @@ -8,9 +8,12 @@ use LaraStrict\Log\Handlers\ConsoleOutputHandler; use LaraStrict\Log\Managers\ConsoleOutputManager; use Monolog\Logger; +use Psr\Log\LogLevel; /** * @internal + * @phpstan-import-type LevelName from Logger + * @phpstan-import-type Level from Logger */ final class ConsoleOutputChannel extends LogManager { @@ -19,10 +22,11 @@ final class ConsoleOutputChannel extends LogManager */ public function __invoke(array $config): Logger { + $handler = new ConsoleOutputHandler( manager: $this->app->make(ConsoleOutputManager::class), - level: $config['level'] ?? Logger::DEBUG, - bubble: $config['bubble'] ?? true, + level: self::getLevel($config), + bubble: self::getBubble($config), ); return new Logger( @@ -30,4 +34,38 @@ public function __invoke(array $config): Logger handlers: [$this->prepareHandler($handler, $config)] ); } + + /** + * @param array $config + * + * @phpstan-return Level|LevelName|LogLevel::* + */ + private static function getLevel(array $config): int|string + { + if (array_key_exists('level', $config)) { + $level = $config['level']; + + if (is_string($level) || is_int($level)) { + return $level; + } + } + + return Logger::DEBUG; + } + + /** + * @param array $config + */ + private static function getBubble(array $config): bool + { + if (array_key_exists('bubble', $config)) { + $bubble = $config['bubble']; + + if (is_string($bubble) || is_int($bubble) || is_bool($bubble)) { + return (bool) $bubble; + } + } + + return true; + } } diff --git a/src/Log/Handlers/ConsoleOutputHandler.php b/src/Log/Handlers/ConsoleOutputHandler.php index b634960a..4cb6e26c 100644 --- a/src/Log/Handlers/ConsoleOutputHandler.php +++ b/src/Log/Handlers/ConsoleOutputHandler.php @@ -9,16 +9,22 @@ use LaraStrict\Log\Managers\ConsoleOutputManager; use Monolog\Handler\AbstractProcessingHandler; use Monolog\Logger; +use Psr\Log\LogLevel; use Symfony\Component\Console\Output\OutputInterface; /** * @internal + * @phpstan-import-type LevelName from Logger + * @phpstan-import-type Level from Logger */ final class ConsoleOutputHandler extends AbstractProcessingHandler { + /** + * @phpstan-param Level|LevelName|LogLevel::* $level + */ public function __construct( private readonly ConsoleOutputManager $manager, - $level = Logger::DEBUG, + string|int $level = Logger::DEBUG, bool $bubble = true ) { parent::__construct($level, $bubble); diff --git a/src/Log/Managers/ConsoleOutputManager.php b/src/Log/Managers/ConsoleOutputManager.php index 591b1b8b..8c72e57b 100644 --- a/src/Log/Managers/ConsoleOutputManager.php +++ b/src/Log/Managers/ConsoleOutputManager.php @@ -15,7 +15,6 @@ use Illuminate\Support\Env; use LaraStrict\Docker\Config\DockerConfig; use LaraStrict\Log\Channels\ConsoleOutputChannel; -use RuntimeException; use Symfony\Component\Console\Input\StringInput; use Symfony\Component\Console\Output\OutputInterface; @@ -55,9 +54,9 @@ public function setCurrentOutput(?OutputInterface $currentOutput): self { $this->currentOutput = $currentOutput; - $this->outputStyle = $currentOutput === null - ? null - : new OutputStyle(new StringInput(''), $currentOutput); + $this->outputStyle = $currentOutput instanceof OutputInterface + ? new OutputStyle(new StringInput(''), $currentOutput) + : null; $this->outputFactory = $this->outputStyle instanceof OutputStyle === false ? null : new Factory($this->outputStyle); @@ -160,13 +159,7 @@ public function boot(): void */ protected function getLogManager(): LogManager { - $logManager = $this->container->make('log'); - - if ($logManager instanceof LogManager === false) { - throw new RuntimeException('Log manager must be instance of ' . LogManager::class); - } - - return $logManager; + return $this->container->make('log'); } /** diff --git a/src/Providers/AbstractBaseServiceProvider.php b/src/Providers/AbstractBaseServiceProvider.php index 5491a008..3e101d11 100644 --- a/src/Providers/AbstractBaseServiceProvider.php +++ b/src/Providers/AbstractBaseServiceProvider.php @@ -38,7 +38,7 @@ public function boot(): void public function getAppServiceProvider(): AppServiceProviderEntity { - if ($this->appServiceProvider === null) { + if (! $this->appServiceProvider instanceof AppServiceProviderEntity) { $action = $this->app->make($this->getCreateAppServiceProviderActionClass()); assert($action instanceof CreateAppServiceProviderActionContract); diff --git a/src/Queue/Actions/RunJobAction.php b/src/Queue/Actions/RunJobAction.php index 0cba8790..8e5b8f9b 100644 --- a/src/Queue/Actions/RunJobAction.php +++ b/src/Queue/Actions/RunJobAction.php @@ -20,7 +20,7 @@ public function __construct( public function execute(Job $job, ?Command $command = null, string $method = null): mixed { - if ($command !== null && $job instanceof UsesCommandInterface) { + if ($command instanceof Command && $job instanceof UsesCommandInterface) { $job->setCommand($command); } diff --git a/src/Queue/Actions/RunOrQueueJobAction.php b/src/Queue/Actions/RunOrQueueJobAction.php index 0aae5c2c..8d83baef 100644 --- a/src/Queue/Actions/RunOrQueueJobAction.php +++ b/src/Queue/Actions/RunOrQueueJobAction.php @@ -34,13 +34,13 @@ public function execute( ?bool $shouldQueue = null, ): mixed { if ($shouldQueue === true - || $shouldQueue === null && ($command === null || $command->option('queue') === true)) { + || $shouldQueue === null && (! $command instanceof Command || $command->option('queue') === true)) { $this->dispatchJobAction->execute($job); return null; } - if ($setupBeforeRun !== null) { + if ($setupBeforeRun instanceof Closure) { $setupBeforeRun($job); } diff --git a/src/Testing/Actions/GetNamespaceForStubsAction.php b/src/Testing/Actions/GetNamespaceForStubsAction.php index 5e64d34e..0dd43ebe 100644 --- a/src/Testing/Actions/GetNamespaceForStubsAction.php +++ b/src/Testing/Actions/GetNamespaceForStubsAction.php @@ -47,15 +47,18 @@ public function execute(Command $command, string $basePath, string $inputClass): return new NamespaceEntity($folder, $baseNamespace); } - protected function getComposerJsonData(string $basePath): mixed + protected function getComposerJsonData(string $basePath): array { - return json_decode($this->filesystem->get($basePath . '/composer.json'), true, 512, JSON_THROW_ON_ERROR); + $json = json_decode($this->filesystem->get($basePath . '/composer.json'), true, 512, JSON_THROW_ON_ERROR); + assert(is_array($json)); + return $json; } private function getComposerDevAutoLoad(array $composer): array { - if (isset($composer[self::ComposerAutoLoadDev]) - && isset($composer[self::ComposerAutoLoadDev][self::ComposerPsr4])) { + if (isset($composer[self::ComposerAutoLoadDev][self::ComposerPsr4]) && is_array( + $composer[self::ComposerAutoLoadDev][self::ComposerPsr4] + )) { return $composer[self::ComposerAutoLoadDev][self::ComposerPsr4]; } diff --git a/src/Testing/Actions/ParsePhpDocAction.php b/src/Testing/Actions/ParsePhpDocAction.php index bfef1a1d..0a5a85b6 100644 --- a/src/Testing/Actions/ParsePhpDocAction.php +++ b/src/Testing/Actions/ParsePhpDocAction.php @@ -28,7 +28,7 @@ public function __construct(Container $container) public function execute(ReflectionMethod $method): PhpDocEntity { - if ($this->phpDocStringResolver === null) { + if (! $this->phpDocStringResolver instanceof PhpDocStringResolver) { return new PhpDocEntity(); } diff --git a/src/Testing/Assert/AbstractExpectationCallsMap.php b/src/Testing/Assert/AbstractExpectationCallsMap.php index 64cec2dd..64b45508 100644 --- a/src/Testing/Assert/AbstractExpectationCallsMap.php +++ b/src/Testing/Assert/AbstractExpectationCallsMap.php @@ -36,7 +36,7 @@ public function addExpectation(object $expectation): self } /** - * @template TExpectation + * @template TExpectation of object * * @param class-string $class * @param array $expectations diff --git a/src/Testing/Assert/AssertExpectationManager.php b/src/Testing/Assert/AssertExpectationManager.php index f6555a04..c4a29541 100644 --- a/src/Testing/Assert/AssertExpectationManager.php +++ b/src/Testing/Assert/AssertExpectationManager.php @@ -18,7 +18,7 @@ final class AssertExpectationManager public static function getInstance(): self { - if (self::$singleton === null) { + if (! self::$singleton instanceof self) { self::$singleton = new self(); } diff --git a/src/Testing/Commands/MakeExpectationCommand.php b/src/Testing/Commands/MakeExpectationCommand.php index 38bb55a5..b706c389 100644 --- a/src/Testing/Commands/MakeExpectationCommand.php +++ b/src/Testing/Commands/MakeExpectationCommand.php @@ -133,7 +133,7 @@ className: $expectationClassName, ), ); - if ($assertFileState !== null) { + if ($assertFileState instanceof AssertFileStateEntity) { $methodName = $method->getName(); $assertFileState->constructorComments[] = sprintf( @@ -162,8 +162,8 @@ className: $expectationClassName, } } - if ($assertFileState !== null) { - if ($assertFileState->constructor !== null) { + if ($assertFileState instanceof AssertFileStateEntity) { + if ($assertFileState->constructor instanceof Method) { $assertFileState->constructor->addComment(implode(PHP_EOL, $assertFileState->constructorComments)); $assertFileState->constructor->addBody(implode(PHP_EOL, $assertFileState->constructorBodies)); } @@ -481,9 +481,10 @@ protected function canReturnExpectation(ReflectionNamedType $returnType): bool */ private function getInputClass(string $basePath, Filesystem $filesystem): ?string { - /** @phpstan-var class-string|string $class */ - $class = (string) $this->input->getArgument('class'); + $class = $this->input->getArgument('class'); + assert(is_string($class), 'Class must be a string'); + /** @phpstan-var class-string|string $class */ if (str_ends_with($class, '.php')) { $fullPath = $basePath . '/' . $class; diff --git a/src/Testing/Concerns/CreateRequest.php b/src/Testing/Concerns/CreateRequest.php index 8c5505be..30d31f23 100644 --- a/src/Testing/Concerns/CreateRequest.php +++ b/src/Testing/Concerns/CreateRequest.php @@ -107,7 +107,7 @@ protected function createFormRequest( ) ); - if ($user !== null) { + if ($user instanceof Authenticatable) { $request->setUserResolver(static fn () => $user); } diff --git a/src/Testing/Laravel/Contracts/Auth/Access/GateAbilitiesExpectation.php b/src/Testing/Laravel/Contracts/Auth/Access/GateAbilitiesExpectation.php index 540280c0..2c23abda 100644 --- a/src/Testing/Laravel/Contracts/Auth/Access/GateAbilitiesExpectation.php +++ b/src/Testing/Laravel/Contracts/Auth/Access/GateAbilitiesExpectation.php @@ -7,7 +7,7 @@ final class GateAbilitiesExpectation { public function __construct( - public readonly mixed $return + public readonly array $return ) { } } diff --git a/src/Testing/Laravel/Contracts/Auth/Access/GateAllowsExpectation.php b/src/Testing/Laravel/Contracts/Auth/Access/GateAllowsExpectation.php index 74fdf1e8..af0f209a 100644 --- a/src/Testing/Laravel/Contracts/Auth/Access/GateAllowsExpectation.php +++ b/src/Testing/Laravel/Contracts/Auth/Access/GateAllowsExpectation.php @@ -7,7 +7,7 @@ final class GateAllowsExpectation { public function __construct( - public readonly mixed $return, + public readonly bool $return, public readonly mixed $ability, public readonly mixed $arguments = [], ) { diff --git a/src/Testing/Laravel/Contracts/Auth/Access/GateAnyExpectation.php b/src/Testing/Laravel/Contracts/Auth/Access/GateAnyExpectation.php index c0439930..80503ff9 100644 --- a/src/Testing/Laravel/Contracts/Auth/Access/GateAnyExpectation.php +++ b/src/Testing/Laravel/Contracts/Auth/Access/GateAnyExpectation.php @@ -7,7 +7,7 @@ final class GateAnyExpectation { public function __construct( - public readonly mixed $return, + public readonly bool $return, public readonly mixed $abilities, public readonly mixed $arguments = [], ) { diff --git a/src/Testing/Laravel/Contracts/Auth/Access/GateCheckExpectation.php b/src/Testing/Laravel/Contracts/Auth/Access/GateCheckExpectation.php index 0a320e4f..7708ae59 100644 --- a/src/Testing/Laravel/Contracts/Auth/Access/GateCheckExpectation.php +++ b/src/Testing/Laravel/Contracts/Auth/Access/GateCheckExpectation.php @@ -7,7 +7,7 @@ final class GateCheckExpectation { public function __construct( - public readonly mixed $return, + public readonly bool $return, public readonly mixed $abilities, public readonly mixed $arguments = [], ) { diff --git a/src/Testing/Laravel/Contracts/Auth/Access/GateDeniesExpectation.php b/src/Testing/Laravel/Contracts/Auth/Access/GateDeniesExpectation.php index 34bfdb09..b580301a 100644 --- a/src/Testing/Laravel/Contracts/Auth/Access/GateDeniesExpectation.php +++ b/src/Testing/Laravel/Contracts/Auth/Access/GateDeniesExpectation.php @@ -7,7 +7,7 @@ final class GateDeniesExpectation { public function __construct( - public readonly mixed $return, + public readonly bool $return, public readonly mixed $ability, public readonly mixed $arguments = [], ) { diff --git a/src/Testing/Laravel/Contracts/Auth/Access/GateHasExpectation.php b/src/Testing/Laravel/Contracts/Auth/Access/GateHasExpectation.php index dd6a7927..c39ad860 100644 --- a/src/Testing/Laravel/Contracts/Auth/Access/GateHasExpectation.php +++ b/src/Testing/Laravel/Contracts/Auth/Access/GateHasExpectation.php @@ -7,7 +7,7 @@ final class GateHasExpectation { public function __construct( - public readonly mixed $return, + public readonly bool $return, public readonly mixed $ability, ) { } diff --git a/src/Testing/Laravel/Contracts/Auth/Access/GateInspectExpectation.php b/src/Testing/Laravel/Contracts/Auth/Access/GateInspectExpectation.php index 69628b16..096c354f 100644 --- a/src/Testing/Laravel/Contracts/Auth/Access/GateInspectExpectation.php +++ b/src/Testing/Laravel/Contracts/Auth/Access/GateInspectExpectation.php @@ -4,10 +4,12 @@ namespace LaraStrict\Testing\Laravel\Contracts\Auth\Access; +use Illuminate\Auth\Access\Response; + final class GateInspectExpectation { public function __construct( - public readonly mixed $return, + public readonly Response $return, public readonly mixed $ability, public readonly mixed $arguments = [], ) { diff --git a/src/Testing/Laravel/Contracts/Auth/GuardCheckExpectation.php b/src/Testing/Laravel/Contracts/Auth/GuardCheckExpectation.php index 1f98b10d..6e96d32b 100644 --- a/src/Testing/Laravel/Contracts/Auth/GuardCheckExpectation.php +++ b/src/Testing/Laravel/Contracts/Auth/GuardCheckExpectation.php @@ -9,10 +9,10 @@ final class GuardCheckExpectation { /** - * @param Closure(self):void|null $hook + * @param Closure(bool):void|null $hook */ public function __construct( - public readonly mixed $return, + public readonly bool $return, public readonly ?Closure $hook = null, ) { } diff --git a/src/Testing/Laravel/Contracts/Auth/GuardGuestExpectation.php b/src/Testing/Laravel/Contracts/Auth/GuardGuestExpectation.php index b1981e1c..e528a8ce 100644 --- a/src/Testing/Laravel/Contracts/Auth/GuardGuestExpectation.php +++ b/src/Testing/Laravel/Contracts/Auth/GuardGuestExpectation.php @@ -9,10 +9,10 @@ final class GuardGuestExpectation { /** - * @param Closure(self):void|null $hook + * @param Closure(bool):void|null $hook */ public function __construct( - public readonly mixed $return, + public readonly bool $return, public readonly ?Closure $hook = null, ) { } diff --git a/src/Testing/Laravel/Contracts/Auth/GuardHasUserExpectation.php b/src/Testing/Laravel/Contracts/Auth/GuardHasUserExpectation.php index 93e86b7f..184e909d 100644 --- a/src/Testing/Laravel/Contracts/Auth/GuardHasUserExpectation.php +++ b/src/Testing/Laravel/Contracts/Auth/GuardHasUserExpectation.php @@ -12,7 +12,7 @@ final class GuardHasUserExpectation * @param Closure(self):void|null $hook */ public function __construct( - public readonly mixed $return, + public readonly bool $return, public readonly ?Closure $hook = null, ) { } diff --git a/src/Testing/Laravel/Contracts/Auth/GuardIdExpectation.php b/src/Testing/Laravel/Contracts/Auth/GuardIdExpectation.php index a21af0a0..81a68c6a 100644 --- a/src/Testing/Laravel/Contracts/Auth/GuardIdExpectation.php +++ b/src/Testing/Laravel/Contracts/Auth/GuardIdExpectation.php @@ -12,7 +12,7 @@ final class GuardIdExpectation * @param Closure(self):void|null $hook */ public function __construct( - public readonly mixed $return, + public readonly int|string|null $return, public readonly ?Closure $hook = null, ) { } diff --git a/src/Testing/Laravel/Contracts/Auth/GuardUserExpectation.php b/src/Testing/Laravel/Contracts/Auth/GuardUserExpectation.php index 7ea42051..7c393736 100644 --- a/src/Testing/Laravel/Contracts/Auth/GuardUserExpectation.php +++ b/src/Testing/Laravel/Contracts/Auth/GuardUserExpectation.php @@ -5,14 +5,15 @@ namespace LaraStrict\Testing\Laravel\Contracts\Auth; use Closure; +use Illuminate\Contracts\Auth\Authenticatable; final class GuardUserExpectation { /** - * @param Closure(self):void|null $hook + * @param Closure(Authenticatable|null):void|null $hook */ public function __construct( - public readonly mixed $return, + public readonly Authenticatable|null $return, public readonly ?Closure $hook = null, ) { } diff --git a/src/Testing/Laravel/Contracts/Auth/GuardValidateExpectation.php b/src/Testing/Laravel/Contracts/Auth/GuardValidateExpectation.php index 536af183..5fb9a64b 100644 --- a/src/Testing/Laravel/Contracts/Auth/GuardValidateExpectation.php +++ b/src/Testing/Laravel/Contracts/Auth/GuardValidateExpectation.php @@ -12,7 +12,7 @@ final class GuardValidateExpectation * @param Closure(array, self):void|null $hook */ public function __construct( - public readonly mixed $return, + public readonly bool $return, public readonly array $credentials = [], public readonly ?Closure $hook = null, ) { diff --git a/src/Testing/Laravel/Contracts/Bus/DispatcherHasCommandHandlerExpectation.php b/src/Testing/Laravel/Contracts/Bus/DispatcherHasCommandHandlerExpectation.php index e120fe51..cb161b15 100644 --- a/src/Testing/Laravel/Contracts/Bus/DispatcherHasCommandHandlerExpectation.php +++ b/src/Testing/Laravel/Contracts/Bus/DispatcherHasCommandHandlerExpectation.php @@ -7,7 +7,7 @@ final class DispatcherHasCommandHandlerExpectation { public function __construct( - public readonly mixed $return, + public readonly bool $return, public readonly mixed $command, ) { } diff --git a/src/Testing/Laravel/Contracts/Cache/RepositoryAddExpectation.php b/src/Testing/Laravel/Contracts/Cache/RepositoryAddExpectation.php index df5cd07c..7872ac51 100644 --- a/src/Testing/Laravel/Contracts/Cache/RepositoryAddExpectation.php +++ b/src/Testing/Laravel/Contracts/Cache/RepositoryAddExpectation.php @@ -9,10 +9,10 @@ final class RepositoryAddExpectation { /** - * @param Closure(mixed, mixed, mixed, self):void|null $hook + * @param Closure(bool, mixed, mixed, self):void|null $hook */ public function __construct( - public readonly mixed $return, + public readonly bool $return, public readonly mixed $key, public readonly mixed $value, public readonly mixed $ttl = null, diff --git a/src/Testing/Laravel/Contracts/Cache/RepositoryForeverExpectation.php b/src/Testing/Laravel/Contracts/Cache/RepositoryForeverExpectation.php index 6256b169..3a19660b 100644 --- a/src/Testing/Laravel/Contracts/Cache/RepositoryForeverExpectation.php +++ b/src/Testing/Laravel/Contracts/Cache/RepositoryForeverExpectation.php @@ -9,10 +9,10 @@ final class RepositoryForeverExpectation { /** - * @param Closure(mixed, mixed, self):void|null $hook + * @param Closure(bool, mixed, self):void|null $hook */ public function __construct( - public readonly mixed $return, + public readonly bool $return, public readonly mixed $key, public readonly mixed $value, public readonly ?Closure $hook = null, diff --git a/src/Testing/Laravel/Contracts/Cache/RepositoryForgetExpectation.php b/src/Testing/Laravel/Contracts/Cache/RepositoryForgetExpectation.php index 1eacf93f..c51b8039 100644 --- a/src/Testing/Laravel/Contracts/Cache/RepositoryForgetExpectation.php +++ b/src/Testing/Laravel/Contracts/Cache/RepositoryForgetExpectation.php @@ -12,7 +12,7 @@ final class RepositoryForgetExpectation * @param Closure(mixed, self):void|null $hook */ public function __construct( - public readonly mixed $return, + public readonly bool $return, public readonly mixed $key, public readonly ?Closure $hook = null, ) { diff --git a/src/Testing/Laravel/Contracts/Cache/RepositoryGetStoreExpectation.php b/src/Testing/Laravel/Contracts/Cache/RepositoryGetStoreExpectation.php index 02500c9f..2eea8c4a 100644 --- a/src/Testing/Laravel/Contracts/Cache/RepositoryGetStoreExpectation.php +++ b/src/Testing/Laravel/Contracts/Cache/RepositoryGetStoreExpectation.php @@ -5,14 +5,15 @@ namespace LaraStrict\Testing\Laravel\Contracts\Cache; use Closure; +use Illuminate\Contracts\Cache\Store; final class RepositoryGetStoreExpectation { /** - * @param Closure(self):void|null $hook + * @param Closure(Store):void|null $hook */ public function __construct( - public readonly mixed $return, + public readonly Store $return, public readonly ?Closure $hook = null, ) { } diff --git a/src/Testing/Laravel/Contracts/Cache/RepositoryPutExpectation.php b/src/Testing/Laravel/Contracts/Cache/RepositoryPutExpectation.php index faa6f802..9ad07eb6 100644 --- a/src/Testing/Laravel/Contracts/Cache/RepositoryPutExpectation.php +++ b/src/Testing/Laravel/Contracts/Cache/RepositoryPutExpectation.php @@ -9,10 +9,10 @@ final class RepositoryPutExpectation { /** - * @param Closure(mixed, mixed, mixed, self):void|null $hook + * @param Closure(bool, mixed, mixed, self):void|null $hook */ public function __construct( - public readonly mixed $return, + public readonly bool $return, public readonly mixed $key, public readonly mixed $value, public readonly mixed $ttl = null, diff --git a/src/Testing/Laravel/Contracts/Debug/ExceptionHandlerAssert.php b/src/Testing/Laravel/Contracts/Debug/ExceptionHandlerAssert.php index 878eafcd..052eaca8 100644 --- a/src/Testing/Laravel/Contracts/Debug/ExceptionHandlerAssert.php +++ b/src/Testing/Laravel/Contracts/Debug/ExceptionHandlerAssert.php @@ -5,11 +5,9 @@ namespace LaraStrict\Testing\Laravel\Contracts\Debug; use Illuminate\Contracts\Debug\ExceptionHandler; -use Illuminate\Http\Request; use LaraStrict\Testing\Assert\AbstractExpectationCallsMap; use PHPUnit\Framework\Assert; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\HttpFoundation\Response; use Throwable; class ExceptionHandlerAssert extends AbstractExpectationCallsMap implements ExceptionHandler @@ -44,11 +42,6 @@ public function report(Throwable $e) Assert::assertEquals($expectation->e, $e, $message); } - /** - * Determine if the exception should be reported. - * - * @return bool - */ public function shouldReport(Throwable $e) { $expectation = $this->getExpectation(ExceptionHandlerShouldReportExpectation::class); @@ -59,12 +52,6 @@ public function shouldReport(Throwable $e) return $expectation->return; } - /** - * Render an exception into an HTTP response. - * - * @param Request $request - * @return Response - */ public function render($request, Throwable $e) { $expectation = $this->getExpectation(ExceptionHandlerRenderExpectation::class); diff --git a/src/Testing/Laravel/Contracts/Debug/ExceptionHandlerRenderExpectation.php b/src/Testing/Laravel/Contracts/Debug/ExceptionHandlerRenderExpectation.php index 51d74bfd..75df39fa 100644 --- a/src/Testing/Laravel/Contracts/Debug/ExceptionHandlerRenderExpectation.php +++ b/src/Testing/Laravel/Contracts/Debug/ExceptionHandlerRenderExpectation.php @@ -4,12 +4,13 @@ namespace LaraStrict\Testing\Laravel\Contracts\Debug; +use Symfony\Component\HttpFoundation\Response; use Throwable; final class ExceptionHandlerRenderExpectation { public function __construct( - public readonly mixed $return, + public readonly Response $return, public readonly mixed $request, public readonly Throwable $e, ) { diff --git a/src/Testing/Laravel/Contracts/Debug/ExceptionHandlerShouldReportExpectation.php b/src/Testing/Laravel/Contracts/Debug/ExceptionHandlerShouldReportExpectation.php index 3e4766a6..751dd1e9 100644 --- a/src/Testing/Laravel/Contracts/Debug/ExceptionHandlerShouldReportExpectation.php +++ b/src/Testing/Laravel/Contracts/Debug/ExceptionHandlerShouldReportExpectation.php @@ -9,7 +9,7 @@ final class ExceptionHandlerShouldReportExpectation { public function __construct( - public readonly mixed $return, + public readonly bool $return, public readonly Throwable $e, ) { } diff --git a/src/Testing/Laravel/Contracts/Events/DispatcherAssert.php b/src/Testing/Laravel/Contracts/Events/DispatcherAssert.php index b67a29b4..e1c1860a 100644 --- a/src/Testing/Laravel/Contracts/Events/DispatcherAssert.php +++ b/src/Testing/Laravel/Contracts/Events/DispatcherAssert.php @@ -4,7 +4,6 @@ namespace LaraStrict\Testing\Laravel\Contracts\Events; -use Closure; use Illuminate\Contracts\Events\Dispatcher; use LaraStrict\Testing\Assert\AbstractExpectationCallsMap; use PHPUnit\Framework\Assert; @@ -45,12 +44,6 @@ public function __construct( $this->setExpectations(DispatcherForgetPushedExpectation::class, $forgetPushed); } - /** - * Register an event listener with the dispatcher. - * - * @param Closure|string|array $events - * @param Closure|string|array|null $listener - */ public function listen($events, $listener = null) { $expectation = $this->getExpectation(DispatcherListenExpectation::class); @@ -60,12 +53,6 @@ public function listen($events, $listener = null) Assert::assertEquals($expectation->listener, $listener, $message); } - /** - * Determine if a given event has listeners. - * - * @param string $eventName - * @return bool - */ public function hasListeners($eventName) { $expectation = $this->getExpectation(DispatcherHasListenersExpectation::class); @@ -89,13 +76,6 @@ public function subscribe($subscriber) Assert::assertEquals($expectation->subscriber, $subscriber, $message); } - /** - * Dispatch an event until the first non-null response is returned. - * - * @param string|object $event - * @param mixed $payload - * @return array|null - */ public function until($event, $payload = []) { $expectation = $this->getExpectation(DispatcherUntilExpectation::class); @@ -107,14 +87,6 @@ public function until($event, $payload = []) return $expectation->return; } - /** - * Dispatch an event and call the listeners. - * - * @param string|object $event - * @param mixed $payload - * @param bool $halt - * @return array|null - */ public function dispatch($event, $payload = [], $halt = false) { $expectation = $this->getExpectation(DispatcherDispatchExpectation::class); @@ -127,12 +99,6 @@ public function dispatch($event, $payload = [], $halt = false) return $expectation->return; } - /** - * Register an event and payload to be fired later. - * - * @param string $event - * @param array $payload - */ public function push($event, $payload = []) { $expectation = $this->getExpectation(DispatcherPushExpectation::class); @@ -142,11 +108,6 @@ public function push($event, $payload = []) Assert::assertEquals($expectation->payload, $payload, $message); } - /** - * Flush a set of pushed events. - * - * @param string $event - */ public function flush($event) { $expectation = $this->getExpectation(DispatcherFlushExpectation::class); @@ -155,11 +116,6 @@ public function flush($event) Assert::assertEquals($expectation->event, $event, $message); } - /** - * Remove a set of listeners from the dispatcher. - * - * @param string $event - */ public function forget($event) { $expectation = $this->getExpectation(DispatcherForgetExpectation::class); @@ -168,11 +124,8 @@ public function forget($event) Assert::assertEquals($expectation->event, $event, $message); } - /** - * Forget all of the queued listeners. - */ public function forgetPushed() { - $expectation = $this->getExpectation(DispatcherForgetPushedExpectation::class); + $this->getExpectation(DispatcherForgetPushedExpectation::class); } } diff --git a/src/Testing/Laravel/Contracts/Events/DispatcherDispatchExpectation.php b/src/Testing/Laravel/Contracts/Events/DispatcherDispatchExpectation.php index 1f42544a..8c369295 100644 --- a/src/Testing/Laravel/Contracts/Events/DispatcherDispatchExpectation.php +++ b/src/Testing/Laravel/Contracts/Events/DispatcherDispatchExpectation.php @@ -7,7 +7,7 @@ final class DispatcherDispatchExpectation { public function __construct( - public readonly mixed $return, + public readonly array|null $return, public readonly mixed $event, public readonly mixed $payload = [], public readonly mixed $halt = false, diff --git a/src/Testing/Laravel/Contracts/Events/DispatcherHasListenersExpectation.php b/src/Testing/Laravel/Contracts/Events/DispatcherHasListenersExpectation.php index f426032f..128a8c1d 100644 --- a/src/Testing/Laravel/Contracts/Events/DispatcherHasListenersExpectation.php +++ b/src/Testing/Laravel/Contracts/Events/DispatcherHasListenersExpectation.php @@ -7,7 +7,7 @@ final class DispatcherHasListenersExpectation { public function __construct( - public readonly mixed $return, + public readonly bool $return, public readonly mixed $eventName, ) { } diff --git a/src/Testing/Laravel/Contracts/Events/DispatcherUntilExpectation.php b/src/Testing/Laravel/Contracts/Events/DispatcherUntilExpectation.php index efec9d68..31bdba88 100644 --- a/src/Testing/Laravel/Contracts/Events/DispatcherUntilExpectation.php +++ b/src/Testing/Laravel/Contracts/Events/DispatcherUntilExpectation.php @@ -6,9 +6,12 @@ final class DispatcherUntilExpectation { + /** + * @param array|null $return + */ public function __construct( - public readonly mixed $return, - public readonly mixed $event, + public readonly array|null $return, + public readonly string|object $event, public readonly mixed $payload = [], ) { } diff --git a/src/Testing/Laravel/Contracts/Routing/ResponseFactoryDownloadExpectation.php b/src/Testing/Laravel/Contracts/Routing/ResponseFactoryDownloadExpectation.php index b1e21fae..4490560b 100644 --- a/src/Testing/Laravel/Contracts/Routing/ResponseFactoryDownloadExpectation.php +++ b/src/Testing/Laravel/Contracts/Routing/ResponseFactoryDownloadExpectation.php @@ -5,6 +5,7 @@ namespace LaraStrict\Testing\Laravel\Contracts\Routing; use Closure; +use Symfony\Component\HttpFoundation\BinaryFileResponse; final class ResponseFactoryDownloadExpectation { @@ -12,7 +13,7 @@ final class ResponseFactoryDownloadExpectation * @param Closure(mixed, mixed, array, mixed, self):void|null $hook */ public function __construct( - public readonly mixed $return, + public readonly BinaryFileResponse $return, public readonly mixed $file, public readonly mixed $name = null, public readonly array $headers = [], diff --git a/src/Testing/Laravel/Contracts/Routing/ResponseFactoryFileExpectation.php b/src/Testing/Laravel/Contracts/Routing/ResponseFactoryFileExpectation.php index d2a41ac0..cd5fd039 100644 --- a/src/Testing/Laravel/Contracts/Routing/ResponseFactoryFileExpectation.php +++ b/src/Testing/Laravel/Contracts/Routing/ResponseFactoryFileExpectation.php @@ -5,6 +5,7 @@ namespace LaraStrict\Testing\Laravel\Contracts\Routing; use Closure; +use Symfony\Component\HttpFoundation\BinaryFileResponse; final class ResponseFactoryFileExpectation { @@ -12,7 +13,7 @@ final class ResponseFactoryFileExpectation * @param Closure(mixed, array, self):void|null $hook */ public function __construct( - public readonly mixed $return, + public readonly BinaryFileResponse $return, public readonly mixed $file, public readonly array $headers = [], public readonly ?Closure $hook = null, diff --git a/src/Testing/Laravel/Contracts/Routing/ResponseFactoryJsonExpectation.php b/src/Testing/Laravel/Contracts/Routing/ResponseFactoryJsonExpectation.php index 194d380a..a991cbf4 100644 --- a/src/Testing/Laravel/Contracts/Routing/ResponseFactoryJsonExpectation.php +++ b/src/Testing/Laravel/Contracts/Routing/ResponseFactoryJsonExpectation.php @@ -5,6 +5,7 @@ namespace LaraStrict\Testing\Laravel\Contracts\Routing; use Closure; +use Illuminate\Http\JsonResponse; final class ResponseFactoryJsonExpectation { @@ -12,7 +13,7 @@ final class ResponseFactoryJsonExpectation * @param Closure(mixed, mixed, array, mixed, self):void|null $hook */ public function __construct( - public readonly mixed $return, + public readonly JsonResponse $return, public readonly mixed $data = [], public readonly mixed $status = 200, public readonly array $headers = [], diff --git a/src/Testing/Laravel/Contracts/Routing/ResponseFactoryJsonpExpectation.php b/src/Testing/Laravel/Contracts/Routing/ResponseFactoryJsonpExpectation.php index 73fb4d98..a52d4492 100644 --- a/src/Testing/Laravel/Contracts/Routing/ResponseFactoryJsonpExpectation.php +++ b/src/Testing/Laravel/Contracts/Routing/ResponseFactoryJsonpExpectation.php @@ -5,6 +5,7 @@ namespace LaraStrict\Testing\Laravel\Contracts\Routing; use Closure; +use Illuminate\Http\JsonResponse; final class ResponseFactoryJsonpExpectation { @@ -12,7 +13,7 @@ final class ResponseFactoryJsonpExpectation * @param Closure(mixed, mixed, mixed, array, mixed, self):void|null $hook */ public function __construct( - public readonly mixed $return, + public readonly JsonResponse $return, public readonly mixed $callback, public readonly mixed $data = [], public readonly mixed $status = 200, diff --git a/src/Testing/Laravel/Contracts/Routing/ResponseFactoryMakeExpectation.php b/src/Testing/Laravel/Contracts/Routing/ResponseFactoryMakeExpectation.php index 34fddc85..bdfb7834 100644 --- a/src/Testing/Laravel/Contracts/Routing/ResponseFactoryMakeExpectation.php +++ b/src/Testing/Laravel/Contracts/Routing/ResponseFactoryMakeExpectation.php @@ -5,6 +5,7 @@ namespace LaraStrict\Testing\Laravel\Contracts\Routing; use Closure; +use Illuminate\Http\Response; final class ResponseFactoryMakeExpectation { @@ -12,7 +13,7 @@ final class ResponseFactoryMakeExpectation * @param Closure(mixed, mixed, array, self):void|null $hook */ public function __construct( - public readonly mixed $return, + public readonly Response $return, public readonly mixed $content = '', public readonly mixed $status = 200, public readonly array $headers = [], diff --git a/src/Testing/Laravel/Contracts/Routing/ResponseFactoryNoContentExpectation.php b/src/Testing/Laravel/Contracts/Routing/ResponseFactoryNoContentExpectation.php index bd53aced..6871f1d0 100644 --- a/src/Testing/Laravel/Contracts/Routing/ResponseFactoryNoContentExpectation.php +++ b/src/Testing/Laravel/Contracts/Routing/ResponseFactoryNoContentExpectation.php @@ -5,6 +5,7 @@ namespace LaraStrict\Testing\Laravel\Contracts\Routing; use Closure; +use Illuminate\Http\Response; final class ResponseFactoryNoContentExpectation { @@ -12,7 +13,7 @@ final class ResponseFactoryNoContentExpectation * @param Closure(mixed, array, self):void|null $hook */ public function __construct( - public readonly mixed $return, + public readonly Response $return, public readonly mixed $status = 204, public readonly array $headers = [], public readonly ?Closure $hook = null, diff --git a/src/Testing/Laravel/Contracts/Routing/ResponseFactoryRedirectGuestExpectation.php b/src/Testing/Laravel/Contracts/Routing/ResponseFactoryRedirectGuestExpectation.php index e01b7680..6cbbb7bb 100644 --- a/src/Testing/Laravel/Contracts/Routing/ResponseFactoryRedirectGuestExpectation.php +++ b/src/Testing/Laravel/Contracts/Routing/ResponseFactoryRedirectGuestExpectation.php @@ -5,6 +5,7 @@ namespace LaraStrict\Testing\Laravel\Contracts\Routing; use Closure; +use Illuminate\Http\RedirectResponse; final class ResponseFactoryRedirectGuestExpectation { @@ -12,7 +13,7 @@ final class ResponseFactoryRedirectGuestExpectation * @param Closure(mixed, mixed, mixed, mixed, self):void|null $hook */ public function __construct( - public readonly mixed $return, + public readonly RedirectResponse $return, public readonly mixed $path, public readonly mixed $status = 302, public readonly mixed $headers = [], diff --git a/src/Testing/Laravel/Contracts/Routing/ResponseFactoryRedirectToActionExpectation.php b/src/Testing/Laravel/Contracts/Routing/ResponseFactoryRedirectToActionExpectation.php index 25b955e1..b250f1fd 100644 --- a/src/Testing/Laravel/Contracts/Routing/ResponseFactoryRedirectToActionExpectation.php +++ b/src/Testing/Laravel/Contracts/Routing/ResponseFactoryRedirectToActionExpectation.php @@ -5,6 +5,7 @@ namespace LaraStrict\Testing\Laravel\Contracts\Routing; use Closure; +use Illuminate\Http\RedirectResponse; final class ResponseFactoryRedirectToActionExpectation { @@ -12,7 +13,7 @@ final class ResponseFactoryRedirectToActionExpectation * @param Closure(mixed, mixed, mixed, mixed, self):void|null $hook */ public function __construct( - public readonly mixed $return, + public readonly RedirectResponse $return, public readonly mixed $action, public readonly mixed $parameters = [], public readonly mixed $status = 302, diff --git a/src/Testing/Laravel/Contracts/Routing/ResponseFactoryRedirectToExpectation.php b/src/Testing/Laravel/Contracts/Routing/ResponseFactoryRedirectToExpectation.php index ac2d025e..9fe3b49f 100644 --- a/src/Testing/Laravel/Contracts/Routing/ResponseFactoryRedirectToExpectation.php +++ b/src/Testing/Laravel/Contracts/Routing/ResponseFactoryRedirectToExpectation.php @@ -5,6 +5,7 @@ namespace LaraStrict\Testing\Laravel\Contracts\Routing; use Closure; +use Illuminate\Http\RedirectResponse; final class ResponseFactoryRedirectToExpectation { @@ -12,7 +13,7 @@ final class ResponseFactoryRedirectToExpectation * @param Closure(mixed, mixed, mixed, mixed, self):void|null $hook */ public function __construct( - public readonly mixed $return, + public readonly RedirectResponse $return, public readonly mixed $path, public readonly mixed $status = 302, public readonly mixed $headers = [], diff --git a/src/Testing/Laravel/Contracts/Routing/ResponseFactoryRedirectToIntendedExpectation.php b/src/Testing/Laravel/Contracts/Routing/ResponseFactoryRedirectToIntendedExpectation.php index c9c16958..e9a0347f 100644 --- a/src/Testing/Laravel/Contracts/Routing/ResponseFactoryRedirectToIntendedExpectation.php +++ b/src/Testing/Laravel/Contracts/Routing/ResponseFactoryRedirectToIntendedExpectation.php @@ -5,6 +5,7 @@ namespace LaraStrict\Testing\Laravel\Contracts\Routing; use Closure; +use Illuminate\Http\RedirectResponse; final class ResponseFactoryRedirectToIntendedExpectation { @@ -12,7 +13,7 @@ final class ResponseFactoryRedirectToIntendedExpectation * @param Closure(mixed, mixed, mixed, mixed, self):void|null $hook */ public function __construct( - public readonly mixed $return, + public readonly RedirectResponse $return, public readonly mixed $default = '/', public readonly mixed $status = 302, public readonly mixed $headers = [], diff --git a/src/Testing/Laravel/Contracts/Routing/ResponseFactoryRedirectToRouteExpectation.php b/src/Testing/Laravel/Contracts/Routing/ResponseFactoryRedirectToRouteExpectation.php index 6681d9d3..58c46bbb 100644 --- a/src/Testing/Laravel/Contracts/Routing/ResponseFactoryRedirectToRouteExpectation.php +++ b/src/Testing/Laravel/Contracts/Routing/ResponseFactoryRedirectToRouteExpectation.php @@ -5,6 +5,7 @@ namespace LaraStrict\Testing\Laravel\Contracts\Routing; use Closure; +use Illuminate\Http\RedirectResponse; final class ResponseFactoryRedirectToRouteExpectation { @@ -12,7 +13,7 @@ final class ResponseFactoryRedirectToRouteExpectation * @param Closure(mixed, mixed, mixed, mixed, self):void|null $hook */ public function __construct( - public readonly mixed $return, + public readonly RedirectResponse $return, public readonly mixed $route, public readonly mixed $parameters = [], public readonly mixed $status = 302, diff --git a/src/Testing/Laravel/Contracts/Routing/ResponseFactoryStreamDownloadExpectation.php b/src/Testing/Laravel/Contracts/Routing/ResponseFactoryStreamDownloadExpectation.php index 5523aa7c..5f1febf0 100644 --- a/src/Testing/Laravel/Contracts/Routing/ResponseFactoryStreamDownloadExpectation.php +++ b/src/Testing/Laravel/Contracts/Routing/ResponseFactoryStreamDownloadExpectation.php @@ -5,6 +5,7 @@ namespace LaraStrict\Testing\Laravel\Contracts\Routing; use Closure; +use Symfony\Component\HttpFoundation\StreamedResponse; final class ResponseFactoryStreamDownloadExpectation { @@ -12,7 +13,7 @@ final class ResponseFactoryStreamDownloadExpectation * @param Closure(mixed, mixed, array, mixed, self):void|null $hook */ public function __construct( - public readonly mixed $return, + public readonly StreamedResponse $return, public readonly mixed $name = null, public readonly array $headers = [], public readonly mixed $disposition = 'attachment', diff --git a/src/Testing/Laravel/Contracts/Routing/ResponseFactoryStreamExpectation.php b/src/Testing/Laravel/Contracts/Routing/ResponseFactoryStreamExpectation.php index 372fec4a..67929942 100644 --- a/src/Testing/Laravel/Contracts/Routing/ResponseFactoryStreamExpectation.php +++ b/src/Testing/Laravel/Contracts/Routing/ResponseFactoryStreamExpectation.php @@ -5,6 +5,7 @@ namespace LaraStrict\Testing\Laravel\Contracts\Routing; use Closure; +use Symfony\Component\HttpFoundation\StreamedResponse; final class ResponseFactoryStreamExpectation { @@ -12,7 +13,7 @@ final class ResponseFactoryStreamExpectation * @param Closure(mixed, mixed, array, self):void|null $hook */ public function __construct( - public readonly mixed $return, + public readonly StreamedResponse $return, public readonly mixed $status = 200, public readonly array $headers = [], public readonly ?Closure $hook = null, diff --git a/src/Testing/Laravel/Contracts/Routing/ResponseFactoryViewExpectation.php b/src/Testing/Laravel/Contracts/Routing/ResponseFactoryViewExpectation.php index bd034b21..526ff864 100644 --- a/src/Testing/Laravel/Contracts/Routing/ResponseFactoryViewExpectation.php +++ b/src/Testing/Laravel/Contracts/Routing/ResponseFactoryViewExpectation.php @@ -5,6 +5,7 @@ namespace LaraStrict\Testing\Laravel\Contracts\Routing; use Closure; +use Illuminate\Http\Response; final class ResponseFactoryViewExpectation { @@ -12,7 +13,7 @@ final class ResponseFactoryViewExpectation * @param Closure(mixed, mixed, mixed, array, self):void|null $hook */ public function __construct( - public readonly mixed $return, + public readonly Response $return, public readonly mixed $view, public readonly mixed $data = [], public readonly mixed $status = 200, diff --git a/src/Testing/Laravel/Contracts/Translation/TranslatorChoiceExpectation.php b/src/Testing/Laravel/Contracts/Translation/TranslatorChoiceExpectation.php index 6d08427f..e8801deb 100644 --- a/src/Testing/Laravel/Contracts/Translation/TranslatorChoiceExpectation.php +++ b/src/Testing/Laravel/Contracts/Translation/TranslatorChoiceExpectation.php @@ -12,7 +12,7 @@ final class TranslatorChoiceExpectation * @param Closure(mixed, mixed, array, mixed, self):void|null $hook */ public function __construct( - public readonly mixed $return, + public readonly string $return, public readonly mixed $key, public readonly mixed $number, public readonly array $replace = [], diff --git a/src/Testing/Laravel/Contracts/Translation/TranslatorGetLocaleExpectation.php b/src/Testing/Laravel/Contracts/Translation/TranslatorGetLocaleExpectation.php index 242bf1d2..2547a939 100644 --- a/src/Testing/Laravel/Contracts/Translation/TranslatorGetLocaleExpectation.php +++ b/src/Testing/Laravel/Contracts/Translation/TranslatorGetLocaleExpectation.php @@ -12,7 +12,7 @@ final class TranslatorGetLocaleExpectation * @param Closure(self):void|null $hook */ public function __construct( - public readonly mixed $return, + public readonly string $return, public readonly ?Closure $hook = null, ) { } diff --git a/src/Testing/Laravel/Contracts/View/FactoryComposerExpectation.php b/src/Testing/Laravel/Contracts/View/FactoryComposerExpectation.php index 0f7dc59f..cfa40e34 100644 --- a/src/Testing/Laravel/Contracts/View/FactoryComposerExpectation.php +++ b/src/Testing/Laravel/Contracts/View/FactoryComposerExpectation.php @@ -7,7 +7,7 @@ final class FactoryComposerExpectation { public function __construct( - public readonly mixed $return, + public readonly array $return, public readonly mixed $views, public readonly mixed $callback, ) { diff --git a/src/Testing/Laravel/Contracts/View/FactoryCreatorExpectation.php b/src/Testing/Laravel/Contracts/View/FactoryCreatorExpectation.php index 41d72891..1359a419 100644 --- a/src/Testing/Laravel/Contracts/View/FactoryCreatorExpectation.php +++ b/src/Testing/Laravel/Contracts/View/FactoryCreatorExpectation.php @@ -7,7 +7,7 @@ final class FactoryCreatorExpectation { public function __construct( - public readonly mixed $return, + public readonly array $return, public readonly mixed $views, public readonly mixed $callback, ) { diff --git a/src/Testing/Laravel/Contracts/View/FactoryExistsExpectation.php b/src/Testing/Laravel/Contracts/View/FactoryExistsExpectation.php index 408003f9..923bcfa3 100644 --- a/src/Testing/Laravel/Contracts/View/FactoryExistsExpectation.php +++ b/src/Testing/Laravel/Contracts/View/FactoryExistsExpectation.php @@ -7,7 +7,7 @@ final class FactoryExistsExpectation { public function __construct( - public readonly mixed $return, + public readonly bool $return, public readonly mixed $view, ) { } diff --git a/src/Testing/Laravel/Contracts/View/FactoryFileExpectation.php b/src/Testing/Laravel/Contracts/View/FactoryFileExpectation.php index a9e7144e..4a51d94e 100644 --- a/src/Testing/Laravel/Contracts/View/FactoryFileExpectation.php +++ b/src/Testing/Laravel/Contracts/View/FactoryFileExpectation.php @@ -4,10 +4,12 @@ namespace LaraStrict\Testing\Laravel\Contracts\View; +use Illuminate\Contracts\View\View; + final class FactoryFileExpectation { public function __construct( - public readonly mixed $return, + public readonly View $return, public readonly mixed $path, public readonly mixed $data = [], public readonly mixed $mergeData = [], diff --git a/src/Testing/Laravel/Contracts/View/FactoryMakeExpectation.php b/src/Testing/Laravel/Contracts/View/FactoryMakeExpectation.php index b755aecb..0c2fd46c 100644 --- a/src/Testing/Laravel/Contracts/View/FactoryMakeExpectation.php +++ b/src/Testing/Laravel/Contracts/View/FactoryMakeExpectation.php @@ -4,10 +4,12 @@ namespace LaraStrict\Testing\Laravel\Contracts\View; +use Illuminate\Contracts\View\View; + final class FactoryMakeExpectation { public function __construct( - public readonly mixed $return, + public readonly View $return, public readonly mixed $view, public readonly mixed $data = [], public readonly mixed $mergeData = [], diff --git a/src/Testing/Laravel/Contracts/View/ViewGetDataExpectation.php b/src/Testing/Laravel/Contracts/View/ViewGetDataExpectation.php index 90480471..d5a2413b 100644 --- a/src/Testing/Laravel/Contracts/View/ViewGetDataExpectation.php +++ b/src/Testing/Laravel/Contracts/View/ViewGetDataExpectation.php @@ -7,7 +7,7 @@ final class ViewGetDataExpectation { public function __construct( - public readonly mixed $return + public readonly array $return ) { } } diff --git a/src/Testing/Laravel/Contracts/View/ViewNameExpectation.php b/src/Testing/Laravel/Contracts/View/ViewNameExpectation.php index 1ada7626..32db4414 100644 --- a/src/Testing/Laravel/Contracts/View/ViewNameExpectation.php +++ b/src/Testing/Laravel/Contracts/View/ViewNameExpectation.php @@ -7,7 +7,7 @@ final class ViewNameExpectation { public function __construct( - public readonly mixed $return + public readonly string $return ) { } } diff --git a/src/Testing/Laravel/Contracts/View/ViewRenderExpectation.php b/src/Testing/Laravel/Contracts/View/ViewRenderExpectation.php index f4a7b90a..ae365902 100644 --- a/src/Testing/Laravel/Contracts/View/ViewRenderExpectation.php +++ b/src/Testing/Laravel/Contracts/View/ViewRenderExpectation.php @@ -7,7 +7,7 @@ final class ViewRenderExpectation { public function __construct( - public readonly mixed $return + public readonly string $return ) { } } diff --git a/src/Testing/Laravel/Routing/UrlGenerator.php b/src/Testing/Laravel/Routing/UrlGenerator.php index 2a36cc7b..d855b883 100644 --- a/src/Testing/Laravel/Routing/UrlGenerator.php +++ b/src/Testing/Laravel/Routing/UrlGenerator.php @@ -22,6 +22,7 @@ public function previous($fallback = false): string public function to($path, $extra = [], $secure = null): string { + assert(is_array($extra)); return $this->createUrl(path: $path, parameters: $extra, secure: $secure); } @@ -37,11 +38,13 @@ public function asset($path, $secure = null): string public function route($name, $parameters = [], $absolute = true): string { + assert(is_array($parameters)); return $this->createUrl(path: 'route/' . $name, parameters: $parameters, absolute: $absolute); } public function action($action, $parameters = [], $absolute = true): string { + assert(is_array($parameters)); $actionString = is_array($action) ? implode('-', $action) : $action; return $this->createUrl(path: 'action/' . $actionString, parameters: $parameters, absolute: $absolute); diff --git a/src/Testing/Laravel/TestingContainer.php b/src/Testing/Laravel/TestingContainer.php index ad5a1154..7911680b 100644 --- a/src/Testing/Laravel/TestingContainer.php +++ b/src/Testing/Laravel/TestingContainer.php @@ -151,7 +151,7 @@ public function makeAlwaysReturn(object|null $make): self public function call($callback, array $parameters = [], $defaultMethod = null) { - if ($this->call === null) { + if (! $this->call instanceof Closure) { return null; } diff --git a/src/Testing/PHPUnit/ResourceTestCase.php b/src/Testing/PHPUnit/ResourceTestCase.php index bc17f3f3..19e9376e 100644 --- a/src/Testing/PHPUnit/ResourceTestCase.php +++ b/src/Testing/PHPUnit/ResourceTestCase.php @@ -8,7 +8,6 @@ use Exception; use Illuminate\Contracts\Container\Container; use Illuminate\Http\Request; -use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Http\Resources\Json\JsonResource as BaseJsonResource; use LaraStrict\Http\Resources\JsonResource as LaraStrictJsonResource; use LaraStrict\Http\Resources\JsonResourceCollection; @@ -32,7 +31,7 @@ protected function setUp(): void public function getRequest(): Request { - if ($this->request === null) { + if (! $this->request instanceof Request) { $this->request = $this->createRequest(); } @@ -72,7 +71,7 @@ protected function assert(mixed $object, array|Exception $expected, ?TestingCont /** * @param TEntity $object */ - abstract protected function createResource(mixed $object): JsonResource; + abstract protected function createResource(mixed $object): BaseJsonResource; /** * Calls toArray on the resource. If the resource is a LaraStrictJsonResource or JsonResourceCollection, the @@ -87,7 +86,7 @@ protected function resourceArray( ?TestingContainer $container = null, Request $request = null ): ?array { - if ($resource === null) { + if (! $resource instanceof BaseJsonResource) { return null; } @@ -112,7 +111,7 @@ protected function createRequest(): Request protected function tryToSetContainer(?TestingContainer $container, BaseJsonResource $resource): void { - if ($container === null) { + if (! $container instanceof TestingContainer) { return; } diff --git a/src/User/Http/Middlewares/Authenticate.php b/src/User/Http/Middlewares/Authenticate.php index c5ac50d1..7e5d9bc8 100644 --- a/src/User/Http/Middlewares/Authenticate.php +++ b/src/User/Http/Middlewares/Authenticate.php @@ -5,6 +5,7 @@ namespace LaraStrict\User\Http\Middlewares; use Illuminate\Auth\Middleware\Authenticate as Middleware; +use Illuminate\Contracts\Auth\Authenticatable; use Illuminate\Contracts\Auth\Factory as Auth; use Illuminate\Contracts\Foundation\Application; use Illuminate\Http\Request; @@ -44,6 +45,7 @@ protected function redirectTo($request) if ($request->expectsJson() === false) { return route('login'); } + return null; } protected function autoLoginFirstUserOnLocalIfNeeded(Request $request, array $guards): void @@ -63,7 +65,7 @@ protected function autoLoginFirstUserOnLocalIfNeeded(Request $request, array $gu $user = $this->getUserForAutoLoginActionContract->execute($autoLogin); - if ($user !== null) { + if ($user instanceof Authenticatable) { $guardInstance->setUser($user); } diff --git a/src/Validation/Rules/NumberRule.php b/src/Validation/Rules/NumberRule.php index d6644508..5f68185a 100644 --- a/src/Validation/Rules/NumberRule.php +++ b/src/Validation/Rules/NumberRule.php @@ -11,6 +11,10 @@ class NumberRule implements Rule { public function passes($attribute, $value): bool { + if (! is_string($value) && ! is_numeric($value)) { + return false; + } + if (self::isNumericInt($value)) { $intVal = (int) $value; return $intVal !== PHP_INT_MAX && $intVal !== PHP_INT_MIN; diff --git a/tests/Feature/Config/NotUsingPipe/Config/NotUsingPipeConfig.php b/tests/Feature/Config/NotUsingPipe/Config/NotUsingPipeConfig.php index 859de5a2..fafafff9 100644 --- a/tests/Feature/Config/NotUsingPipe/Config/NotUsingPipeConfig.php +++ b/tests/Feature/Config/NotUsingPipe/Config/NotUsingPipeConfig.php @@ -11,7 +11,9 @@ class NotUsingPipeConfig extends AbstractProviderConfig { public function getTest(): string { - return $this->get(keyOrPath: ['test', 'sub-key'], default: 'missing file, this is a default'); + $value = $this->get(keyOrPath: ['test', 'sub-key'], default: 'missing file, this is a default'); + assert(is_string($value)); + return $value; } protected function getServiceProvider(): string diff --git a/tests/Feature/Config/Valid/Config/ValidConfig.php b/tests/Feature/Config/Valid/Config/ValidConfig.php index c64ca36a..1345f844 100644 --- a/tests/Feature/Config/Valid/Config/ValidConfig.php +++ b/tests/Feature/Config/Valid/Config/ValidConfig.php @@ -13,7 +13,9 @@ class ValidConfig extends AbstractProviderConfig public function getTest(): string { - return $this->get(self::KeyTest); + $value = $this->get(self::KeyTest); + assert(is_string($value)); + return $value; } protected function getServiceProvider(): string diff --git a/tests/Feature/Docker/DockerServiceProviderTest.php b/tests/Feature/Docker/DockerServiceProviderTest.php index e1017f85..61b3d315 100644 --- a/tests/Feature/Docker/DockerServiceProviderTest.php +++ b/tests/Feature/Docker/DockerServiceProviderTest.php @@ -97,7 +97,7 @@ public function assertEnsureOutput( $event = new ScheduledTaskStarting(task: new Event(mutex: $eventMutex, command: 'test')); - if ($setDockerOutput !== null) { + if ($setDockerOutput instanceof Closure) { $setDockerOutput($event); } diff --git a/tests/Feature/Providers/Pipes/LoadProviderConfig/NoConfig/Config/NoConfigConfig.php b/tests/Feature/Providers/Pipes/LoadProviderConfig/NoConfig/Config/NoConfigConfig.php index 21679b22..fb8d6a47 100644 --- a/tests/Feature/Providers/Pipes/LoadProviderConfig/NoConfig/Config/NoConfigConfig.php +++ b/tests/Feature/Providers/Pipes/LoadProviderConfig/NoConfig/Config/NoConfigConfig.php @@ -11,7 +11,9 @@ class NoConfigConfig extends AbstractProviderConfig { public function getValue(): string { - return $this->get(keyOrPath: ['no-key'], default: 'this is default value'); + $value = $this->get(keyOrPath: ['no-key'], default: 'this is default value'); + assert(is_string($value)); + return $value; } protected function getServiceProvider(): string diff --git a/tests/Feature/Queue/Actions/RunJobActionTest.php b/tests/Feature/Queue/Actions/RunJobActionTest.php index 1a1d9a74..00be5468 100644 --- a/tests/Feature/Queue/Actions/RunJobActionTest.php +++ b/tests/Feature/Queue/Actions/RunJobActionTest.php @@ -30,7 +30,7 @@ protected function setUp(): void } /** - * @return array + * @return array */ public function data(): array { diff --git a/tests/Feature/Testing/Commands/MakeExpectationCommand/TestActionContractAssert.php.stub b/tests/Feature/Testing/Commands/MakeExpectationCommand/TestActionContractAssert.php.stub index 74d87f3a..4b3dad7f 100644 --- a/tests/Feature/Testing/Commands/MakeExpectationCommand/TestActionContractAssert.php.stub +++ b/tests/Feature/Testing/Commands/MakeExpectationCommand/TestActionContractAssert.php.stub @@ -26,7 +26,7 @@ class TestActionContractAssert extends \LaraStrict\Testing\Assert\AbstractExpect string|int $multi, string|int|null $multiNull, string|int|null $multiNullDefault = 'test', - string $optional = null, + ?string $optional = null, string $optionalString = 'test', string $constant = DIRECTORY_SEPARATOR, int $constantClass = \LaraStrict\Cache\Constants\CacheExpirations::Day, diff --git a/tests/Feature/Testing/Commands/MakeExpectationCommand/TestReturnActionContractAssert.php.stub b/tests/Feature/Testing/Commands/MakeExpectationCommand/TestReturnActionContractAssert.php.stub index ba1a840a..b95414ed 100644 --- a/tests/Feature/Testing/Commands/MakeExpectationCommand/TestReturnActionContractAssert.php.stub +++ b/tests/Feature/Testing/Commands/MakeExpectationCommand/TestReturnActionContractAssert.php.stub @@ -26,7 +26,7 @@ class TestReturnActionContractAssert extends \LaraStrict\Testing\Assert\Abstract string|int $multi, string|int|null $multiNull, string|int|null $multiNullDefault = 'test', - string $optional = null, + ?string $optional = null, string $optionalString = 'test', string $constant = DIRECTORY_SEPARATOR, int $constantClass = \LaraStrict\Cache\Constants\CacheExpirations::Day, diff --git a/tests/Feature/Testing/Commands/MakeExpectationCommand/TestReturnUnionActionContractAssert.php.stub b/tests/Feature/Testing/Commands/MakeExpectationCommand/TestReturnUnionActionContractAssert.php.stub index 930394e9..1d10afe0 100644 --- a/tests/Feature/Testing/Commands/MakeExpectationCommand/TestReturnUnionActionContractAssert.php.stub +++ b/tests/Feature/Testing/Commands/MakeExpectationCommand/TestReturnUnionActionContractAssert.php.stub @@ -26,7 +26,7 @@ class TestReturnUnionActionContractAssert extends \LaraStrict\Testing\Assert\Abs string|int $multi, string|int|null $multiNull, string|int|null $multiNullDefault = 'test', - string $optional = null, + ?string $optional = null, string $optionalString = 'test', string $constant = DIRECTORY_SEPARATOR, int $constantClass = \LaraStrict\Cache\Constants\CacheExpirations::Day, diff --git a/tests/Feature/Testing/Commands/MakeExpectationCommand/one.TestActionContractAssert.php.stub b/tests/Feature/Testing/Commands/MakeExpectationCommand/one.TestActionContractAssert.php.stub index 5099327f..44a46158 100644 --- a/tests/Feature/Testing/Commands/MakeExpectationCommand/one.TestActionContractAssert.php.stub +++ b/tests/Feature/Testing/Commands/MakeExpectationCommand/one.TestActionContractAssert.php.stub @@ -26,7 +26,7 @@ class TestActionContractAssert extends \LaraStrict\Testing\Assert\AbstractExpect string|int $multi, string|int|null $multiNull, string|int|null $multiNullDefault = 'test', - string $optional = null, + ?string $optional = null, string $optionalString = 'test', string $constant = DIRECTORY_SEPARATOR, int $constantClass = \LaraStrict\Cache\Constants\CacheExpirations::Day, diff --git a/tests/Feature/Testing/Commands/MakeExpectationCommand/one.TestReturnActionContractAssert.php.stub b/tests/Feature/Testing/Commands/MakeExpectationCommand/one.TestReturnActionContractAssert.php.stub index a1cf7576..8e52a10f 100644 --- a/tests/Feature/Testing/Commands/MakeExpectationCommand/one.TestReturnActionContractAssert.php.stub +++ b/tests/Feature/Testing/Commands/MakeExpectationCommand/one.TestReturnActionContractAssert.php.stub @@ -26,7 +26,7 @@ class TestReturnActionContractAssert extends \LaraStrict\Testing\Assert\Abstract string|int $multi, string|int|null $multiNull, string|int|null $multiNullDefault = 'test', - string $optional = null, + ?string $optional = null, string $optionalString = 'test', string $constant = DIRECTORY_SEPARATOR, int $constantClass = \LaraStrict\Cache\Constants\CacheExpirations::Day, diff --git a/tests/Feature/Testing/Commands/MakeExpectationCommand/one.TestReturnUnionActionContractAssert.php.stub b/tests/Feature/Testing/Commands/MakeExpectationCommand/one.TestReturnUnionActionContractAssert.php.stub index d31be957..3a2a9c60 100644 --- a/tests/Feature/Testing/Commands/MakeExpectationCommand/one.TestReturnUnionActionContractAssert.php.stub +++ b/tests/Feature/Testing/Commands/MakeExpectationCommand/one.TestReturnUnionActionContractAssert.php.stub @@ -26,7 +26,7 @@ class TestReturnUnionActionContractAssert extends \LaraStrict\Testing\Assert\Abs string|int $multi, string|int|null $multiNull, string|int|null $multiNullDefault = 'test', - string $optional = null, + ?string $optional = null, string $optionalString = 'test', string $constant = DIRECTORY_SEPARATOR, int $constantClass = \LaraStrict\Cache\Constants\CacheExpirations::Day, diff --git a/tests/Feature/Testing/Commands/MakeExpectationCommand/two.TestActionContractAssert.php.stub b/tests/Feature/Testing/Commands/MakeExpectationCommand/two.TestActionContractAssert.php.stub index a7f54ca0..4065e6f4 100644 --- a/tests/Feature/Testing/Commands/MakeExpectationCommand/two.TestActionContractAssert.php.stub +++ b/tests/Feature/Testing/Commands/MakeExpectationCommand/two.TestActionContractAssert.php.stub @@ -26,7 +26,7 @@ class TestActionContractAssert extends \LaraStrict\Testing\Assert\AbstractExpect string|int $multi, string|int|null $multiNull, string|int|null $multiNullDefault = 'test', - string $optional = null, + ?string $optional = null, string $optionalString = 'test', string $constant = DIRECTORY_SEPARATOR, int $constantClass = \LaraStrict\Cache\Constants\CacheExpirations::Day, diff --git a/tests/Feature/Testing/Commands/MakeExpectationCommand/two.TestReturnActionContractAssert.php.stub b/tests/Feature/Testing/Commands/MakeExpectationCommand/two.TestReturnActionContractAssert.php.stub index 97d58942..270476d4 100644 --- a/tests/Feature/Testing/Commands/MakeExpectationCommand/two.TestReturnActionContractAssert.php.stub +++ b/tests/Feature/Testing/Commands/MakeExpectationCommand/two.TestReturnActionContractAssert.php.stub @@ -26,7 +26,7 @@ class TestReturnActionContractAssert extends \LaraStrict\Testing\Assert\Abstract string|int $multi, string|int|null $multiNull, string|int|null $multiNullDefault = 'test', - string $optional = null, + ?string $optional = null, string $optionalString = 'test', string $constant = DIRECTORY_SEPARATOR, int $constantClass = \LaraStrict\Cache\Constants\CacheExpirations::Day, diff --git a/tests/Feature/Testing/Commands/MakeExpectationCommand/two.TestReturnUnionActionContractAssert.php.stub b/tests/Feature/Testing/Commands/MakeExpectationCommand/two.TestReturnUnionActionContractAssert.php.stub index 6e485201..62eb0fb0 100644 --- a/tests/Feature/Testing/Commands/MakeExpectationCommand/two.TestReturnUnionActionContractAssert.php.stub +++ b/tests/Feature/Testing/Commands/MakeExpectationCommand/two.TestReturnUnionActionContractAssert.php.stub @@ -26,7 +26,7 @@ class TestReturnUnionActionContractAssert extends \LaraStrict\Testing\Assert\Abs string|int $multi, string|int|null $multiNull, string|int|null $multiNullDefault = 'test', - string $optional = null, + ?string $optional = null, string $optionalString = 'test', string $constant = DIRECTORY_SEPARATOR, int $constantClass = \LaraStrict\Cache\Constants\CacheExpirations::Day, diff --git a/tests/Feature/Testing/Laravel/Contracts/Auth/GuardAssertTest.php b/tests/Feature/Testing/Laravel/Contracts/Auth/GuardAssertTest.php index 197f108e..3dbd3f52 100644 --- a/tests/Feature/Testing/Laravel/Contracts/Auth/GuardAssertTest.php +++ b/tests/Feature/Testing/Laravel/Contracts/Auth/GuardAssertTest.php @@ -77,10 +77,10 @@ protected function generateData(): array ), new AssertExpectationEntity( methodName: 'validate', - createAssert: static fn () => new GuardAssert(validate: [new GuardValidateExpectation(return: 1)]), + createAssert: static fn () => new GuardAssert(validate: [new GuardValidateExpectation(return: true)]), call: static fn (GuardAssert $assert) => $assert->validate(), checkResult: true, - expectedResult: 1 + expectedResult: true ), new AssertExpectationEntity( methodName: 'validate', diff --git a/tests/Feature/Testing/Laravel/Contracts/Cache/RepositoryAssertTest.php b/tests/Feature/Testing/Laravel/Contracts/Cache/RepositoryAssertTest.php index ae4db64e..7d5618e0 100644 --- a/tests/Feature/Testing/Laravel/Contracts/Cache/RepositoryAssertTest.php +++ b/tests/Feature/Testing/Laravel/Contracts/Cache/RepositoryAssertTest.php @@ -59,38 +59,38 @@ protected function generateData(): array new AssertExpectationEntity( methodName: 'put', createAssert: static fn () => new RepositoryAssert(put: [ - new RepositoryPutExpectation(return: 'Test', key: '123', value: 'Rock'), + new RepositoryPutExpectation(return: true, key: '123', value: 'Rock'), ]), call: static fn (RepositoryAssert $assert) => $assert->put(key: '123', value: 'Rock'), checkResult: true, - expectedResult: 'Test' + expectedResult: true ), new AssertExpectationEntity( methodName: 'put', createAssert: static fn () => new RepositoryAssert(put: [ - new RepositoryPutExpectation(return: 'Test', key: '123', value: 'Rock', ttl: 123), + new RepositoryPutExpectation(return: true, key: '123', value: 'Rock', ttl: 123), ]), call: static fn (RepositoryAssert $assert) => $assert->put(key: '123', value: 'Rock', ttl: 123), checkResult: true, - expectedResult: 'Test' + expectedResult: true ), new AssertExpectationEntity( methodName: 'add', createAssert: static fn () => new RepositoryAssert(add: [ - new RepositoryAddExpectation(return: 'Test', key: '123', value: 'Rock'), + new RepositoryAddExpectation(return: true, key: '123', value: 'Rock'), ]), call: static fn (RepositoryAssert $assert) => $assert->add(key: '123', value: 'Rock'), checkResult: true, - expectedResult: 'Test' + expectedResult: true ), new AssertExpectationEntity( methodName: 'add', createAssert: static fn () => new RepositoryAssert(add: [ - new RepositoryAddExpectation(return: 'Test', key: '123', value: 'Rock', ttl: 123), + new RepositoryAddExpectation(return: true, key: '123', value: 'Rock', ttl: 123), ]), call: static fn (RepositoryAssert $assert) => $assert->add(key: '123', value: 'Rock', ttl: 123), checkResult: true, - expectedResult: 'Test' + expectedResult: true ), new AssertExpectationEntity( methodName: 'increment', @@ -131,11 +131,11 @@ protected function generateData(): array new AssertExpectationEntity( methodName: 'forever', createAssert: static fn () => new RepositoryAssert(forever: [ - new RepositoryForeverExpectation(return: 'Test', key: '123', value: 'Rock'), + new RepositoryForeverExpectation(return: true, key: '123', value: 'Rock'), ]), call: static fn (RepositoryAssert $assert) => $assert->forever(key: '123', value: 'Rock'), checkResult: true, - expectedResult: 'Test' + expectedResult: true ), new AssertExpectationEntity( methodName: 'remember', @@ -190,11 +190,11 @@ protected function generateData(): array new AssertExpectationEntity( methodName: 'forget', createAssert: static fn () => new RepositoryAssert(forget: [ - new RepositoryForgetExpectation(return: 'Test', key: '123'), + new RepositoryForgetExpectation(return: true, key: '123'), ]), call: static fn (RepositoryAssert $assert) => $assert->forget(key: '123'), checkResult: true, - expectedResult: 'Test' + expectedResult: true ), new AssertExpectationEntity( methodName: 'getStore', diff --git a/tests/Feature/Testing/Laravel/Contracts/View/ViewAssertTest.php b/tests/Feature/Testing/Laravel/Contracts/View/ViewAssertTest.php index fd967f32..2ee7fea0 100644 --- a/tests/Feature/Testing/Laravel/Contracts/View/ViewAssertTest.php +++ b/tests/Feature/Testing/Laravel/Contracts/View/ViewAssertTest.php @@ -52,10 +52,10 @@ protected function generateData(): array ), new AssertExpectationEntity( methodName: 'getData', - createAssert: static fn () => new ViewAssert(getData: [new ViewGetDataExpectation(return: 'test')]), + createAssert: static fn () => new ViewAssert(getData: [new ViewGetDataExpectation(return: ['test'])]), call: static fn (ViewAssert $assert) => $assert->getData(), checkResult: true, - expectedResult: 'test' + expectedResult: ['test'] ), new AssertExpectationEntity( methodName: 'render', diff --git a/tests/Feature/Testing/TestServiceProviderTest.php b/tests/Feature/Testing/TestServiceProviderTest.php index 971b767a..60bf2475 100644 --- a/tests/Feature/Testing/TestServiceProviderTest.php +++ b/tests/Feature/Testing/TestServiceProviderTest.php @@ -66,11 +66,12 @@ public function testSleepServiceInProduction(): void $this->app() ->register(LaraStrictServiceProvider::class); - $this->assertInstanceOf( - expected: SleepService::class, - actual: $this->app() - ->make(SleepServiceContract::class) - ); + $service = $this->app() + ->make(SleepServiceContract::class); + + // larastan will resolve this as NoSleepService - does not support dynamic env change. + /** @phpstan-ignore-next-line */ + $this->assertTrue($service instanceof SleepService); } protected function getPackageProviders($app) @@ -80,8 +81,10 @@ protected function getPackageProviders($app) protected function setEnv(string|EnvironmentType $environment): void { - $config = $this->app() + $config = $this + ->app() ->get(Repository::class); + assert($config instanceof Repository); $config->set('app.env', $environment); } diff --git a/tests/Unit/Http/Resources/ResourceArrayResource.php b/tests/Unit/Http/Resources/ResourceArrayResource.php index be386302..04962d90 100644 --- a/tests/Unit/Http/Resources/ResourceArrayResource.php +++ b/tests/Unit/Http/Resources/ResourceArrayResource.php @@ -18,7 +18,7 @@ public function __construct(?BaseJsonResource $resource) } /** - * @return array>> + * @return array> */ public function toArray($request) { diff --git a/tests/Unit/Providers/Pipes/BootViewComposersPipe/BootViewComposersPipeTest.php b/tests/Unit/Providers/Pipes/BootViewComposersPipe/BootViewComposersPipeTest.php index 406647b4..ae0168e1 100644 --- a/tests/Unit/Providers/Pipes/BootViewComposersPipe/BootViewComposersPipeTest.php +++ b/tests/Unit/Providers/Pipes/BootViewComposersPipe/BootViewComposersPipeTest.php @@ -51,7 +51,7 @@ public function bootViewComposers(string $serviceName, Factory $viewFactory): vo }, viewFactory: $viewFactory, factoryComposerExpectation: new FactoryComposerExpectation( - return: null, + return: [], views: ['test'], callback: Composer::class, ), @@ -77,7 +77,7 @@ public function assert( ): void { $pipe = new BootViewComposersPipe(viewFactory: $viewFactory); - if ($factoryComposerExpectation !== null) { + if ($factoryComposerExpectation instanceof FactoryComposerExpectation) { $viewFactory->addExpectation($factoryComposerExpectation); } diff --git a/tests/Unit/Testing/Laravel/TestingContainerTest.php b/tests/Unit/Testing/Laravel/TestingContainerTest.php index 93338805..13476c7b 100644 --- a/tests/Unit/Testing/Laravel/TestingContainerTest.php +++ b/tests/Unit/Testing/Laravel/TestingContainerTest.php @@ -97,7 +97,7 @@ public function makeException(): array public function testBindingResolutionException( bool $setMake, string $expectedMessage, - mixed $value = null + ?object $value = null ): void { $container = new TestingContainer();