diff --git a/system/Common.php b/system/Common.php index 11c95e1b9c57..d604c07d6f56 100644 --- a/system/Common.php +++ b/system/Common.php @@ -1226,7 +1226,7 @@ function view_cell(string $library, $params = null, int $ttl = 0, ?string $cache /** * Get the class "basename" of the given object / class. * - * @param object|string $class + * @param class-string|object $class * * @return string * @@ -1244,9 +1244,9 @@ function class_basename($class) /** * Returns all traits used by a class, its parent classes and trait of their traits. * - * @param object|string $class + * @param class-string|object $class * - * @return array + * @return array * * @codeCoverageIgnore */ @@ -1270,9 +1270,9 @@ function class_uses_recursive($class) /** * Returns all traits used by a trait and its traits. * - * @param string $trait + * @param class-string $trait * - * @return array + * @return array * * @codeCoverageIgnore */ diff --git a/system/Test/CIUnitTestCase.php b/system/Test/CIUnitTestCase.php index 4780a1bbdefd..81d669138422 100644 --- a/system/Test/CIUnitTestCase.php +++ b/system/Test/CIUnitTestCase.php @@ -19,6 +19,7 @@ use CodeIgniter\Database\MigrationRunner; use CodeIgniter\Database\Seeder; use CodeIgniter\Events\Events; +use CodeIgniter\HTTP\Header; use CodeIgniter\Router\RouteCollection; use CodeIgniter\Session\Handlers\ArrayHandler; use CodeIgniter\Test\Mock\MockCache; @@ -72,6 +73,8 @@ abstract class CIUnitTestCase extends TestCase /** * Store of identified traits. + * + * @var array|null */ private ?array $traits = null; @@ -109,9 +112,9 @@ abstract class CIUnitTestCase extends TestCase /** * The seed file(s) used for all tests within this test case. - * Should be fully-namespaced or relative to $basePath + * Should be fully-namespaced or relative to $basePath. * - * @var class-string|list> + * @var ''|class-string|list> */ protected $seed = ''; @@ -127,9 +130,9 @@ abstract class CIUnitTestCase extends TestCase * The namespace(s) to help us find the migration classes. * `null` is equivalent to running `spark migrate --all`. * Note that running "all" runs migrations in date order, - * but specifying namespaces runs them in namespace order (then date) + * but specifying namespaces runs them in namespace order (then date). * - * @var array|string|null + * @var list|string|null */ protected $namespace = 'Tests\Support'; @@ -156,17 +159,17 @@ abstract class CIUnitTestCase extends TestCase protected $migrations; /** - * Seeder instance + * Seeder instance. * - * @var Seeder + * @var Seeder|null */ protected $seeder; /** * Stores information needed to remove any - * rows inserted via $this->hasInDatabase(); + * rows inserted via $this->hasInDatabase(). * - * @var array + * @var list> */ protected $insertCache = []; @@ -186,27 +189,27 @@ abstract class CIUnitTestCase extends TestCase * Values to be set in the SESSION global * before running the test. * - * @var array + * @var array */ protected $session = []; /** - * Enabled auto clean op buffer after request call + * Enabled auto clean op buffer after request call. * * @var bool */ protected $clean = true; /** - * Custom request's headers + * Custom request's headers. * - * @var array + * @var array> */ protected $headers = []; /** * Allows for formatting the request body to what - * the controller is going to expect + * the controller is going to expect. * * @var string */ @@ -276,7 +279,7 @@ protected function tearDown(): void * Checks for traits with corresponding * methods for setUp or tearDown. * - * @param string $stage 'setUp' or 'tearDown' + * @param 'setUp'|'tearDown' $stage */ private function callTraitMethods(string $stage): void { @@ -298,7 +301,7 @@ private function callTraitMethods(string $stage): void // -------------------------------------------------------------------- /** - * Resets shared instanced for all Factories components + * Resets shared instanced for all Factories components. * * @return void */ @@ -308,7 +311,7 @@ protected function resetFactories() } /** - * Resets shared instanced for all Services + * Resets shared instanced for all Services. * * @return void */ @@ -318,7 +321,7 @@ protected function resetServices(bool $initAutoloader = true) } /** - * Injects the mock Cache driver to prevent filesystem collisions + * Injects the mock Cache driver to prevent filesystem collisions. * * @return void */ @@ -328,7 +331,7 @@ protected function mockCache() } /** - * Injects the mock email driver so no emails really send + * Injects the mock email driver so no emails really send. * * @return void */ @@ -338,7 +341,7 @@ protected function mockEmail() } /** - * Injects the mock session driver into Services + * Injects the mock session driver into Services. * * @return void */ diff --git a/system/Test/DatabaseTestTrait.php b/system/Test/DatabaseTestTrait.php index c0d4473c7b9e..14c47c95cee7 100644 --- a/system/Test/DatabaseTestTrait.php +++ b/system/Test/DatabaseTestTrait.php @@ -14,11 +14,13 @@ namespace CodeIgniter\Test; use CodeIgniter\Database\BaseBuilder; +use CodeIgniter\Database\BaseConnection; use CodeIgniter\Database\Exceptions\DatabaseException; +use CodeIgniter\Database\MigrationRunner; +use CodeIgniter\Database\Seeder; use CodeIgniter\Test\Constraints\SeeInDatabase; use Config\Database; use Config\Migrations; -use Config\Services; use PHPUnit\Framework\Attributes\AfterClass; /** @@ -27,6 +29,12 @@ * Provides functionality for refreshing/seeding * the database during testing. * + * @property BaseConnection $db + * @property list> $insertCache + * @property Seeder|null $seeder + * @property MigrationRunner|null $migrations + * @property list|string|null $namespace + * * @mixin CIUnitTestCase */ trait DatabaseTestTrait @@ -88,7 +96,7 @@ public function loadDependencies() $config = new Migrations(); $config->enabled = true; - $this->migrations = Services::migrations($config, $this->db, false); + $this->migrations = service('migrations', $config, $this->db, false); $this->migrations->setSilent(false); } diff --git a/system/Test/FeatureTestTrait.php b/system/Test/FeatureTestTrait.php index eaf49a0a9147..600e490ab7e9 100644 --- a/system/Test/FeatureTestTrait.php +++ b/system/Test/FeatureTestTrait.php @@ -13,13 +13,17 @@ namespace CodeIgniter\Test; +use Closure; use CodeIgniter\Events\Events; use CodeIgniter\HTTP\Exceptions\RedirectException; +use CodeIgniter\HTTP\Header; use CodeIgniter\HTTP\IncomingRequest; use CodeIgniter\HTTP\Method; use CodeIgniter\HTTP\Request; +use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\HTTP\SiteURI; use CodeIgniter\HTTP\URI; +use CodeIgniter\Router\RouteCollection; use Config\App; use Config\Services; use Exception; @@ -30,6 +34,12 @@ * * Provides additional utilities for doing full HTTP testing * against your application in trait format. + * + * @property array $session + * @property array> $headers + * @property RouteCollection|null $routes + * + * @mixin CIUnitTestCase */ trait FeatureTestTrait { @@ -42,7 +52,12 @@ trait FeatureTestTrait * ['GET', 'home', 'Home::index'], * ] * - * @param array|null $routes Array to set routes + * @param array + * }>|null $routes Array to set routes * * @return $this */ @@ -84,7 +99,7 @@ protected function withRoutes(?array $routes = null) /** * Sets any values that should exist during this session. * - * @param array|null $values Array of values, or null to use the current $_SESSION + * @param array|null $values Array of values, or null to use the current $_SESSION * * @return $this */ @@ -103,7 +118,7 @@ public function withSession(?array $values = null) * 'Authorization' => 'Token' * ]) * - * @param array $headers Array of headers + * @param array> $headers Array of headers * * @return $this */ diff --git a/tests/system/Database/DatabaseTestCase/DatabaseTestCaseMigrationOnce1Test.php b/tests/system/Database/DatabaseTestCase/DatabaseTestCaseMigrationOnce1Test.php index d6cb6b503adb..86889e859fff 100644 --- a/tests/system/Database/DatabaseTestCase/DatabaseTestCaseMigrationOnce1Test.php +++ b/tests/system/Database/DatabaseTestCase/DatabaseTestCaseMigrationOnce1Test.php @@ -29,29 +29,9 @@ final class DatabaseTestCaseMigrationOnce1Test extends CIUnitTestCase { use DatabaseTestTrait; - /** - * Should run db migration only once? - * - * @var bool - */ protected $migrateOnce = true; - - /** - * Should the db be refreshed before test? - * - * @var bool - */ - protected $refresh = true; - - /** - * The namespace(s) to help us find the migration classes. - * Empty is equivalent to running `spark migrate -all`. - * Note that running "all" runs migrations in date order, - * but specifying namespaces runs them in namespace order (then date) - * - * @var array|string|null - */ - protected $namespace = [ + protected $refresh = true; + protected $namespace = [ 'Tests\Support\MigrationTestMigrations', ]; diff --git a/tests/system/Database/DatabaseTestCase/DatabaseTestCaseMigrationOnce2Test.php b/tests/system/Database/DatabaseTestCase/DatabaseTestCaseMigrationOnce2Test.php index b485093438ce..12df06ca89cd 100644 --- a/tests/system/Database/DatabaseTestCase/DatabaseTestCaseMigrationOnce2Test.php +++ b/tests/system/Database/DatabaseTestCase/DatabaseTestCaseMigrationOnce2Test.php @@ -29,29 +29,9 @@ final class DatabaseTestCaseMigrationOnce2Test extends CIUnitTestCase { use DatabaseTestTrait; - /** - * Should run db migration only once? - * - * @var bool - */ protected $migrateOnce = true; - - /** - * Should the db be refreshed before test? - * - * @var bool - */ - protected $refresh = true; - - /** - * The namespace(s) to help us find the migration classes. - * Empty is equivalent to running `spark migrate -all`. - * Note that running "all" runs migrations in date order, - * but specifying namespaces runs them in namespace order (then date) - * - * @var array|string|null - */ - protected $namespace = [ + protected $refresh = true; + protected $namespace = [ 'Tests\Support\MigrationTestMigrations', ]; diff --git a/tests/system/Database/DatabaseTestCaseTest.php b/tests/system/Database/DatabaseTestCaseTest.php index b41aba3b76a7..0827f82c1d1f 100644 --- a/tests/system/Database/DatabaseTestCaseTest.php +++ b/tests/system/Database/DatabaseTestCaseTest.php @@ -28,33 +28,11 @@ final class DatabaseTestCaseTest extends CIUnitTestCase { use DatabaseTestTrait; - /** - * Should the db be refreshed before - * each test? - * - * @var bool - */ protected $refresh = true; - - /** - * The seed file(s) used for all tests within this test case. - * Should be fully-namespaced or relative to $basePath - * - * @var array|string - */ - protected $seed = [ + protected $seed = [ CITestSeeder::class, AnotherSeeder::class, ]; - - /** - * The namespace(s) to help us find the migration classes. - * Empty is equivalent to running `spark migrate -all`. - * Note that running "all" runs migrations in date order, - * but specifying namespaces runs them in namespace order (then date) - * - * @var array|string|null - */ protected $namespace = [ 'Tests\Support', 'Tests\Support\MigrationTestMigrations', diff --git a/tests/system/Database/Live/MetadataTest.php b/tests/system/Database/Live/MetadataTest.php index 643d0689fdad..ad70d281af0a 100644 --- a/tests/system/Database/Live/MetadataTest.php +++ b/tests/system/Database/Live/MetadataTest.php @@ -27,13 +27,7 @@ final class MetadataTest extends CIUnitTestCase { use DatabaseTestTrait; - /** - * The seed file used for all tests within this test case. - * - * @var string - */ - protected $seed = CITestSeeder::class; - + protected $seed = CITestSeeder::class; private array $expectedTables = []; protected function setUp(): void diff --git a/utils/phpstan-baseline/loader.neon b/utils/phpstan-baseline/loader.neon index a92562caf39d..76e5523f24c1 100644 --- a/utils/phpstan-baseline/loader.neon +++ b/utils/phpstan-baseline/loader.neon @@ -1,4 +1,4 @@ -# total 2837 errors +# total 2808 errors includes: - argument.type.neon - assign.propertyType.neon diff --git a/utils/phpstan-baseline/missingType.iterableValue.neon b/utils/phpstan-baseline/missingType.iterableValue.neon index b217c6c64cda..42c18a6e7522 100644 --- a/utils/phpstan-baseline/missingType.iterableValue.neon +++ b/utils/phpstan-baseline/missingType.iterableValue.neon @@ -1,4 +1,4 @@ -# total 1409 errors +# total 1388 errors parameters: ignoreErrors: @@ -337,11 +337,6 @@ parameters: count: 1 path: ../../system/Commands/Utilities/Routes/FilterFinder.php - - - message: '#^Function class_uses_recursive\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Common.php - - message: '#^Function log_message\(\) has parameter \$context with no value type specified in iterable type array\.$#' count: 1 @@ -367,11 +362,6 @@ parameters: count: 1 path: ../../system/Common.php - - - message: '#^Function trait_uses_recursive\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Common.php - - message: '#^Function view\(\) has parameter \$data with no value type specified in iterable type array\.$#' count: 1 @@ -4587,31 +4577,6 @@ parameters: count: 1 path: ../../system/Superglobals.php - - - message: '#^Property CodeIgniter\\Test\\CIUnitTestCase\:\:\$headers type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Test/CIUnitTestCase.php - - - - message: '#^Property CodeIgniter\\Test\\CIUnitTestCase\:\:\$insertCache type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Test/CIUnitTestCase.php - - - - message: '#^Property CodeIgniter\\Test\\CIUnitTestCase\:\:\$namespace type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Test/CIUnitTestCase.php - - - - message: '#^Property CodeIgniter\\Test\\CIUnitTestCase\:\:\$session type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Test/CIUnitTestCase.php - - - - message: '#^Property CodeIgniter\\Test\\CIUnitTestCase\:\:\$traits type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Test/CIUnitTestCase.php - - message: '#^Method CodeIgniter\\Test\\Constraints\\SeeInDatabase\:\:__construct\(\) has parameter \$data with no value type specified in iterable type array\.$#' count: 1 @@ -5632,26 +5597,6 @@ parameters: count: 1 path: ../../tests/system/Database/ConfigTest.php - - - message: '#^Property CodeIgniter\\Database\\DatabaseTestCase\\DatabaseTestCaseMigrationOnce1Test\:\:\$namespace type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../tests/system/Database/DatabaseTestCase/DatabaseTestCaseMigrationOnce1Test.php - - - - message: '#^Property CodeIgniter\\Database\\DatabaseTestCase\\DatabaseTestCaseMigrationOnce2Test\:\:\$namespace type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../tests/system/Database/DatabaseTestCase/DatabaseTestCaseMigrationOnce2Test.php - - - - message: '#^Property CodeIgniter\\Database\\DatabaseTestCaseTest\:\:\$namespace type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../tests/system/Database/DatabaseTestCaseTest.php - - - - message: '#^Property CodeIgniter\\Database\\DatabaseTestCaseTest\:\:\$seed type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../tests/system/Database/DatabaseTestCaseTest.php - - message: '#^Property CodeIgniter\\Database\\Live\\MetadataTest\:\:\$expectedTables type has no value type specified in iterable type array\.$#' count: 1 @@ -5672,11 +5617,6 @@ parameters: count: 1 path: ../../tests/system/Database/Live/UpdateTest.php - - - message: '#^Property CodeIgniter\\Database\\Migrations\\MigrationRunnerTest\:\:\$namespace type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../tests/system/Database/Migrations/MigrationRunnerTest.php - - message: '#^Method CodeIgniter\\Debug\\ExceptionHandlerTest\:\:backupIniValues\(\) has parameter \$keys with no value type specified in iterable type array\.$#' count: 1 @@ -6132,21 +6072,6 @@ parameters: count: 1 path: ../../tests/system/HomeTest.php - - - message: '#^Method CodeIgniter\\HomeTest\:\:withHeaders\(\) has parameter \$headers with no value type specified in iterable type array\.$#' - count: 1 - path: ../../tests/system/HomeTest.php - - - - message: '#^Method CodeIgniter\\HomeTest\:\:withRoutes\(\) has parameter \$routes with no value type specified in iterable type array\.$#' - count: 1 - path: ../../tests/system/HomeTest.php - - - - message: '#^Method CodeIgniter\\HomeTest\:\:withSession\(\) has parameter \$values with no value type specified in iterable type array\.$#' - count: 1 - path: ../../tests/system/HomeTest.php - - message: '#^Method CodeIgniter\\I18n\\TimeLegacyTest\:\:provideToStringDoesNotDependOnLocale\(\) return type has no value type specified in iterable type iterable\.$#' count: 1 @@ -6347,21 +6272,6 @@ parameters: count: 1 path: ../../tests/system/Test/FeatureTestAutoRoutingImprovedTest.php - - - message: '#^Method CodeIgniter\\Test\\FeatureTestAutoRoutingImprovedTest\:\:withHeaders\(\) has parameter \$headers with no value type specified in iterable type array\.$#' - count: 1 - path: ../../tests/system/Test/FeatureTestAutoRoutingImprovedTest.php - - - - message: '#^Method CodeIgniter\\Test\\FeatureTestAutoRoutingImprovedTest\:\:withRoutes\(\) has parameter \$routes with no value type specified in iterable type array\.$#' - count: 1 - path: ../../tests/system/Test/FeatureTestAutoRoutingImprovedTest.php - - - - message: '#^Method CodeIgniter\\Test\\FeatureTestAutoRoutingImprovedTest\:\:withSession\(\) has parameter \$values with no value type specified in iterable type array\.$#' - count: 1 - path: ../../tests/system/Test/FeatureTestAutoRoutingImprovedTest.php - - message: '#^Method CodeIgniter\\Test\\FeatureTestTraitTest\:\:call\(\) has parameter \$params with no value type specified in iterable type array\.$#' count: 1 @@ -6412,21 +6322,6 @@ parameters: count: 1 path: ../../tests/system/Test/FeatureTestTraitTest.php - - - message: '#^Method CodeIgniter\\Test\\FeatureTestTraitTest\:\:withHeaders\(\) has parameter \$headers with no value type specified in iterable type array\.$#' - count: 1 - path: ../../tests/system/Test/FeatureTestTraitTest.php - - - - message: '#^Method CodeIgniter\\Test\\FeatureTestTraitTest\:\:withRoutes\(\) has parameter \$routes with no value type specified in iterable type array\.$#' - count: 1 - path: ../../tests/system/Test/FeatureTestTraitTest.php - - - - message: '#^Method CodeIgniter\\Test\\FeatureTestTraitTest\:\:withSession\(\) has parameter \$values with no value type specified in iterable type array\.$#' - count: 1 - path: ../../tests/system/Test/FeatureTestTraitTest.php - - message: '#^Method CodeIgniter\\Test\\IniTestTraitTest\:\:backupIniValues\(\) has parameter \$keys with no value type specified in iterable type array\.$#' count: 1 diff --git a/utils/phpstan-baseline/nullCoalesce.property.neon b/utils/phpstan-baseline/nullCoalesce.property.neon index 88cdd2e7254e..1dbb4f758a25 100644 --- a/utils/phpstan-baseline/nullCoalesce.property.neon +++ b/utils/phpstan-baseline/nullCoalesce.property.neon @@ -1,4 +1,4 @@ -# total 19 errors +# total 16 errors parameters: ignoreErrors: @@ -37,21 +37,6 @@ parameters: count: 1 path: ../../system/Throttle/Throttler.php - - - message: '#^Property CodeIgniter\\Test\\CIUnitTestCase\:\:\$session \(array\) on left side of \?\? is not nullable\.$#' - count: 1 - path: ../../tests/system/HomeTest.php - - - - message: '#^Property CodeIgniter\\Test\\CIUnitTestCase\:\:\$session \(array\) on left side of \?\? is not nullable\.$#' - count: 1 - path: ../../tests/system/Test/FeatureTestAutoRoutingImprovedTest.php - - - - message: '#^Property CodeIgniter\\Test\\CIUnitTestCase\:\:\$session \(array\) on left side of \?\? is not nullable\.$#' - count: 1 - path: ../../tests/system/Test/FeatureTestTraitTest.php - - message: '#^Property CodeIgniter\\Test\\FilterTestTraitTest\:\:\$request \(CodeIgniter\\HTTP\\RequestInterface\) on left side of \?\?\= is not nullable\.$#' count: 1 diff --git a/utils/phpstan-baseline/property.defaultValue.neon b/utils/phpstan-baseline/property.defaultValue.neon index 21d5acab00f2..2b8e75c7009c 100644 --- a/utils/phpstan-baseline/property.defaultValue.neon +++ b/utils/phpstan-baseline/property.defaultValue.neon @@ -1,4 +1,4 @@ -# total 4 errors +# total 1 error parameters: ignoreErrors: @@ -6,18 +6,3 @@ parameters: message: '#^Property CodeIgniter\\Config\\View\:\:\$coreFilters \(array\\) does not accept default value of type array\{abs\: ''\\\\abs'', capitalize\: ''\\\\CodeIgniter\\\\View…'', date\: ''\\\\CodeIgniter\\\\View…'', date_modify\: ''\\\\CodeIgniter\\\\View…'', default\: ''\\\\CodeIgniter\\\\View…'', esc\: ''\\\\CodeIgniter\\\\View…'', excerpt\: ''\\\\CodeIgniter\\\\View…'', highlight\: ''\\\\CodeIgniter\\\\View…'', \.\.\.\}\.$#' count: 1 path: ../../system/Config/View.php - - - - message: '#^Property CodeIgniter\\Test\\CIUnitTestCase\:\:\$seed \(class\-string\\|list\\>\) does not accept default value of type ''''\.$#' - count: 1 - path: ../../system/Test/CIUnitTestCase.php - - - - message: '#^Property CodeIgniter\\Models\\DataConverterModelTest\:\:\$seed \(class\-string\\|list\\>\) does not accept default value of type ''''\.$#' - count: 1 - path: ../../tests/system/Models/DataConverterModelTest.php - - - - message: '#^Property CodeIgniter\\Models\\TimestampModelTest\:\:\$seed \(class\-string\\|list\\>\) does not accept default value of type ''''\.$#' - count: 1 - path: ../../tests/system/Models/TimestampModelTest.php diff --git a/utils/phpstan-baseline/property.phpDocType.neon b/utils/phpstan-baseline/property.phpDocType.neon index dda215c49436..3318d5c97890 100644 --- a/utils/phpstan-baseline/property.phpDocType.neon +++ b/utils/phpstan-baseline/property.phpDocType.neon @@ -1,4 +1,4 @@ -# total 46 errors +# total 44 errors parameters: ignoreErrors: @@ -197,16 +197,6 @@ parameters: count: 1 path: ../../tests/system/Database/Builder/WhereTest.php - - - message: '#^PHPDoc type array\|string of property CodeIgniter\\Database\\DatabaseTestCaseTest\:\:\$seed is not the same as PHPDoc type class\-string\\|list\\> of overridden property CodeIgniter\\Test\\CIUnitTestCase\:\:\$seed\.$#' - count: 1 - path: ../../tests/system/Database/DatabaseTestCaseTest.php - - - - message: '#^PHPDoc type string of property CodeIgniter\\Database\\Live\\MetadataTest\:\:\$seed is not the same as PHPDoc type class\-string\\|list\\> of overridden property CodeIgniter\\Test\\CIUnitTestCase\:\:\$seed\.$#' - count: 1 - path: ../../tests/system/Database/Live/MetadataTest.php - - message: '#^PHPDoc type CodeIgniter\\Database\\SQLite3\\Connection of property CodeIgniter\\Database\\Live\\SQLite3\\GetIndexDataTest\:\:\$db is not the same as PHPDoc type CodeIgniter\\Database\\BaseConnection of overridden property CodeIgniter\\Test\\CIUnitTestCase\:\:\$db\.$#' count: 1