From 4f97aac34420631753a936c2b7decd7f17cb68c0 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 19 Mar 2022 22:52:14 +0700 Subject: [PATCH] [Rector] Clean up skip config and re-run Rector --- app/Config/App.php | 3 +- app/Config/Database.php | 3 +- app/Config/Format.php | 8 +++-- app/Config/Logger.php | 3 +- rector.php | 16 +++++++--- system/Cache/Handlers/PredisHandler.php | 2 +- system/CodeIgniter.php | 2 +- system/Commands/Database/CreateDatabase.php | 3 +- .../Generators/ControllerGenerator.php | 9 ++++-- system/Config/AutoloadConfig.php | 28 +++++++++++------ system/Config/BaseService.php | 4 +-- system/Database/BaseConnection.php | 2 +- system/Database/BasePreparedQuery.php | 2 +- system/Database/BaseResult.php | 3 +- system/Database/MySQLi/Result.php | 2 +- system/Database/OCI8/Result.php | 2 +- system/Database/Postgre/Result.php | 2 +- system/Database/SQLSRV/Result.php | 2 +- system/Database/SQLite3/Connection.php | 2 +- system/Database/SQLite3/Result.php | 4 +-- system/Images/Handlers/ImageMagickHandler.php | 2 +- system/Language/Language.php | 2 +- system/Test/Fabricator.php | 3 +- system/Test/Mock/MockResult.php | 3 +- system/View/View.php | 3 +- tests/system/API/ResponseTraitTest.php | 8 ++--- tests/system/Autoloader/AutoloaderTest.php | 11 +++---- tests/system/Autoloader/FileLocatorTest.php | 5 +-- tests/system/CLI/CLITest.php | 5 +-- tests/system/Cache/CacheFactoryTest.php | 9 +++--- .../system/Cache/Handlers/BaseHandlerTest.php | 5 +-- .../system/Cache/Handlers/FileHandlerTest.php | 3 +- tests/system/CodeIgniterTest.php | 9 ++---- tests/system/CommonFunctionsTest.php | 2 +- tests/system/Config/DotEnvTest.php | 5 +-- tests/system/Config/ServicesTest.php | 3 +- tests/system/Database/Builder/InsertTest.php | 7 +++-- tests/system/Database/Builder/ReplaceTest.php | 3 +- tests/system/Database/Builder/UpdateTest.php | 9 +++--- tests/system/Database/ConfigTest.php | 13 ++++---- tests/system/Database/DatabaseSeederTest.php | 7 +++-- tests/system/Database/Live/DbUtilsTest.php | 5 +-- tests/system/Database/Live/DeleteTest.php | 2 +- tests/system/Database/Live/ForgeTest.php | 31 ++++++++++--------- tests/system/Database/Live/GetTest.php | 5 +-- .../Database/Live/SQLite/AlterTableTest.php | 16 ++++------ .../Migrations/MigrationRunnerTest.php | 5 +-- tests/system/Encryption/EncryptionTest.php | 14 ++++----- .../Handlers/OpenSSLHandlerTest.php | 12 +++---- .../Encryption/Handlers/SodiumHandlerTest.php | 24 ++++++-------- tests/system/Entity/EntityTest.php | 2 +- tests/system/Files/FileTest.php | 3 +- tests/system/Format/FormatTest.php | 8 ++--- tests/system/Format/JSONFormatterTest.php | 3 +- .../HTTP/CURLRequestDoNotShareOptionsTest.php | 7 ++--- tests/system/HTTP/CURLRequestTest.php | 7 ++--- tests/system/Helpers/ArrayHelperTest.php | 6 ++-- tests/system/HomeTest.php | 3 +- tests/system/Honeypot/HoneypotTest.php | 4 +-- tests/system/I18n/TimeTest.php | 22 ++++++------- tests/system/Language/LanguageTest.php | 5 +-- tests/system/Models/FindModelTest.php | 3 +- .../system/RESTful/ResourceControllerTest.php | 10 +++--- .../system/RESTful/ResourcePresenterTest.php | 18 +++++------ .../Session/Handlers/DatabaseHandlerTest.php | 2 +- tests/system/Session/SessionTest.php | 2 +- tests/system/Test/FabricatorTest.php | 8 ++--- tests/system/Test/FilterTestTraitTest.php | 6 ++-- tests/system/View/CellTest.php | 9 ++---- 69 files changed, 235 insertions(+), 226 deletions(-) diff --git a/app/Config/App.php b/app/Config/App.php index 7ab0c7d7cfcb..c6c716822756 100644 --- a/app/Config/App.php +++ b/app/Config/App.php @@ -3,6 +3,7 @@ namespace Config; use CodeIgniter\Config\BaseConfig; +use CodeIgniter\Session\Handlers\FileHandler; class App extends BaseConfig { @@ -151,7 +152,7 @@ class App extends BaseConfig * * @var string */ - public $sessionDriver = 'CodeIgniter\Session\Handlers\FileHandler'; + public $sessionDriver = FileHandler::class; /** * -------------------------------------------------------------------------- diff --git a/app/Config/Database.php b/app/Config/Database.php index 1e6340899bf4..376de53a821d 100644 --- a/app/Config/Database.php +++ b/app/Config/Database.php @@ -3,6 +3,7 @@ namespace Config; use CodeIgniter\Database\Config; +use SQLite3; /** * Database Configuration @@ -62,7 +63,7 @@ class Database extends Config 'username' => '', 'password' => '', 'database' => ':memory:', - 'DBDriver' => 'SQLite3', + 'DBDriver' => SQLite3::class, 'DBPrefix' => 'db_', // Needed to ensure we're working correctly with prefixes live. DO NOT REMOVE FOR CI DEVS 'pConnect' => false, 'DBDebug' => (ENVIRONMENT !== 'production'), diff --git a/app/Config/Format.php b/app/Config/Format.php index 533540e27918..d89e40842c22 100644 --- a/app/Config/Format.php +++ b/app/Config/Format.php @@ -4,6 +4,8 @@ use CodeIgniter\Config\BaseConfig; use CodeIgniter\Format\FormatterInterface; +use CodeIgniter\Format\JSONFormatter; +use CodeIgniter\Format\XMLFormatter; class Format extends BaseConfig { @@ -40,9 +42,9 @@ class Format extends BaseConfig * @var array */ public $formatters = [ - 'application/json' => 'CodeIgniter\Format\JSONFormatter', - 'application/xml' => 'CodeIgniter\Format\XMLFormatter', - 'text/xml' => 'CodeIgniter\Format\XMLFormatter', + 'application/json' => JSONFormatter::class, + 'application/xml' => XMLFormatter::class, + 'text/xml' => XMLFormatter::class, ]; /** diff --git a/app/Config/Logger.php b/app/Config/Logger.php index a4eaeb648955..406d9aaccc85 100644 --- a/app/Config/Logger.php +++ b/app/Config/Logger.php @@ -2,6 +2,7 @@ namespace Config; +use CodeIgniter\Log\Handlers\FileHandler; use CodeIgniter\Config\BaseConfig; class Logger extends BaseConfig @@ -83,7 +84,7 @@ class Logger extends BaseConfig * File Handler * -------------------------------------------------------------------- */ - 'CodeIgniter\Log\Handlers\FileHandler' => [ + FileHandler::class => [ // The log levels that this handler will handle. 'handles' => [ diff --git a/rector.php b/rector.php index b90225d80fcf..6c2bc99bcf8d 100644 --- a/rector.php +++ b/rector.php @@ -84,8 +84,6 @@ RemoveUnusedPrivateMethodRector::class => [ // private method called via getPrivateMethodInvoker __DIR__ . '/tests/system/Test/ReflectionHelperTest.php', - // Rector bug? - __DIR__ . '/system/CodeIgniter.php', ], // call on purpose for nothing happen check @@ -103,9 +101,17 @@ __DIR__ . '/system/Session/Handlers', ], - // may cause load view files directly when detecting class that - // make warning - StringClassNameToClassConstantRector::class, + StringClassNameToClassConstantRector::class => [ + // may cause load view files directly when detecting namespaced string + // due to internal PHPStan issue + __DIR__ . '/app/Config/Pager.php', + __DIR__ . '/app/Config/Validation.php', + __DIR__ . '/tests/system/Validation/StrictRules/ValidationTest.php', + __DIR__ . '/tests/system/Validation/ValidationTest.php', + + // expected Qualified name + __DIR__ . '/tests/system/Autoloader/FileLocatorTest.php', + ], // sometime too detail CountOnNullRector::class, diff --git a/system/Cache/Handlers/PredisHandler.php b/system/Cache/Handlers/PredisHandler.php index 5d1f37cdfc24..87ab4e333dca 100644 --- a/system/Cache/Handlers/PredisHandler.php +++ b/system/Cache/Handlers/PredisHandler.php @@ -222,6 +222,6 @@ public function getMetaData(string $key) */ public function isSupported(): bool { - return class_exists('Predis\Client'); + return class_exists(Client::class); } } diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index 86e70546dd41..127e087458a0 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -830,7 +830,7 @@ protected function startController() $this->benchmark->start('controller_constructor'); // Is it routed to a Closure? - if (is_object($this->controller) && (get_class($this->controller) === 'Closure')) { + if (is_object($this->controller) && (get_class($this->controller) === Closure::class)) { $controller = $this->controller; return $controller(...$this->router->params()); diff --git a/system/Commands/Database/CreateDatabase.php b/system/Commands/Database/CreateDatabase.php index 17e1e51bb68b..0682f945b9bf 100644 --- a/system/Commands/Database/CreateDatabase.php +++ b/system/Commands/Database/CreateDatabase.php @@ -16,6 +16,7 @@ use CodeIgniter\Config\Factories; use CodeIgniter\Database\SQLite3\Connection; use Config\Database; +use SQLite3; use Throwable; /** @@ -106,7 +107,7 @@ public function run(array $params) $name = str_replace(['.db', '.sqlite'], '', $name) . ".{$ext}"; } - $config->{$group}['DBDriver'] = 'SQLite3'; + $config->{$group}['DBDriver'] = SQLite3::class; $config->{$group}['database'] = $name; if ($name !== ':memory:') { diff --git a/system/Commands/Generators/ControllerGenerator.php b/system/Commands/Generators/ControllerGenerator.php index 36a951cf0df0..f27c77ee0fe5 100644 --- a/system/Commands/Generators/ControllerGenerator.php +++ b/system/Commands/Generators/ControllerGenerator.php @@ -14,6 +14,9 @@ use CodeIgniter\CLI\BaseCommand; use CodeIgniter\CLI\CLI; use CodeIgniter\CLI\GeneratorTrait; +use CodeIgniter\Controller; +use CodeIgniter\RESTful\ResourceController; +use CodeIgniter\RESTful\ResourcePresenter; /** * Generates a skeleton controller file. @@ -99,7 +102,7 @@ protected function prepare(string $class): string // Gets the appropriate parent class to extend. if ($bare || $rest) { if ($bare) { - $useStatement = 'CodeIgniter\Controller'; + $useStatement = Controller::class; $extends = 'Controller'; } elseif ($rest) { $rest = is_string($rest) ? $rest : 'controller'; @@ -112,10 +115,10 @@ protected function prepare(string $class): string } if ($rest === 'controller') { - $useStatement = 'CodeIgniter\RESTful\ResourceController'; + $useStatement = ResourceController::class; $extends = 'ResourceController'; } elseif ($rest === 'presenter') { - $useStatement = 'CodeIgniter\RESTful\ResourcePresenter'; + $useStatement = ResourcePresenter::class; $extends = 'ResourcePresenter'; } } diff --git a/system/Config/AutoloadConfig.php b/system/Config/AutoloadConfig.php index d3dbefcd7c3c..13a6721fd2e6 100644 --- a/system/Config/AutoloadConfig.php +++ b/system/Config/AutoloadConfig.php @@ -11,6 +11,16 @@ namespace CodeIgniter\Config; +use Laminas\Escaper\Escaper; +use Psr\Log\AbstractLogger; +use Psr\Log\InvalidArgumentException; +use Psr\Log\LoggerAwareInterface; +use Psr\Log\LoggerAwareTrait; +use Psr\Log\LoggerInterface; +use Psr\Log\LoggerTrait; +use Psr\Log\LogLevel; +use Psr\Log\NullLogger; + /** * AUTOLOADER CONFIGURATION * @@ -93,15 +103,15 @@ class AutoloadConfig * @var array */ protected $coreClassmap = [ - 'Psr\Log\AbstractLogger' => SYSTEMPATH . 'ThirdParty/PSR/Log/AbstractLogger.php', - 'Psr\Log\InvalidArgumentException' => SYSTEMPATH . 'ThirdParty/PSR/Log/InvalidArgumentException.php', - 'Psr\Log\LoggerAwareInterface' => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerAwareInterface.php', - 'Psr\Log\LoggerAwareTrait' => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerAwareTrait.php', - 'Psr\Log\LoggerInterface' => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerInterface.php', - 'Psr\Log\LoggerTrait' => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerTrait.php', - 'Psr\Log\LogLevel' => SYSTEMPATH . 'ThirdParty/PSR/Log/LogLevel.php', - 'Psr\Log\NullLogger' => SYSTEMPATH . 'ThirdParty/PSR/Log/NullLogger.php', - 'Laminas\Escaper\Escaper' => SYSTEMPATH . 'ThirdParty/Escaper/Escaper.php', + AbstractLogger::class => SYSTEMPATH . 'ThirdParty/PSR/Log/AbstractLogger.php', + InvalidArgumentException::class => SYSTEMPATH . 'ThirdParty/PSR/Log/InvalidArgumentException.php', + LoggerAwareInterface::class => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerAwareInterface.php', + LoggerAwareTrait::class => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerAwareTrait.php', + LoggerInterface::class => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerInterface.php', + LoggerTrait::class => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerTrait.php', + LogLevel::class => SYSTEMPATH . 'ThirdParty/PSR/Log/LogLevel.php', + NullLogger::class => SYSTEMPATH . 'ThirdParty/PSR/Log/NullLogger.php', + Escaper::class => SYSTEMPATH . 'ThirdParty/Escaper/Escaper.php', ]; /** diff --git a/system/Config/BaseService.php b/system/Config/BaseService.php index 572b6cf576bd..4244b7a7097d 100644 --- a/system/Config/BaseService.php +++ b/system/Config/BaseService.php @@ -332,7 +332,7 @@ protected static function discoverServices(string $name, array $arguments) foreach ($files as $file) { $classname = $locator->getClassname($file); - if (! in_array($classname, ['CodeIgniter\\Config\\Services'], true)) { + if (! in_array($classname, [\CodeIgniter\Config\Services::class], true)) { static::$services[] = new $classname(); } } @@ -369,7 +369,7 @@ protected static function buildServicesCache(): void foreach ($files as $file) { $classname = $locator->getClassname($file); - if ($classname !== 'CodeIgniter\\Config\\Services') { + if ($classname !== \CodeIgniter\Config\Services::class) { self::$serviceNames[] = $classname; static::$services[] = new $classname(); } diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index 4f54c1980830..d2ce3fdd390a 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -326,7 +326,7 @@ abstract class BaseConnection implements ConnectionInterface * * @var string */ - protected $queryClass = 'CodeIgniter\\Database\\Query'; + protected $queryClass = Query::class; /** * Saves our connection settings. diff --git a/system/Database/BasePreparedQuery.php b/system/Database/BasePreparedQuery.php index b6e2db706d2a..ce5a208a1ef3 100644 --- a/system/Database/BasePreparedQuery.php +++ b/system/Database/BasePreparedQuery.php @@ -69,7 +69,7 @@ public function __construct(BaseConnection $db) * * @return mixed */ - public function prepare(string $sql, array $options = [], string $queryClass = 'CodeIgniter\\Database\\Query') + public function prepare(string $sql, array $options = [], string $queryClass = Query::class) { // We only supports positional placeholders (?) // in order to work with the execute method below, so we diff --git a/system/Database/BaseResult.php b/system/Database/BaseResult.php index 5d223c7fc08b..b5818525dc30 100644 --- a/system/Database/BaseResult.php +++ b/system/Database/BaseResult.php @@ -12,6 +12,7 @@ namespace CodeIgniter\Database; use CodeIgniter\Entity\Entity; +use stdClass; /** * Class BaseResult @@ -508,5 +509,5 @@ abstract protected function fetchAssoc(); * * @return object */ - abstract protected function fetchObject(string $className = 'stdClass'); + abstract protected function fetchObject(string $className = stdClass::class); } diff --git a/system/Database/MySQLi/Result.php b/system/Database/MySQLi/Result.php index 7eab7d86c685..35f480776c85 100644 --- a/system/Database/MySQLi/Result.php +++ b/system/Database/MySQLi/Result.php @@ -139,7 +139,7 @@ protected function fetchAssoc() * * @return bool|Entity|object */ - protected function fetchObject(string $className = 'stdClass') + protected function fetchObject(string $className = stdClass::class) { if (is_subclass_of($className, Entity::class)) { return empty($data = $this->fetchAssoc()) ? false : (new $className())->setAttributes($data); diff --git a/system/Database/OCI8/Result.php b/system/Database/OCI8/Result.php index ce3a73def1c4..6ad26b649480 100644 --- a/system/Database/OCI8/Result.php +++ b/system/Database/OCI8/Result.php @@ -98,7 +98,7 @@ protected function fetchObject(string $className = stdClass::class) { $row = oci_fetch_object($this->resultID); - if ($className === 'stdClass' || ! $row) { + if ($className === stdClass::class || ! $row) { return $row; } if (is_subclass_of($className, Entity::class)) { diff --git a/system/Database/Postgre/Result.php b/system/Database/Postgre/Result.php index 76a0dd956515..581d79b1d421 100644 --- a/system/Database/Postgre/Result.php +++ b/system/Database/Postgre/Result.php @@ -105,7 +105,7 @@ protected function fetchAssoc() * * @return bool|Entity|object */ - protected function fetchObject(string $className = 'stdClass') + protected function fetchObject(string $className = stdClass::class) { if (is_subclass_of($className, Entity::class)) { return empty($data = $this->fetchAssoc()) ? false : (new $className())->setAttributes($data); diff --git a/system/Database/SQLSRV/Result.php b/system/Database/SQLSRV/Result.php index 2a55e452ac09..045a5eebd81a 100755 --- a/system/Database/SQLSRV/Result.php +++ b/system/Database/SQLSRV/Result.php @@ -147,7 +147,7 @@ protected function fetchAssoc() * * @return bool|Entity|object */ - protected function fetchObject(string $className = 'stdClass') + protected function fetchObject(string $className = stdClass::class) { if (is_subclass_of($className, Entity::class)) { return empty($data = $this->fetchAssoc()) ? false : (new $className())->setAttributes($data); diff --git a/system/Database/SQLite3/Connection.php b/system/Database/SQLite3/Connection.php index 39fbca8bcfea..e335e7985ba7 100644 --- a/system/Database/SQLite3/Connection.php +++ b/system/Database/SQLite3/Connection.php @@ -28,7 +28,7 @@ class Connection extends BaseConnection * * @var string */ - public $DBDriver = 'SQLite3'; + public $DBDriver = SQLite3::class; /** * Identifier escape character diff --git a/system/Database/SQLite3/Result.php b/system/Database/SQLite3/Result.php index 6afc04c51578..39b9897af1e4 100644 --- a/system/Database/SQLite3/Result.php +++ b/system/Database/SQLite3/Result.php @@ -122,14 +122,14 @@ protected function fetchAssoc() * * @return bool|object */ - protected function fetchObject(string $className = 'stdClass') + protected function fetchObject(string $className = stdClass::class) { // No native support for fetching rows as objects if (($row = $this->fetchAssoc()) === false) { return false; } - if ($className === 'stdClass') { + if ($className === stdClass::class) { return (object) $row; } diff --git a/system/Images/Handlers/ImageMagickHandler.php b/system/Images/Handlers/ImageMagickHandler.php index 37bd168ead02..5e0bafe00841 100644 --- a/system/Images/Handlers/ImageMagickHandler.php +++ b/system/Images/Handlers/ImageMagickHandler.php @@ -49,7 +49,7 @@ public function __construct($config = null) // We should never see this, so can't test it // @codeCoverageIgnoreStart - if (! (extension_loaded('imagick') || class_exists('Imagick'))) { + if (! (extension_loaded('imagick') || class_exists(Imagick::class))) { throw ImageException::forMissingExtension('IMAGICK'); } // @codeCoverageIgnoreEnd diff --git a/system/Language/Language.php b/system/Language/Language.php index 299618657aa2..640dcfaa552d 100644 --- a/system/Language/Language.php +++ b/system/Language/Language.php @@ -57,7 +57,7 @@ public function __construct(string $locale) { $this->locale = $locale; - if (class_exists('MessageFormatter')) { + if (class_exists(MessageFormatter::class)) { $this->intlSupport = true; } } diff --git a/system/Test/Fabricator.php b/system/Test/Fabricator.php index d4369765f0ee..d474e796df78 100644 --- a/system/Test/Fabricator.php +++ b/system/Test/Fabricator.php @@ -17,6 +17,7 @@ use Faker\Generator; use InvalidArgumentException; use RuntimeException; +use stdClass; /** * Fabricator @@ -409,7 +410,7 @@ public function makeObject(?string $className = null): object { if ($className === null) { if ($this->model->returnType === 'object' || $this->model->returnType === 'array') { - $className = 'stdClass'; + $className = stdClass::class; } else { $className = $this->model->returnType; } diff --git a/system/Test/Mock/MockResult.php b/system/Test/Mock/MockResult.php index 0aaa340a95de..f3807d9170c9 100644 --- a/system/Test/Mock/MockResult.php +++ b/system/Test/Mock/MockResult.php @@ -12,6 +12,7 @@ namespace CodeIgniter\Test\Mock; use CodeIgniter\Database\BaseResult; +use stdClass; class MockResult extends BaseResult { @@ -81,7 +82,7 @@ protected function fetchAssoc() * * @return object */ - protected function fetchObject($className = 'stdClass') + protected function fetchObject($className = stdClass::class) { return new $className(); } diff --git a/system/View/View.php b/system/View/View.php index f557b6629b0a..b0206d67caba 100644 --- a/system/View/View.php +++ b/system/View/View.php @@ -13,6 +13,7 @@ use CodeIgniter\Autoloader\FileLocator; use CodeIgniter\Debug\Toolbar\Collectors\Views; +use CodeIgniter\Filters\DebugToolbar; use CodeIgniter\View\Exceptions\ViewException; use Config\Services; use Config\Toolbar; @@ -235,7 +236,7 @@ public function render(string $view, ?array $options = null, ?bool $saveData = n $this->logPerformance($this->renderVars['start'], microtime(true), $this->renderVars['view']); if (($this->debug && (! isset($options['debug']) || $options['debug'] === true)) - && in_array('CodeIgniter\Filters\DebugToolbar', service('filters')->getFiltersClass()['after'], true) + && in_array(DebugToolbar::class, service('filters')->getFiltersClass()['after'], true) ) { $toolbarCollectors = config(Toolbar::class)->collectors; diff --git a/tests/system/API/ResponseTraitTest.php b/tests/system/API/ResponseTraitTest.php index 8cf06372dcdd..821e217a35b8 100644 --- a/tests/system/API/ResponseTraitTest.php +++ b/tests/system/API/ResponseTraitTest.php @@ -29,11 +29,7 @@ final class ResponseTraitTest extends CIUnitTestCase { protected $request; protected $response; - - /** - * @var FormatterInterface|null - */ - protected $formatter; + protected ?FormatterInterface $formatter = null; protected function setUp(): void { @@ -505,7 +501,7 @@ public function testXMLFormatter() $this->formatter = new XMLFormatter(); $controller = $this->makeController(); - $this->assertInstanceOf('CodeIgniter\Format\XMLFormatter', $this->formatter); + $this->assertInstanceOf(XMLFormatter::class, $this->formatter); $this->invoke($controller, 'respondCreated', [['id' => 3], 'A Custom Reason']); diff --git a/tests/system/Autoloader/AutoloaderTest.php b/tests/system/Autoloader/AutoloaderTest.php index 3c7156abdde2..95d74c6c1b7e 100644 --- a/tests/system/Autoloader/AutoloaderTest.php +++ b/tests/system/Autoloader/AutoloaderTest.php @@ -15,6 +15,7 @@ use Config\Autoload; use Config\Modules; use Config\Services; +use InvalidArgumentException; use UnnamespacedClass; /** @@ -22,12 +23,8 @@ */ final class AutoloaderTest extends CIUnitTestCase { - /** - * @var Autoloader - */ - protected $loader; - - protected $filesPath = SUPPORTPATH . 'Autoloader/'; + protected Autoloader $loader; + protected string $filesPath = SUPPORTPATH . 'Autoloader/'; protected function setUp(): void { @@ -58,7 +55,7 @@ public function testLoadStoredClass() public function testInitializeWithInvalidArguments() { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage("Config array must contain either the 'psr4' key or the 'classmap' key."); $config = new Autoload(); diff --git a/tests/system/Autoloader/FileLocatorTest.php b/tests/system/Autoloader/FileLocatorTest.php index 3a40ed24345b..54a471d74453 100644 --- a/tests/system/Autoloader/FileLocatorTest.php +++ b/tests/system/Autoloader/FileLocatorTest.php @@ -20,10 +20,7 @@ */ final class FileLocatorTest extends CIUnitTestCase { - /** - * @var FileLocator - */ - protected $locator; + protected FileLocator $locator; protected function setUp(): void { diff --git a/tests/system/CLI/CLITest.php b/tests/system/CLI/CLITest.php index 68008ccc1e4d..107ac1463e67 100644 --- a/tests/system/CLI/CLITest.php +++ b/tests/system/CLI/CLITest.php @@ -14,6 +14,7 @@ use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\Filters\CITestStreamFilter; use ReflectionProperty; +use RuntimeException; /** * @internal @@ -100,7 +101,7 @@ public function testNewLine() public function testColorExceptionForeground() { - $this->expectException('RuntimeException'); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Invalid foreground color: Foreground'); CLI::color('test', 'Foreground'); @@ -108,7 +109,7 @@ public function testColorExceptionForeground() public function testColorExceptionBackground() { - $this->expectException('RuntimeException'); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Invalid background color: Background'); CLI::color('test', 'white', 'Background'); diff --git a/tests/system/Cache/CacheFactoryTest.php b/tests/system/Cache/CacheFactoryTest.php index c67d1c805ad0..45bc16df58e8 100644 --- a/tests/system/Cache/CacheFactoryTest.php +++ b/tests/system/Cache/CacheFactoryTest.php @@ -11,6 +11,7 @@ namespace CodeIgniter\Cache; +use CodeIgniter\Cache\Exceptions\CacheException; use CodeIgniter\Cache\Handlers\DummyHandler; use CodeIgniter\Test\CIUnitTestCase; use Config\Cache; @@ -50,7 +51,7 @@ public function testNew() public function testGetHandlerExceptionCacheInvalidHandlers() { - $this->expectException('CodeIgniter\Cache\Exceptions\CacheException'); + $this->expectException(CacheException::class); $this->expectExceptionMessage('Cache config must have an array of $validHandlers.'); $this->config->validHandlers = null; @@ -60,7 +61,7 @@ public function testGetHandlerExceptionCacheInvalidHandlers() public function testGetHandlerExceptionCacheNoBackup() { - $this->expectException('CodeIgniter\Cache\Exceptions\CacheException'); + $this->expectException(CacheException::class); $this->expectExceptionMessage('Cache config must have a handler and backupHandler set.'); $this->config->backupHandler = null; @@ -70,7 +71,7 @@ public function testGetHandlerExceptionCacheNoBackup() public function testGetHandlerExceptionCacheNoHandler() { - $this->expectException('CodeIgniter\Cache\Exceptions\CacheException'); + $this->expectException(CacheException::class); $this->expectExceptionMessage('Cache config must have a handler and backupHandler set.'); $this->config->handler = null; @@ -80,7 +81,7 @@ public function testGetHandlerExceptionCacheNoHandler() public function testGetHandlerExceptionCacheHandlerNotFound() { - $this->expectException('CodeIgniter\Cache\Exceptions\CacheException'); + $this->expectException(CacheException::class); $this->expectExceptionMessage('Cache config has an invalid handler or backup handler specified.'); unset($this->config->validHandlers[$this->config->handler]); diff --git a/tests/system/Cache/Handlers/BaseHandlerTest.php b/tests/system/Cache/Handlers/BaseHandlerTest.php index b2ebb61e01ef..18bfcff0d113 100644 --- a/tests/system/Cache/Handlers/BaseHandlerTest.php +++ b/tests/system/Cache/Handlers/BaseHandlerTest.php @@ -12,6 +12,7 @@ namespace CodeIgniter\Cache\Handlers; use CodeIgniter\Test\CIUnitTestCase; +use InvalidArgumentException; use stdClass; use Tests\Support\Cache\RestrictiveHandler; @@ -27,7 +28,7 @@ final class BaseHandlerTest extends CIUnitTestCase */ public function testValidateKeyInvalidType($input) { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Cache key must be a string'); BaseHandler::validateKey($input); @@ -48,7 +49,7 @@ public function testValidateKeyUsesConfig() { config('Cache')->reservedCharacters = 'b'; - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Cache key contains reserved characters b'); BaseHandler::validateKey('banana'); diff --git a/tests/system/Cache/Handlers/FileHandlerTest.php b/tests/system/Cache/Handlers/FileHandlerTest.php index 032243d890f1..23573dee3314 100644 --- a/tests/system/Cache/Handlers/FileHandlerTest.php +++ b/tests/system/Cache/Handlers/FileHandlerTest.php @@ -11,6 +11,7 @@ namespace CodeIgniter\Cache\Handlers; +use CodeIgniter\Cache\Exceptions\CacheException; use CodeIgniter\CLI\CLI; use Config\Cache; @@ -76,7 +77,7 @@ public function testNew() public function testNewWithNonWritablePath() { - $this->expectException('CodeIgniter\Cache\Exceptions\CacheException'); + $this->expectException(CacheException::class); chmod($this->config->file['storePath'], 0444); new FileHandler($this->config); diff --git a/tests/system/CodeIgniterTest.php b/tests/system/CodeIgniterTest.php index 418bde4530f6..42706e39d110 100644 --- a/tests/system/CodeIgniterTest.php +++ b/tests/system/CodeIgniterTest.php @@ -12,6 +12,7 @@ namespace CodeIgniter; use CodeIgniter\Config\Services; +use CodeIgniter\HTTP\Response; use CodeIgniter\Router\RouteCollection; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\Mock\MockCodeIgniter; @@ -26,11 +27,7 @@ */ final class CodeIgniterTest extends CIUnitTestCase { - /** - * @var CodeIgniter - */ - protected $codeigniter; - + protected CodeIgniter $codeigniter; protected $routes; protected function setUp(): void @@ -218,7 +215,7 @@ public function testResponseConfigEmpty() $response = Services::response(null, false); - $this->assertInstanceOf('\CodeIgniter\HTTP\Response', $response); + $this->assertInstanceOf(Response::class, $response); } public function testRoutesIsEmpty() diff --git a/tests/system/CommonFunctionsTest.php b/tests/system/CommonFunctionsTest.php index 1c8088fdf227..758e1727eca1 100644 --- a/tests/system/CommonFunctionsTest.php +++ b/tests/system/CommonFunctionsTest.php @@ -399,7 +399,7 @@ public function testSlashItem() protected function injectSessionMock() { $defaults = [ - 'sessionDriver' => 'CodeIgniter\Session\Handlers\FileHandler', + 'sessionDriver' => FileHandler::class, 'sessionCookieName' => 'ci_session', 'sessionExpiration' => 7200, 'sessionSavePath' => null, diff --git a/tests/system/Config/DotEnvTest.php b/tests/system/Config/DotEnvTest.php index 2aff090b9576..077bd8f23ea4 100644 --- a/tests/system/Config/DotEnvTest.php +++ b/tests/system/Config/DotEnvTest.php @@ -12,6 +12,7 @@ namespace CodeIgniter\Config; use CodeIgniter\Test\CIUnitTestCase; +use InvalidArgumentException; use org\bovigo\vfs\vfsStream; /** @@ -115,7 +116,7 @@ public function testLoadsUnreadableFile() $file = 'unreadable.env'; $path = rtrim($this->fixturesFolder, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $file; chmod($path, 0000); - $this->expectException('\InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage("The .env file is not readable: {$path}"); $dotenv = new DotEnv($this->fixturesFolder, $file); $dotenv->load(); @@ -135,7 +136,7 @@ public function testQuotedDotenvLoadsEnvironmentVars() public function testSpacedValuesWithoutQuotesThrowsException() { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('.env values containing spaces must be surrounded by quotes.'); $dotenv = new DotEnv($this->fixturesFolder, 'spaced-wrong.env'); diff --git a/tests/system/Config/ServicesTest.php b/tests/system/Config/ServicesTest.php index b33ff13f9387..14fbd27a2910 100644 --- a/tests/system/Config/ServicesTest.php +++ b/tests/system/Config/ServicesTest.php @@ -43,6 +43,7 @@ use CodeIgniter\View\Parser; use Config\App; use Config\Exceptions; +use RuntimeException; use Tests\Support\Config\Services; /** @@ -69,7 +70,7 @@ protected function tearDown(): void public function testCanReplaceFrameworkServices() { - $this->expectException('RuntimeException'); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Service originated from Tests\Support\Config\Services'); Services::uri('testCanReplaceFrameworkServices'); diff --git a/tests/system/Database/Builder/InsertTest.php b/tests/system/Database/Builder/InsertTest.php index 1844434d3a1c..713e77bd15a7 100644 --- a/tests/system/Database/Builder/InsertTest.php +++ b/tests/system/Database/Builder/InsertTest.php @@ -11,6 +11,7 @@ namespace CodeIgniter\Database\Builder; +use CodeIgniter\Database\Exceptions\DatabaseException; use CodeIgniter\Database\Query; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\Mock\MockConnection; @@ -62,7 +63,7 @@ public function testThrowsExceptionOnNoValuesSet() { $builder = $this->db->table('jobs'); - $this->expectException('\CodeIgniter\Database\Exceptions\DatabaseException'); + $this->expectException(DatabaseException::class); $this->expectExceptionMessage('You must use the "set" method to update an entry.'); $builder->testMode()->insert(null, true); @@ -192,7 +193,7 @@ public function testInsertBatchThrowsExceptionOnNoData() { $builder = $this->db->table('jobs'); - $this->expectException('\CodeIgniter\Database\Exceptions\DatabaseException'); + $this->expectException(DatabaseException::class); $this->expectExceptionMessage('You must use the "set" method to update an entry.'); $builder->insertBatch(); } @@ -201,7 +202,7 @@ public function testInsertBatchThrowsExceptionOnEmptyData() { $builder = $this->db->table('jobs'); - $this->expectException('\CodeIgniter\Database\Exceptions\DatabaseException'); + $this->expectException(DatabaseException::class); $this->expectExceptionMessage('insertBatch() called with no data'); $builder->insertBatch([]); } diff --git a/tests/system/Database/Builder/ReplaceTest.php b/tests/system/Database/Builder/ReplaceTest.php index 4197ed05449d..e7a1262cb107 100644 --- a/tests/system/Database/Builder/ReplaceTest.php +++ b/tests/system/Database/Builder/ReplaceTest.php @@ -11,6 +11,7 @@ namespace CodeIgniter\Database\Builder; +use CodeIgniter\Database\Exceptions\DatabaseException; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\Mock\MockConnection; @@ -47,7 +48,7 @@ public function testReplaceThrowsExceptionWithNoData() { $builder = $this->db->table('jobs'); - $this->expectException('\CodeIgniter\Database\Exceptions\DatabaseException'); + $this->expectException(DatabaseException::class); $this->expectExceptionMessage('You must use the "set" method to update an entry.'); $builder->replace(); diff --git a/tests/system/Database/Builder/UpdateTest.php b/tests/system/Database/Builder/UpdateTest.php index bda9ae49915d..5af1490f6f66 100644 --- a/tests/system/Database/Builder/UpdateTest.php +++ b/tests/system/Database/Builder/UpdateTest.php @@ -12,6 +12,7 @@ namespace CodeIgniter\Database\Builder; use CodeIgniter\Database\BaseBuilder; +use CodeIgniter\Database\Exceptions\DatabaseException; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\Mock\MockConnection; use CodeIgniter\Test\Mock\MockQuery; @@ -177,7 +178,7 @@ public function testUpdateThrowsExceptionWithNoData() { $builder = new BaseBuilder('jobs', $this->db); - $this->expectException('CodeIgniter\Database\Exceptions\DatabaseException'); + $this->expectException(DatabaseException::class); $this->expectExceptionMessage('You must use the "set" method to update an entry.'); $builder->update(null, null, null); @@ -266,7 +267,7 @@ public function testUpdateBatchThrowsExceptionWithNoData() { $builder = new BaseBuilder('jobs', $this->db); - $this->expectException('\CodeIgniter\Database\Exceptions\DatabaseException'); + $this->expectException(DatabaseException::class); $this->expectExceptionMessage('You must use the "set" method to update an entry.'); $builder->updateBatch(null, 'id'); @@ -276,7 +277,7 @@ public function testUpdateBatchThrowsExceptionWithNoID() { $builder = new BaseBuilder('jobs', $this->db); - $this->expectException('\CodeIgniter\Database\Exceptions\DatabaseException'); + $this->expectException(DatabaseException::class); $this->expectExceptionMessage('You must specify an index to match on for batch updates.'); $builder->updateBatch([]); @@ -286,7 +287,7 @@ public function testUpdateBatchThrowsExceptionWithEmptySetArray() { $builder = new BaseBuilder('jobs', $this->db); - $this->expectException('\CodeIgniter\Database\Exceptions\DatabaseException'); + $this->expectException(DatabaseException::class); $this->expectExceptionMessage('updateBatch() called with no data'); $builder->updateBatch([], 'id'); diff --git a/tests/system/Database/ConfigTest.php b/tests/system/Database/ConfigTest.php index 0dc9a1619485..301a95158bf1 100644 --- a/tests/system/Database/ConfigTest.php +++ b/tests/system/Database/ConfigTest.php @@ -13,6 +13,7 @@ use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\ReflectionHelper; +use SQLite3; /** * @internal @@ -21,7 +22,7 @@ final class ConfigTest extends CIUnitTestCase { use ReflectionHelper; - protected $group = [ + protected array $group = [ 'DSN' => '', 'hostname' => 'localhost', 'username' => 'first', @@ -40,13 +41,13 @@ final class ConfigTest extends CIUnitTestCase 'failover' => [], 'port' => 3306, ]; - protected $dsnGroup = [ + protected array $dsnGroup = [ 'DSN' => 'MySQLi://user:pass@localhost:3306/dbname?DBPrefix=test_&pConnect=true&charset=latin1&DBCollat=latin1_swedish_ci', 'hostname' => '', 'username' => '', 'password' => '', 'database' => '', - 'DBDriver' => 'SQLite3', + 'DBDriver' => SQLite3::class, 'DBPrefix' => 't_', 'pConnect' => false, 'DBDebug' => (ENVIRONMENT !== 'production'), @@ -59,13 +60,13 @@ final class ConfigTest extends CIUnitTestCase 'failover' => [], 'port' => 3306, ]; - protected $dsnGroupPostgre = [ + protected array $dsnGroupPostgre = [ 'DSN' => 'Postgre://user:pass@localhost:5432/dbname?DBPrefix=test_&connect_timeout=5&sslmode=1', 'hostname' => '', 'username' => '', 'password' => '', 'database' => '', - 'DBDriver' => 'SQLite3', + 'DBDriver' => SQLite3::class, 'DBPrefix' => 't_', 'pConnect' => false, 'DBDebug' => (ENVIRONMENT !== 'production'), @@ -78,7 +79,7 @@ final class ConfigTest extends CIUnitTestCase 'failover' => [], 'port' => 5432, ]; - protected $dsnGroupPostgreNative = [ + protected array $dsnGroupPostgreNative = [ 'DSN' => 'pgsql:host=localhost;port=5432;dbname=database_name', 'hostname' => '', 'username' => '', diff --git a/tests/system/Database/DatabaseSeederTest.php b/tests/system/Database/DatabaseSeederTest.php index 7e08d6648508..70721718ea8a 100644 --- a/tests/system/Database/DatabaseSeederTest.php +++ b/tests/system/Database/DatabaseSeederTest.php @@ -14,6 +14,7 @@ use CodeIgniter\Test\CIUnitTestCase; use Config\Database; use Faker\Generator; +use InvalidArgumentException; /** * @internal @@ -22,7 +23,7 @@ final class DatabaseSeederTest extends CIUnitTestCase { public function testInstantiateNoSeedPath() { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $config = new Database(); $config->filesPath = ''; @@ -31,7 +32,7 @@ public function testInstantiateNoSeedPath() public function testInstantiateNotDirSeedPath() { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $config = new Database(); $config->filesPath = APPPATH . 'Foo'; @@ -48,7 +49,7 @@ public function testFakerGet() public function testCallOnEmptySeeder() { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $seeder = new Seeder(new Database()); $seeder->call(''); diff --git a/tests/system/Database/Live/DbUtilsTest.php b/tests/system/Database/Live/DbUtilsTest.php index e767d0b6991d..414412a72ded 100644 --- a/tests/system/Database/Live/DbUtilsTest.php +++ b/tests/system/Database/Live/DbUtilsTest.php @@ -15,6 +15,7 @@ use CodeIgniter\Database\Exceptions\DatabaseException; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\DatabaseTestTrait; +use SQLite3; /** * @group DatabaseLive @@ -80,7 +81,7 @@ public function testUtilsListDatabases() $databases = $util->listDatabases(); $this->assertContains($this->db->getDatabase(), $databases); - } elseif ($this->db->DBDriver === 'SQLite3') { + } elseif ($this->db->DBDriver === SQLite3::class) { $this->expectException(DatabaseException::class); $this->expectExceptionMessage('Unsupported feature of the database platform you are using.'); @@ -96,7 +97,7 @@ public function testUtilsDatabaseExist() $exist = $util->databaseExists($this->db->getDatabase()); $this->assertTrue($exist); - } elseif ($this->db->DBDriver === 'SQLite3') { + } elseif ($this->db->DBDriver === SQLite3::class) { $this->expectException(DatabaseException::class); $this->expectExceptionMessage('Unsupported feature of the database platform you are using.'); diff --git a/tests/system/Database/Live/DeleteTest.php b/tests/system/Database/Live/DeleteTest.php index 31b89412e78a..f8311e9d042a 100644 --- a/tests/system/Database/Live/DeleteTest.php +++ b/tests/system/Database/Live/DeleteTest.php @@ -29,7 +29,7 @@ final class DeleteTest extends CIUnitTestCase public function testDeleteThrowExceptionWithNoCriteria() { - $this->expectException('\CodeIgniter\Database\Exceptions\DatabaseException'); + $this->expectException(DatabaseException::class); $this->db->table('job')->delete(); } diff --git a/tests/system/Database/Live/ForgeTest.php b/tests/system/Database/Live/ForgeTest.php index 113f2c0a211e..f83593ed320e 100644 --- a/tests/system/Database/Live/ForgeTest.php +++ b/tests/system/Database/Live/ForgeTest.php @@ -18,6 +18,7 @@ use Config\Database; use InvalidArgumentException; use RuntimeException; +use SQLite3; /** * @group DatabaseLive @@ -56,7 +57,7 @@ public function testCreateDatabaseIfNotExists() $dbName = 'test_forge_database_exist'; $databaseCreateIfNotExists = $this->forge->createDatabase($dbName, true); - if ($this->db->DBDriver !== 'SQLite3') { + if ($this->db->DBDriver !== SQLite3::class) { $this->forge->dropDatabase($dbName); } @@ -72,7 +73,7 @@ public function testCreateDatabaseIfNotExistsWithDb() $this->forge->createDatabase($dbName); $databaseExists = $this->forge->createDatabase($dbName, true); - if ($this->db->DBDriver !== 'SQLite3') { + if ($this->db->DBDriver !== SQLite3::class) { $this->forge->dropDatabase($dbName); } @@ -84,7 +85,7 @@ public function testDropDatabase() if ($this->db->DBDriver === 'OCI8') { $this->markTestSkipped('OCI8 does not support drop database.'); } - if ($this->db->DBDriver === 'SQLite3') { + if ($this->db->DBDriver === SQLite3::class) { $this->markTestSkipped('SQLite3 requires file path to drop database'); } @@ -97,7 +98,7 @@ public function testCreateDatabaseExceptionNoCreateStatement() { $this->setPrivateProperty($this->forge, 'createDatabaseStr', false); - if ($this->db->DBDriver === 'SQLite3') { + if ($this->db->DBDriver === SQLite3::class) { $databaseCreated = $this->forge->createDatabase('test_forge_database'); $this->assertTrue($databaseCreated); } else { @@ -112,7 +113,7 @@ public function testDropDatabaseExceptionNoDropStatement() { $this->setPrivateProperty($this->forge, 'dropDatabaseStr', false); - if ($this->db->DBDriver === 'SQLite3') { + if ($this->db->DBDriver === SQLite3::class) { $this->markTestSkipped('SQLite3 requires file path to drop database'); } else { $this->expectException(DatabaseException::class); @@ -175,7 +176,7 @@ public function testCreateTableApplyBigInt() $this->assertSame(strtolower($fieldsData[0]->type), 'bigint'); } elseif ($this->db->DBDriver === 'Postgre') { $this->assertSame(strtolower($fieldsData[0]->type), 'bigint'); - } elseif ($this->db->DBDriver === 'SQLite3') { + } elseif ($this->db->DBDriver === SQLite3::class) { $this->assertSame(strtolower($fieldsData[0]->type), 'integer'); } elseif ($this->db->DBDriver === 'OCI8') { $this->assertSame(strtolower($fieldsData[0]->type), 'number'); @@ -191,7 +192,7 @@ public function testCreateTableWithAttributes() if ($this->db->DBDriver === 'OCI8') { $this->markTestSkipped('OCI8 does not support comments on tables or columns.'); } - if ($this->db->DBDriver === 'SQLite3') { + if ($this->db->DBDriver === SQLite3::class) { $this->markTestSkipped('SQLite3 does not support comments on tables or columns.'); } @@ -213,7 +214,7 @@ public function testCreateTableWithAttributes() public function testCreateTableWithArrayFieldConstraints() { - if (in_array($this->db->DBDriver, ['MySQLi', 'SQLite3'], true)) { + if (in_array($this->db->DBDriver, ['MySQLi', SQLite3::class], true)) { $this->forge->dropTable('forge_array_constraint', true); $this->forge->addField([ 'status' => [ @@ -231,7 +232,7 @@ public function testCreateTableWithArrayFieldConstraints() $this->assertSame('status', $fields[0]->name); - if ($this->db->DBDriver === 'SQLite3') { + if ($this->db->DBDriver === SQLite3::class) { // SQLite3 converts array constraints to TEXT CHECK(...) $this->assertSame('TEXT', $fields[0]->type); } else { @@ -431,7 +432,7 @@ public function testForeignKey() $foreignKeyData = $this->db->getForeignKeyData($tableName); - if ($this->db->DBDriver === 'SQLite3') { + if ($this->db->DBDriver === SQLite3::class) { $this->assertSame($foreignKeyData[0]->constraint_name, 'users_id to db_forge_test_users.id'); $this->assertSame($foreignKeyData[0]->sequence, 0); } elseif ($this->db->DBDriver === 'OCI8') { @@ -553,7 +554,7 @@ public function testCompositeForeignKey() $foreignKeyData = $this->db->getForeignKeyData($forgeTestInvoicesTableName); - if ($this->db->DBDriver === 'SQLite3') { + if ($this->db->DBDriver === SQLite3::class) { $this->assertSame('users_id to db_forge_test_users.id', $foreignKeyData[0]->constraint_name); $this->assertSame(0, $foreignKeyData[0]->sequence); $this->assertSame('users_second_id to db_forge_test_users.second_id', $foreignKeyData[1]->constraint_name); @@ -843,7 +844,7 @@ public function testAddFields() $this->assertSame(32, (int) $fieldsData[0]->max_length); $this->assertNull($fieldsData[1]->default); $this->assertSame(255, (int) $fieldsData[1]->max_length); - } elseif ($this->db->DBDriver === 'SQLite3') { + } elseif ($this->db->DBDriver === SQLite3::class) { $this->assertSame('integer', strtolower($fieldsData[0]->type)); $this->assertSame('varchar', strtolower($fieldsData[1]->type)); $this->assertNull($fieldsData[1]->default); @@ -868,7 +869,7 @@ public function testAddFields() public function testCompositeKey() { // SQLite3 uses auto increment different - $uniqueOrAuto = $this->db->DBDriver === 'SQLite3' ? 'unique' : 'auto_increment'; + $uniqueOrAuto = $this->db->DBDriver === SQLite3::class ? 'unique' : 'auto_increment'; $this->forge->addField([ 'id' => [ @@ -916,7 +917,7 @@ public function testCompositeKey() $this->assertSame($keys['db_forge_test_1_code_active']->name, 'db_forge_test_1_code_active'); $this->assertSame($keys['db_forge_test_1_code_active']->fields, ['code', 'active']); $this->assertSame($keys['db_forge_test_1_code_active']->type, 'UNIQUE'); - } elseif ($this->db->DBDriver === 'SQLite3') { + } elseif ($this->db->DBDriver === SQLite3::class) { $this->assertSame($keys['sqlite_autoindex_db_forge_test_1_1']->name, 'sqlite_autoindex_db_forge_test_1_1'); $this->assertSame($keys['sqlite_autoindex_db_forge_test_1_1']->fields, ['id']); $this->assertSame($keys['db_forge_test_1_code_company']->name, 'db_forge_test_1_code_company'); @@ -1054,7 +1055,7 @@ public function testDropTableSuccess() $this->assertFalse($this->db->tableExists('dropTest')); - if ($this->db->DBDriver === 'SQLite3') { + if ($this->db->DBDriver === SQLite3::class) { $this->assertCount(0, $this->db->getIndexData('droptest')); } } diff --git a/tests/system/Database/Live/GetTest.php b/tests/system/Database/Live/GetTest.php index 20ae2e099d0d..768f24d72de3 100644 --- a/tests/system/Database/Live/GetTest.php +++ b/tests/system/Database/Live/GetTest.php @@ -14,6 +14,7 @@ use CodeIgniter\Database\Exceptions\DatabaseException; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\DatabaseTestTrait; +use SQLite3; /** * @group DatabaseLive @@ -91,7 +92,7 @@ public function testGetFieldData() $typeTest = $this->db->table('type_test')->get()->getFieldData(); - if ($this->db->DBDriver === 'SQLite3') { + if ($this->db->DBDriver === SQLite3::class) { $this->assertSame('integer', $typeTest[0]->type_name); // INTEGER AUTO INC $this->assertSame('text', $typeTest[1]->type_name); // VARCHAR $this->assertSame('text', $typeTest[2]->type_name); // CHAR @@ -172,7 +173,7 @@ public function testGetDataSeek() { $data = $this->db->table('job')->get(); - if ($this->db->DBDriver === 'SQLite3') { + if ($this->db->DBDriver === SQLite3::class) { $this->expectException(DatabaseException::class); $this->expectExceptionMessage('SQLite3 doesn\'t support seeking to other offset.'); } elseif ($this->db->DBDriver === 'OCI8') { diff --git a/tests/system/Database/Live/SQLite/AlterTableTest.php b/tests/system/Database/Live/SQLite/AlterTableTest.php index 2816008a2a54..8889c9d8f639 100644 --- a/tests/system/Database/Live/SQLite/AlterTableTest.php +++ b/tests/system/Database/Live/SQLite/AlterTableTest.php @@ -11,12 +11,14 @@ namespace CodeIgniter\Database\Live\SQLite; +use CodeIgniter\Database\Exceptions\DataException; use CodeIgniter\Database\SQLite3\Connection; use CodeIgniter\Database\SQLite3\Forge; use CodeIgniter\Database\SQLite3\Table; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\DatabaseTestTrait; use Config\Database; +use SQLite3; /** * @group DatabaseLive @@ -34,27 +36,21 @@ final class AlterTableTest extends CIUnitTestCase */ protected $migrate = false; - /** - * @var Table - */ - protected $table; + protected Table $table; /** * @var Connection */ protected $db; - /** - * @var Forge - */ - protected $forge; + protected Forge $forge; protected function setUp(): void { parent::setUp(); $config = [ - 'DBDriver' => 'SQLite3', + 'DBDriver' => SQLite3::class, 'database' => 'database.db', ]; @@ -77,7 +73,7 @@ private function dropTables() public function testFromTableThrowsOnNoTable() { - $this->expectException('CodeIgniter\Database\Exceptions\DataException'); + $this->expectException(DataException::class); $this->expectExceptionMessage('Table `foo` was not found in the current database.'); $this->table->fromTable('foo'); diff --git a/tests/system/Database/Migrations/MigrationRunnerTest.php b/tests/system/Database/Migrations/MigrationRunnerTest.php index 2c9fa09e1d73..9a5f467ed9c2 100644 --- a/tests/system/Database/Migrations/MigrationRunnerTest.php +++ b/tests/system/Database/Migrations/MigrationRunnerTest.php @@ -22,6 +22,7 @@ use Config\Migrations; use Config\Services; use org\bovigo\vfs\vfsStream; +use SQLite3; /** * @group DatabaseLive @@ -74,7 +75,7 @@ public function testLoadsDefaultDatabaseWhenNoneSpecified() $this->assertInstanceOf(BaseConnection::class, $db); $this->assertSame( - ($dbConfig->tests['DBDriver'] === 'SQLite3' ? WRITEPATH : '') . $dbConfig->tests['database'], + ($dbConfig->tests['DBDriver'] === SQLite3::class ? WRITEPATH : '') . $dbConfig->tests['database'], $this->getPrivateProperty($db, 'database') ); $this->assertSame($dbConfig->tests['DBDriver'], $this->getPrivateProperty($db, 'DBDriver')); @@ -254,7 +255,7 @@ public function testFindMigrationsSuccessTimestamp() public function testMigrationThrowsDisabledException() { - $this->expectException('CodeIgniter\Exceptions\ConfigException'); + $this->expectException(ConfigException::class); $this->expectExceptionMessage('Migrations have been loaded but are disabled or setup incorrectly.'); $config = $this->config; diff --git a/tests/system/Encryption/EncryptionTest.php b/tests/system/Encryption/EncryptionTest.php index a1f6085a33a6..cb4eb4cad7da 100644 --- a/tests/system/Encryption/EncryptionTest.php +++ b/tests/system/Encryption/EncryptionTest.php @@ -11,6 +11,7 @@ namespace CodeIgniter\Encryption; +use CodeIgniter\Encryption\Exceptions\EncryptionException; use CodeIgniter\Test\CIUnitTestCase; use Config\Encryption as EncryptionConfig; use Config\Services; @@ -20,10 +21,7 @@ */ final class EncryptionTest extends CIUnitTestCase { - /** - * @var \CodeIgniter\Encryption\Encryption - */ - protected $encryption; + protected \CodeIgniter\Encryption\Encryption $encryption; protected function setUp(): void { @@ -57,7 +55,7 @@ public function testConstructor() */ public function testBadDriver() { - $this->expectException('CodeIgniter\Encryption\Exceptions\EncryptionException'); + $this->expectException(EncryptionException::class); // ask for a bad driver $config = new EncryptionConfig(); @@ -72,7 +70,7 @@ public function testBadDriver() */ public function testMissingDriver() { - $this->expectException('CodeIgniter\Encryption\Exceptions\EncryptionException'); + $this->expectException(EncryptionException::class); // ask for a bad driver $config = new EncryptionConfig(); @@ -101,7 +99,7 @@ public function testServiceSuccess() public function testServiceFailure() { - $this->expectException('CodeIgniter\Encryption\Exceptions\EncryptionException'); + $this->expectException(EncryptionException::class); // ask for a bad driver $config = new EncryptionConfig(); @@ -113,7 +111,7 @@ public function testServiceFailure() public function testServiceWithoutKey() { - $this->expectException('CodeIgniter\Encryption\Exceptions\EncryptionException'); + $this->expectException(EncryptionException::class); Services::encrypter(); } diff --git a/tests/system/Encryption/Handlers/OpenSSLHandlerTest.php b/tests/system/Encryption/Handlers/OpenSSLHandlerTest.php index 89886b6f8901..5427c99a5edb 100644 --- a/tests/system/Encryption/Handlers/OpenSSLHandlerTest.php +++ b/tests/system/Encryption/Handlers/OpenSSLHandlerTest.php @@ -12,6 +12,7 @@ namespace CodeIgniter\Encryption\Handlers; use CodeIgniter\Encryption\Encryption; +use CodeIgniter\Encryption\Exceptions\EncryptionException; use CodeIgniter\Test\CIUnitTestCase; use Config\Encryption as EncryptionConfig; @@ -20,10 +21,7 @@ */ final class OpenSSLHandlerTest extends CIUnitTestCase { - /** - * @var \CodeIgniter\Encryption\Encryption - */ - protected $encryption; + protected \CodeIgniter\Encryption\Encryption $encryption; protected function setUp(): void { @@ -79,7 +77,7 @@ public function testSimple() */ public function testWithoutKey() { - $this->expectException('CodeIgniter\Encryption\Exceptions\EncryptionException'); + $this->expectException(EncryptionException::class); $encrypter = new OpenSSLHandler(); $message1 = 'This is a plain-text message.'; @@ -100,7 +98,7 @@ public function testWithKeyString() */ public function testWithWrongKeyString() { - $this->expectException('CodeIgniter\Encryption\Exceptions\EncryptionException'); + $this->expectException(EncryptionException::class); $key1 = 'abracadabra'; $encrypter = new OpenSSLHandler(); @@ -125,7 +123,7 @@ public function testWithKeyArray() */ public function testWithWrongKeyArray() { - $this->expectException('CodeIgniter\Encryption\Exceptions\EncryptionException'); + $this->expectException(EncryptionException::class); $key1 = 'abracadabra'; $encrypter = new OpenSSLHandler(); diff --git a/tests/system/Encryption/Handlers/SodiumHandlerTest.php b/tests/system/Encryption/Handlers/SodiumHandlerTest.php index fc5f353d2ffb..421af43e1330 100644 --- a/tests/system/Encryption/Handlers/SodiumHandlerTest.php +++ b/tests/system/Encryption/Handlers/SodiumHandlerTest.php @@ -12,6 +12,7 @@ namespace CodeIgniter\Encryption\Handlers; use CodeIgniter\Encryption\Encryption; +use CodeIgniter\Encryption\Exceptions\EncryptionException; use CodeIgniter\Test\CIUnitTestCase; use Config\Encryption as EncryptionConfig; @@ -20,15 +21,8 @@ */ final class SodiumHandlerTest extends CIUnitTestCase { - /** - * @var \CodeIgniter\Encryption\Encryption - */ - protected $encryption; - - /** - * @var \Config\Encryption - */ - protected $config; + protected \CodeIgniter\Encryption\Encryption $encryption; + protected \Config\Encryption $config; protected function setUp(): void { @@ -57,7 +51,7 @@ public function testPropertiesGetter() public function testEmptyKeyThrowsErrorOnInitialize() { - $this->expectException('CodeIgniter\Encryption\Exceptions\EncryptionException'); + $this->expectException(EncryptionException::class); $this->config->key = ''; $this->encryption->initialize($this->config); @@ -65,7 +59,7 @@ public function testEmptyKeyThrowsErrorOnInitialize() public function testEmptyKeyThrowsErrorOnEncrypt() { - $this->expectException('CodeIgniter\Encryption\Exceptions\EncryptionException'); + $this->expectException(EncryptionException::class); $encrypter = $this->encryption->initialize($this->config); $encrypter->encrypt('Some message to encrypt', ''); @@ -73,7 +67,7 @@ public function testEmptyKeyThrowsErrorOnEncrypt() public function testInvalidBlockSizeThrowsErrorOnEncrypt() { - $this->expectException('CodeIgniter\Encryption\Exceptions\EncryptionException'); + $this->expectException(EncryptionException::class); $this->config->blockSize = -1; $encrypter = $this->encryption->initialize($this->config); @@ -82,7 +76,7 @@ public function testInvalidBlockSizeThrowsErrorOnEncrypt() public function testEmptyKeyThrowsErrorOnDecrypt() { - $this->expectException('CodeIgniter\Encryption\Exceptions\EncryptionException'); + $this->expectException(EncryptionException::class); $encrypter = $this->encryption->initialize($this->config); $ciphertext = $encrypter->encrypt('Some message to encrypt'); @@ -92,7 +86,7 @@ public function testEmptyKeyThrowsErrorOnDecrypt() public function testInvalidBlockSizeThrowsErrorOnDecrypt() { - $this->expectException('CodeIgniter\Encryption\Exceptions\EncryptionException'); + $this->expectException(EncryptionException::class); $key = $this->config->key; $encrypter = $this->encryption->initialize($this->config); @@ -103,7 +97,7 @@ public function testInvalidBlockSizeThrowsErrorOnDecrypt() public function testTruncatedMessageThrowsErrorOnDecrypt() { - $this->expectException('CodeIgniter\Encryption\Exceptions\EncryptionException'); + $this->expectException(EncryptionException::class); $encrypter = $this->encryption->initialize($this->config); $ciphertext = $encrypter->encrypt('Some message to encrypt'); diff --git a/tests/system/Entity/EntityTest.php b/tests/system/Entity/EntityTest.php index a9a59502575f..82c758f92f5e 100644 --- a/tests/system/Entity/EntityTest.php +++ b/tests/system/Entity/EntityTest.php @@ -382,7 +382,7 @@ public function testCastDateTime() $entity->eighth = 'March 12, 2017'; - $this->assertInstanceOf('DateTime', $entity->eighth); + $this->assertInstanceOf(DateTime::class, $entity->eighth); $this->assertSame('2017-03-12', $entity->eighth->format('Y-m-d')); } diff --git a/tests/system/Files/FileTest.php b/tests/system/Files/FileTest.php index 6ff5b77fd3bc..573c8cdb3499 100644 --- a/tests/system/Files/FileTest.php +++ b/tests/system/Files/FileTest.php @@ -11,6 +11,7 @@ namespace CodeIgniter\Files; +use CodeIgniter\Files\Exceptions\FileNotFoundException; use CodeIgniter\Test\CIUnitTestCase; /** @@ -85,7 +86,7 @@ public function testGetSizeReturnsBytes() public function testThrowsExceptionIfNotAFile() { - $this->expectException('CodeIgniter\Files\Exceptions\FileNotFoundException'); + $this->expectException(FileNotFoundException::class); new File(SYSTEMPATH . 'Commoner.php', true); } diff --git a/tests/system/Format/FormatTest.php b/tests/system/Format/FormatTest.php index 0cd53e62a22c..3bc6854fa3ae 100644 --- a/tests/system/Format/FormatTest.php +++ b/tests/system/Format/FormatTest.php @@ -12,6 +12,7 @@ namespace CodeIgniter\Format; use CodeIgniter\Format\Exceptions\FormatException; +use CodeIgniter\HTTP\URI; use CodeIgniter\Test\CIUnitTestCase; /** @@ -19,10 +20,7 @@ */ final class FormatTest extends CIUnitTestCase { - /** - * @var Format - */ - protected $format; + protected Format $format; protected function setUp(): void { @@ -66,7 +64,7 @@ public function testGetFormatterExpectsExceptionOnClassNotImplementingFormatterI { $this->format->getConfig()->formatters = array_merge( $this->format->getConfig()->formatters, - ['text/xml' => 'CodeIgniter\HTTP\URI'] + ['text/xml' => URI::class] ); $this->expectException(FormatException::class); diff --git a/tests/system/Format/JSONFormatterTest.php b/tests/system/Format/JSONFormatterTest.php index b2eb5f2e0d5e..19dacb02e86c 100644 --- a/tests/system/Format/JSONFormatterTest.php +++ b/tests/system/Format/JSONFormatterTest.php @@ -12,6 +12,7 @@ namespace CodeIgniter\Format; use CodeIgniter\Test\CIUnitTestCase; +use RuntimeException; /** * @internal @@ -67,7 +68,7 @@ public function testKeepsURLs() public function testJSONError() { - $this->expectException('RuntimeException'); + $this->expectException(RuntimeException::class); $data = ["\xB1\x31"]; $expected = 'Boom'; diff --git a/tests/system/HTTP/CURLRequestDoNotShareOptionsTest.php b/tests/system/HTTP/CURLRequestDoNotShareOptionsTest.php index 21070736d741..bcf9d1c51124 100644 --- a/tests/system/HTTP/CURLRequestDoNotShareOptionsTest.php +++ b/tests/system/HTTP/CURLRequestDoNotShareOptionsTest.php @@ -25,10 +25,7 @@ */ final class CURLRequestDoNotShareOptionsTest extends CIUnitTestCase { - /** - * @var MockCURLRequest - */ - protected $request; + protected MockCURLRequest $request; protected function setUp(): void { @@ -96,7 +93,7 @@ public function testSendReturnsResponse() $response = $this->request->setOutput($output)->send('get', 'http://example.com'); - $this->assertInstanceOf('CodeIgniter\\HTTP\\Response', $response); + $this->assertInstanceOf(Response::class, $response); $this->assertSame($output, $response->getBody()); } diff --git a/tests/system/HTTP/CURLRequestTest.php b/tests/system/HTTP/CURLRequestTest.php index 64b824cbad56..31808a739e29 100644 --- a/tests/system/HTTP/CURLRequestTest.php +++ b/tests/system/HTTP/CURLRequestTest.php @@ -25,10 +25,7 @@ */ final class CURLRequestTest extends CIUnitTestCase { - /** - * @var MockCURLRequest - */ - protected $request; + protected MockCURLRequest $request; protected function setUp(): void { @@ -96,7 +93,7 @@ public function testSendReturnsResponse() $response = $this->request->setOutput($output)->send('get', 'http://example.com'); - $this->assertInstanceOf('CodeIgniter\\HTTP\\Response', $response); + $this->assertInstanceOf(Response::class, $response); $this->assertSame($output, $response->getBody()); } diff --git a/tests/system/Helpers/ArrayHelperTest.php b/tests/system/Helpers/ArrayHelperTest.php index 90413c570a00..59257fbab7d6 100644 --- a/tests/system/Helpers/ArrayHelperTest.php +++ b/tests/system/Helpers/ArrayHelperTest.php @@ -12,6 +12,8 @@ namespace CodeIgniter\Helpers; use CodeIgniter\Test\CIUnitTestCase; +use ErrorException; +use ValueError; /** * @internal @@ -295,9 +297,9 @@ public function testArraySortByMultipleKeysFailsInconsistentArraySizes($data) { // PHP 8 changes this error type if (version_compare(PHP_VERSION, '8.0', '<')) { - $this->expectException('ErrorException'); + $this->expectException(ErrorException::class); } else { - $this->expectException('ValueError'); + $this->expectException(ValueError::class); } $this->expectExceptionMessage('Array sizes are inconsistent'); diff --git a/tests/system/HomeTest.php b/tests/system/HomeTest.php index fca482d3dec8..382e6c4ee522 100644 --- a/tests/system/HomeTest.php +++ b/tests/system/HomeTest.php @@ -13,6 +13,7 @@ use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\FeatureTestTrait; +use CodeIgniter\Test\TestResponse; /** * @internal @@ -32,7 +33,7 @@ public function testPageLoadsSuccessfully() ]); $response = $this->get('home'); - $this->assertInstanceOf('CodeIgniter\Test\TestResponse', $response); + $this->assertInstanceOf(TestResponse::class, $response); $this->assertTrue($response->isOK()); } } diff --git a/tests/system/Honeypot/HoneypotTest.php b/tests/system/Honeypot/HoneypotTest.php index 860d552d4e86..b732b27fca7b 100644 --- a/tests/system/Honeypot/HoneypotTest.php +++ b/tests/system/Honeypot/HoneypotTest.php @@ -103,7 +103,7 @@ public function testConfigName() public function testHoneypotFilterBefore() { $config = [ - 'aliases' => ['trap' => '\CodeIgniter\Filters\Honeypot'], + 'aliases' => ['trap' => \CodeIgniter\Filters\Honeypot::class], 'globals' => [ 'before' => ['trap'], 'after' => [], @@ -120,7 +120,7 @@ public function testHoneypotFilterBefore() public function testHoneypotFilterAfter() { $config = [ - 'aliases' => ['trap' => '\CodeIgniter\Filters\Honeypot'], + 'aliases' => ['trap' => \CodeIgniter\Filters\Honeypot::class], 'globals' => [ 'before' => [], 'after' => ['trap'], diff --git a/tests/system/I18n/TimeTest.php b/tests/system/I18n/TimeTest.php index ed1b747699a4..03f142479478 100644 --- a/tests/system/I18n/TimeTest.php +++ b/tests/system/I18n/TimeTest.php @@ -497,7 +497,7 @@ public function testSetDay() public function testSetDayOverMaxInCurrentMonth() { - $this->expectException('CodeIgniter\I18n\Exceptions\I18nException'); + $this->expectException(I18nException::class); $time = Time::parse('Feb 02, 2009'); $time->setDay(29); @@ -545,7 +545,7 @@ public function testSetSecond() public function testSetMonthTooSmall() { - $this->expectException('CodeIgniter\I18n\Exceptions\I18nException'); + $this->expectException(I18nException::class); $time = Time::parse('May 10, 2017'); $time->setMonth(-5); @@ -553,7 +553,7 @@ public function testSetMonthTooSmall() public function testSetMonthTooBig() { - $this->expectException('CodeIgniter\I18n\Exceptions\I18nException'); + $this->expectException(I18nException::class); $time = Time::parse('May 10, 2017'); $time->setMonth(30); @@ -561,7 +561,7 @@ public function testSetMonthTooBig() public function testSetDayTooSmall() { - $this->expectException('CodeIgniter\I18n\Exceptions\I18nException'); + $this->expectException(I18nException::class); $time = Time::parse('May 10, 2017'); $time->setDay(-5); @@ -569,7 +569,7 @@ public function testSetDayTooSmall() public function testSetDayTooBig() { - $this->expectException('CodeIgniter\I18n\Exceptions\I18nException'); + $this->expectException(I18nException::class); $time = Time::parse('May 10, 2017'); $time->setDay(80); @@ -577,7 +577,7 @@ public function testSetDayTooBig() public function testSetHourTooSmall() { - $this->expectException('CodeIgniter\I18n\Exceptions\I18nException'); + $this->expectException(I18nException::class); $time = Time::parse('May 10, 2017'); $time->setHour(-5); @@ -585,7 +585,7 @@ public function testSetHourTooSmall() public function testSetHourTooBig() { - $this->expectException('CodeIgniter\I18n\Exceptions\I18nException'); + $this->expectException(I18nException::class); $time = Time::parse('May 10, 2017'); $time->setHour(80); @@ -593,7 +593,7 @@ public function testSetHourTooBig() public function testSetMinuteTooSmall() { - $this->expectException('CodeIgniter\I18n\Exceptions\I18nException'); + $this->expectException(I18nException::class); $time = Time::parse('May 10, 2017'); $time->setMinute(-5); @@ -601,7 +601,7 @@ public function testSetMinuteTooSmall() public function testSetMinuteTooBig() { - $this->expectException('CodeIgniter\I18n\Exceptions\I18nException'); + $this->expectException(I18nException::class); $time = Time::parse('May 10, 2017'); $time->setMinute(80); @@ -609,7 +609,7 @@ public function testSetMinuteTooBig() public function testSetSecondTooSmall() { - $this->expectException('CodeIgniter\I18n\Exceptions\I18nException'); + $this->expectException(I18nException::class); $time = Time::parse('May 10, 2017'); $time->setSecond(-5); @@ -617,7 +617,7 @@ public function testSetSecondTooSmall() public function testSetSecondTooBig() { - $this->expectException('CodeIgniter\I18n\Exceptions\I18nException'); + $this->expectException(I18nException::class); $time = Time::parse('May 10, 2017'); $time->setSecond(80); diff --git a/tests/system/Language/LanguageTest.php b/tests/system/Language/LanguageTest.php index f89e6dd18125..58994434b3ec 100644 --- a/tests/system/Language/LanguageTest.php +++ b/tests/system/Language/LanguageTest.php @@ -14,6 +14,7 @@ use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\Mock\MockLanguage; use Config\Services; +use MessageFormatter; use Tests\Support\Language\SecondMockLanguage; /** @@ -96,7 +97,7 @@ public function testGetLineArrayReturnsLineArray() public function testGetLineFormatsMessage() { // No intl extension? then we can't test this - go away.... - if (! class_exists('MessageFormatter')) { + if (! class_exists(MessageFormatter::class)) { $this->markTestSkipped('No intl support.'); } @@ -110,7 +111,7 @@ public function testGetLineFormatsMessage() public function testGetLineArrayFormatsMessages() { // No intl extension? Then we can't test this - go away... - if (! class_exists('MessageFormatter')) { + if (! class_exists(MessageFormatter::class)) { $this->markTestSkipped('No intl support.'); } diff --git a/tests/system/Models/FindModelTest.php b/tests/system/Models/FindModelTest.php index e564f570ec8c..e0fdad5024a1 100644 --- a/tests/system/Models/FindModelTest.php +++ b/tests/system/Models/FindModelTest.php @@ -13,6 +13,7 @@ use CodeIgniter\Database\Exceptions\DataException; use CodeIgniter\Exceptions\ModelException; +use stdClass; use Tests\Support\Models\JobModel; use Tests\Support\Models\SecondaryModel; use Tests\Support\Models\UserModel; @@ -295,7 +296,7 @@ public function testFirstWithNoPrimaryKey(): void ]); $record = $this->model->first(); - $this->assertInstanceOf('stdClass', $record); + $this->assertInstanceOf(stdClass::class, $record); $this->assertSame('foo', $record->key); } diff --git a/tests/system/RESTful/ResourceControllerTest.php b/tests/system/RESTful/ResourceControllerTest.php index e6098527d09c..06719fdbfd85 100644 --- a/tests/system/RESTful/ResourceControllerTest.php +++ b/tests/system/RESTful/ResourceControllerTest.php @@ -19,6 +19,7 @@ use CodeIgniter\HTTP\Response; use CodeIgniter\HTTP\URI; use CodeIgniter\HTTP\UserAgent; +use CodeIgniter\Model; use CodeIgniter\Router\RouteCollection; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\Mock\MockCodeIgniter; @@ -40,10 +41,7 @@ */ final class ResourceControllerTest extends CIUnitTestCase { - /** - * @var CodeIgniter - */ - protected $codeigniter; + protected CodeIgniter $codeigniter; /** * @var RouteCollection @@ -247,7 +245,7 @@ public function testModelByName() { $resource = new MockResourceController(); $resource->setModel('\Tests\Support\Models\UserModel'); - $this->assertInstanceOf('CodeIgniter\Model', $resource->getModel()); + $this->assertInstanceOf(Model::class, $resource->getModel()); $this->assertSame('\Tests\Support\Models\UserModel', $resource->getModelName()); } @@ -256,7 +254,7 @@ public function testModelByObject() $resource = new MockResourceController(); $model = new UserModel(); $resource->setModel($model); - $this->assertInstanceOf('CodeIgniter\Model', $resource->getModel()); + $this->assertInstanceOf(Model::class, $resource->getModel()); // Note that the leading backslash is missing if we build it this way $this->assertSame('Tests\Support\Models\UserModel', $resource->getModelName()); diff --git a/tests/system/RESTful/ResourcePresenterTest.php b/tests/system/RESTful/ResourcePresenterTest.php index 26ea1084b196..568b395a778c 100644 --- a/tests/system/RESTful/ResourcePresenterTest.php +++ b/tests/system/RESTful/ResourcePresenterTest.php @@ -13,6 +13,7 @@ use CodeIgniter\CodeIgniter; use CodeIgniter\Config\Services; +use CodeIgniter\Model; use CodeIgniter\Router\RouteCollection; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\Mock\MockCodeIgniter; @@ -34,10 +35,7 @@ */ final class ResourcePresenterTest extends CIUnitTestCase { - /** - * @var CodeIgniter - */ - protected $codeigniter; + protected CodeIgniter $codeigniter; /** * @var RouteCollection @@ -247,7 +245,7 @@ public function testModelByName() { $resource = new MockResourcePresenter(); $resource->setModel('\Tests\Support\Models\UserModel'); - $this->assertInstanceOf('CodeIgniter\Model', $resource->getModel()); + $this->assertInstanceOf(Model::class, $resource->getModel()); $this->assertSame('\Tests\Support\Models\UserModel', $resource->getModelName()); } @@ -256,7 +254,7 @@ public function testModelByObject() $resource = new MockResourcePresenter(); $model = new UserModel(); $resource->setModel($model); - $this->assertInstanceOf('CodeIgniter\Model', $resource->getModel()); + $this->assertInstanceOf(Model::class, $resource->getModel()); // Note that the leading backslash is missing if we build it this way $this->assertSame('Tests\Support\Models\UserModel', $resource->getModelName()); @@ -266,12 +264,12 @@ public function testChangeSetModelByObject() { $resource = new MockResourcePresenter(); $resource->setModel('\Tests\Support\Models\UserModel'); - $this->assertInstanceOf('CodeIgniter\Model', $resource->getModel()); + $this->assertInstanceOf(Model::class, $resource->getModel()); $this->assertSame('\Tests\Support\Models\UserModel', $resource->getModelName()); $model = new EntityModel(); $resource->setModel($model); - $this->assertInstanceOf('CodeIgniter\Model', $resource->getModel()); + $this->assertInstanceOf(Model::class, $resource->getModel()); $this->assertSame('Tests\Support\Models\EntityModel', $resource->getModelName()); } @@ -279,11 +277,11 @@ public function testChangeSetModelByName() { $resource = new MockResourcePresenter(); $resource->setModel('\Tests\Support\Models\UserModel'); - $this->assertInstanceOf('CodeIgniter\Model', $resource->getModel()); + $this->assertInstanceOf(Model::class, $resource->getModel()); $this->assertSame('\Tests\Support\Models\UserModel', $resource->getModelName()); $resource->setModel('\Tests\Support\Models\EntityModel'); - $this->assertInstanceOf('CodeIgniter\Model', $resource->getModel()); + $this->assertInstanceOf(Model::class, $resource->getModel()); $this->assertSame('\Tests\Support\Models\EntityModel', $resource->getModelName()); } } diff --git a/tests/system/Session/Handlers/DatabaseHandlerTest.php b/tests/system/Session/Handlers/DatabaseHandlerTest.php index 2349bc292bd8..7af077606cba 100644 --- a/tests/system/Session/Handlers/DatabaseHandlerTest.php +++ b/tests/system/Session/Handlers/DatabaseHandlerTest.php @@ -40,7 +40,7 @@ protected function setUp(): void protected function getInstance($options = []) { $defaults = [ - 'sessionDriver' => 'CodeIgniter\Session\Handlers\DatabaseHandler', + 'sessionDriver' => DatabaseHandler::class, 'sessionCookieName' => 'ci_session', 'sessionExpiration' => 7200, 'sessionSavePath' => 'ci_sessions', diff --git a/tests/system/Session/SessionTest.php b/tests/system/Session/SessionTest.php index c295e26ba7d3..574ffaf99ce9 100644 --- a/tests/system/Session/SessionTest.php +++ b/tests/system/Session/SessionTest.php @@ -41,7 +41,7 @@ protected function setUp(): void protected function getInstance($options = []) { $defaults = [ - 'sessionDriver' => 'CodeIgniter\Session\Handlers\FileHandler', + 'sessionDriver' => FileHandler::class, 'sessionCookieName' => 'ci_session', 'sessionExpiration' => 7200, 'sessionSavePath' => null, diff --git a/tests/system/Test/FabricatorTest.php b/tests/system/Test/FabricatorTest.php index f7ba5781979a..13de446cbcb9 100644 --- a/tests/system/Test/FabricatorTest.php +++ b/tests/system/Test/FabricatorTest.php @@ -26,10 +26,8 @@ final class FabricatorTest extends CIUnitTestCase { /** * Default formatters to use for UserModel. Should match detected version. - * - * @var array */ - protected $formatters = [ + protected array $formatters = [ 'name' => 'name', 'email' => 'email', 'country' => 'country', @@ -363,7 +361,7 @@ public function testMakeReturnsSingleton() $result = $fabricator->make(); - $this->assertInstanceOf('stdClass', $result); + $this->assertInstanceOf(stdClass::class, $result); } public function testMakeReturnsExpectedCount() @@ -383,7 +381,7 @@ public function testCreateMockReturnsSingleton() $result = $fabricator->create(null, true); - $this->assertInstanceOf('stdClass', $result); + $this->assertInstanceOf(stdClass::class, $result); } public function testCreateMockReturnsExpectedCount() diff --git a/tests/system/Test/FilterTestTraitTest.php b/tests/system/Test/FilterTestTraitTest.php index 15b98379fbcf..f3cb0a4a6165 100644 --- a/tests/system/Test/FilterTestTraitTest.php +++ b/tests/system/Test/FilterTestTraitTest.php @@ -11,8 +11,10 @@ namespace CodeIgniter\Test; +use Closure; use CodeIgniter\Filters\Filters; use CodeIgniter\HTTP\RequestInterface; +use InvalidArgumentException; use Tests\Support\Filters\Customfilter; /** @@ -50,12 +52,12 @@ public function testGetCallerReturnsClosure() $caller = $this->getFilterCaller('test-customfilter', 'before'); $this->assertIsCallable($caller); - $this->assertInstanceOf('Closure', $caller); + $this->assertInstanceOf(Closure::class, $caller); } public function testGetCallerInvalidPosition() { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Invalid filter position passed: banana'); $this->getFilterCaller('test-customfilter', 'banana'); diff --git a/tests/system/View/CellTest.php b/tests/system/View/CellTest.php index 2d05fad5fbf2..f15e7ce16abb 100644 --- a/tests/system/View/CellTest.php +++ b/tests/system/View/CellTest.php @@ -11,6 +11,7 @@ namespace CodeIgniter\View; +use CodeIgniter\HTTP\Response; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\Mock\MockCache; use CodeIgniter\View\Exceptions\ViewException; @@ -21,11 +22,7 @@ final class CellTest extends CIUnitTestCase { protected $cache; - - /** - * @var Cell - */ - protected $cell; + protected Cell $cell; protected function setUp(): void { @@ -252,6 +249,6 @@ public function testParametersDontMatch() public function testCallInitControllerIfMethodExists() { - $this->assertSame('CodeIgniter\HTTP\Response', $this->cell->render('\Tests\Support\View\SampleClassWithInitController::index')); + $this->assertSame(Response::class, $this->cell->render('\Tests\Support\View\SampleClassWithInitController::index')); } }