diff --git a/composer.json b/composer.json index e703580fd4b9..b291ea49c21c 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "mikey179/vfsstream": "^1.6.12", "nexusphp/tachycardia": "^2.0", "phpstan/extension-installer": "^1.4", - "phpstan/phpstan": "^2.2.1", + "phpstan/phpstan": "^2.2.15", "phpstan/phpstan-strict-rules": "^2.0", "phpunit/phpcov": "^9.0.2 || ^10.0", "phpunit/phpunit": "^10.5.16 || ^11.2", diff --git a/tests/system/Config/ServicesTest.php b/tests/system/Config/ServicesTest.php index 66c9158e67ab..f9b8d8158c39 100644 --- a/tests/system/Config/ServicesTest.php +++ b/tests/system/Config/ServicesTest.php @@ -197,7 +197,8 @@ public function testNewUnsharedLanguage(): void { $actual = Services::language(null, false); $this->assertInstanceOf(Language::class, $actual); - $this->assertSame('en', $actual->getLocale()); + $locale = $actual->getLocale(); + $this->assertSame('en', $locale); Services::language('la', false); $this->assertSame('en', $actual->getLocale()); diff --git a/tests/system/Email/EmailTest.php b/tests/system/Email/EmailTest.php index fc94686589d1..a54bf8d90ce5 100644 --- a/tests/system/Email/EmailTest.php +++ b/tests/system/Email/EmailTest.php @@ -713,7 +713,8 @@ public function testSetPriorityFallback(): void // Priority 6 is invalid, falls back to 3 $email->setPriority(6); - $this->assertSame(3, $this->getPrivateProperty($email, 'priority')); + $priority = $this->getPrivateProperty($email, 'priority'); + $this->assertSame(3, $priority); // Priority 0 is invalid, falls back to 3 $email->setPriority(0); diff --git a/tests/system/Encryption/Handlers/OpenSSLHandlerTest.php b/tests/system/Encryption/Handlers/OpenSSLHandlerTest.php index bac22a881f0a..01254f31b810 100644 --- a/tests/system/Encryption/Handlers/OpenSSLHandlerTest.php +++ b/tests/system/Encryption/Handlers/OpenSSLHandlerTest.php @@ -149,7 +149,8 @@ public function testInternalKeyNotModifiedByParams(): void $encrypter = $this->encryption->initialize($params); $this->assertInstanceOf(OpenSSLHandler::class, $encrypter); - $this->assertSame('original-key-value', $encrypter->key); + $key = $encrypter->key; + $this->assertSame('original-key-value', $key); $message = 'This is a plain-text message.'; $differentKey = 'temporary-param-key'; diff --git a/tests/system/Encryption/Handlers/SodiumHandlerTest.php b/tests/system/Encryption/Handlers/SodiumHandlerTest.php index 47406cef00d0..fe63cec36fb9 100644 --- a/tests/system/Encryption/Handlers/SodiumHandlerTest.php +++ b/tests/system/Encryption/Handlers/SodiumHandlerTest.php @@ -139,7 +139,8 @@ public function testInternalKeyNotModifiedByParams(): void $encrypter = $this->encryption->initialize($this->config); $this->assertInstanceOf(SodiumHandler::class, $encrypter); - $this->assertSame($originalKey, $encrypter->key); + $key = $encrypter->key; + $this->assertSame($originalKey, $key); $message = 'This is a plain-text message.'; $differentKey = sodium_crypto_secretbox_keygen(); diff --git a/tests/system/Entity/EntityTest.php b/tests/system/Entity/EntityTest.php index be8f64f31775..3aff3fac3a10 100644 --- a/tests/system/Entity/EntityTest.php +++ b/tests/system/Entity/EntityTest.php @@ -373,8 +373,9 @@ public function testCastInteger(): void $entity->first = 3.1; - $this->assertIsInt($entity->first); - $this->assertSame(3, $entity->first); + $first = $entity->first; + $this->assertIsInt($first); + $this->assertSame(3, $first); $entity->first = 3.6; diff --git a/tests/system/Events/EventsTest.php b/tests/system/Events/EventsTest.php index bfdef1e2bbe9..39be06b1235b 100644 --- a/tests/system/Events/EventsTest.php +++ b/tests/system/Events/EventsTest.php @@ -69,7 +69,8 @@ public function testInitialize(): void // but we should be able to change it through the backdoor MockEvents::setFiles(['/peanuts']); - $this->assertSame(['/peanuts'], Events::getFiles()); + $files = Events::getFiles(); + $this->assertSame(['/peanuts'], $files); // re-initializing should have no effect MockEvents::initialize(); diff --git a/tests/system/HTTP/IncomingRequestTest.php b/tests/system/HTTP/IncomingRequestTest.php index 90e6c7d57e90..464b46e2ce2c 100644 --- a/tests/system/HTTP/IncomingRequestTest.php +++ b/tests/system/HTTP/IncomingRequestTest.php @@ -1057,7 +1057,8 @@ public function testGetIPAddressNormal(): void $request = new Request(new App()); $request->populateHeaders(); - $this->assertSame($expected, $request->getIPAddress()); + $ipAddress = $request->getIPAddress(); + $this->assertSame($expected, $ipAddress); // call a second time to exercise the initial conditional block in getIPAddress() $this->assertSame($expected, $request->getIPAddress()); } diff --git a/tests/system/HTTP/RequestTest.php b/tests/system/HTTP/RequestTest.php index e1f70bdd272f..2dafdc4fd792 100644 --- a/tests/system/HTTP/RequestTest.php +++ b/tests/system/HTTP/RequestTest.php @@ -562,7 +562,8 @@ public function testGetIPAddressNormal(): void $expected = '123.123.123.123'; service('superglobals')->setServer('REMOTE_ADDR', $expected); $this->request = new Request(new App()); - $this->assertSame($expected, $this->request->getIPAddress()); + $ipAddress = $this->request->getIPAddress(); + $this->assertSame($expected, $ipAddress); // call a second time to exercise the initial conditional block in getIPAddress() $this->assertSame($expected, $this->request->getIPAddress()); } diff --git a/tests/system/Helpers/FormHelperTest.php b/tests/system/Helpers/FormHelperTest.php index 73cbe2430a5f..c24d34b04a3e 100644 --- a/tests/system/Helpers/FormHelperTest.php +++ b/tests/system/Helpers/FormHelperTest.php @@ -870,7 +870,8 @@ public function testSetValue(): void public function testSetSelect(): void { $_SESSION['_ci_old_input']['post']['foo'] = 'bar'; - $this->assertSame(' selected="selected"', set_select('foo', 'bar')); + $selected = set_select('foo', 'bar'); + $this->assertSame(' selected="selected"', $selected); $_SESSION['_ci_old_input']['post']['foo'] = ['foo' => 'bar']; $this->assertSame(' selected="selected"', set_select('foo', 'bar')); @@ -890,7 +891,8 @@ public function testSetCheckbox(): void ], ]; - $this->assertSame(' checked="checked"', set_checkbox('foo', 'bar')); + $checked = set_checkbox('foo', 'bar'); + $this->assertSame(' checked="checked"', $checked); $_SESSION = [ '_ci_old_input' => [ @@ -919,7 +921,8 @@ public function testSetCheckboxWithValueZero(): void ], ]; - $this->assertSame(' checked="checked"', set_checkbox('foo', '0')); + $checked = set_checkbox('foo', '0'); + $this->assertSame(' checked="checked"', $checked); $_SESSION = [ '_ci_old_input' => [ diff --git a/tests/system/Helpers/TextHelperTest.php b/tests/system/Helpers/TextHelperTest.php index 212f2797bacf..a4702db4b604 100644 --- a/tests/system/Helpers/TextHelperTest.php +++ b/tests/system/Helpers/TextHelperTest.php @@ -161,7 +161,8 @@ public function testIncrementString(): void $this->assertSame('my-test_1', increment_string('my-test')); $this->assertSame('my-test-1', increment_string('my-test', '-')); $this->assertSame('file_5', increment_string('file_4')); - $this->assertSame('file-5', increment_string('file-4', '-')); + $incremented = increment_string('file-4', '-'); + $this->assertSame('file-5', $incremented); $this->assertSame('file-5', increment_string('file-4', '-')); $this->assertSame('file-1', increment_string('file', '-', 1)); $this->assertSame('124', increment_string('123', '')); diff --git a/tests/system/Language/LanguageTest.php b/tests/system/Language/LanguageTest.php index 6233941e7d75..b67292da2236 100644 --- a/tests/system/Language/LanguageTest.php +++ b/tests/system/Language/LanguageTest.php @@ -338,10 +338,12 @@ public function testLangKeepLocale(): void $lang = service('language', 'en', true); lang('Language.languageGetLineInvalidArgumentException'); - $this->assertSame('en', $lang->getLocale()); + $locale = $lang->getLocale(); + $this->assertSame('en', $locale); lang('Language.languageGetLineInvalidArgumentException', [], 'ru'); - $this->assertSame('en', $lang->getLocale()); + $locale = $lang->getLocale(); + $this->assertSame('en', $locale); lang('Language.languageGetLineInvalidArgumentException'); $this->assertSame('en', $lang->getLocale()); diff --git a/tests/system/Session/Handlers/Database/RedisHandlerTest.php b/tests/system/Session/Handlers/Database/RedisHandlerTest.php index 637132669aec..c2f549e31659 100644 --- a/tests/system/Session/Handlers/Database/RedisHandlerTest.php +++ b/tests/system/Session/Handlers/Database/RedisHandlerTest.php @@ -142,7 +142,8 @@ public function testSecondaryReadAfterClose(): void $expected = <<<'DATA' __ci_last_regenerate|i:1664607454;_ci_previous_url|s:32:"http://localhost:8080/index.php/";key|s:5:"value"; DATA; - $this->assertSame($expected, $handler->read('555556b43phsnnf8if6bo33b635e4447')); + $data = $handler->read('555556b43phsnnf8if6bo33b635e4447'); + $this->assertSame($expected, $data); $handler->close(); diff --git a/tests/system/Throttle/ThrottleTest.php b/tests/system/Throttle/ThrottleTest.php index 98751a86781b..b16606341ab7 100644 --- a/tests/system/Throttle/ThrottleTest.php +++ b/tests/system/Throttle/ThrottleTest.php @@ -39,7 +39,8 @@ public function testTokenTime(): void $throttler = new Throttler($this->cache); // tokenTime should be 0 to start - $this->assertSame(0, $throttler->getTokenTime()); + $tokenTime = $throttler->getTokenTime(); + $this->assertSame(0, $tokenTime); // set $rate $rate = 1; // allow 1 request per minute diff --git a/tests/system/View/ParserTest.php b/tests/system/View/ParserTest.php index 95d807729c58..36e8707430d6 100644 --- a/tests/system/View/ParserTest.php +++ b/tests/system/View/ParserTest.php @@ -962,7 +962,8 @@ public function testCachedRender(): void $this->parser->setVar('teststring', 'Hello World'); $expected = "

Hello World

\n"; - $this->assertSame($expected, $this->parser->render('template1', ['cache' => 10, 'cache_name' => 'HelloWorld'])); + $output = $this->parser->render('template1', ['cache' => 10, 'cache_name' => 'HelloWorld']); + $this->assertSame($expected, $output); // this second renderings should go thru the cache $this->assertSame($expected, $this->parser->render('template1', ['cache' => 10, 'cache_name' => 'HelloWorld'])); }