Skip to content

Commit 66cc4fc

Browse files
committed
Fix PR comments
1 parent 785bdfa commit 66cc4fc

File tree

7 files changed

+39
-45
lines changed

7 files changed

+39
-45
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"codemix/yii2-localeurls": "^1.7",
3030
"codeception/module-asserts": ">= 3.0",
3131
"codeception/module-filesystem": "> 3.0",
32-
"phpstan/phpstan": "^1.10"
32+
"phpstan/phpstan": "^1.10",
33+
"rector/rector": "^1.2"
3334
},
3435
"autoload":{
3536
"classmap": ["src/"]

src/Codeception/Lib/Connector/Yii2.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function getInternalDomains(): array
181181
if ($urlManager->enablePrettyUrl) {
182182
foreach ($urlManager->rules as $rule) {
183183
/** @var \yii\web\UrlRule $rule */
184-
if (isset($rule->host)) {
184+
if ($rule->host !== null) {
185185
$domains[] = $this->getDomainRegex($rule->host);
186186
}
187187
}
@@ -228,10 +228,10 @@ private function getDomainRegex(string $template): string
228228
$template = $matches[1];
229229
}
230230
$parameters = [];
231-
if (strpos($template, '<') !== false) {
231+
if (str_contains($template, '<')) {
232232
$template = preg_replace_callback(
233233
'/<(?:\w+):?([^>]+)?>/u',
234-
function ($matches) use (&$parameters) {
234+
function ($matches) use (&$parameters): string {
235235
$key = '__' . count($parameters) . '__';
236236
$parameters[$key] = $matches[1] ?? '\w+';
237237
return $key;
@@ -258,7 +258,7 @@ public function startApp(?\yii\log\Logger $logger = null): void
258258
codecept_debug('Starting application');
259259
$config = require($this->configFile);
260260
if (!isset($config['class'])) {
261-
$config['class'] = $this->applicationClass ?? 'yii\web\Application';
261+
$config['class'] = $this->applicationClass ?? \yii\web\Application::class;
262262
}
263263

264264
if (isset($config['container'])) {
@@ -267,10 +267,9 @@ public function startApp(?\yii\log\Logger $logger = null): void
267267
}
268268

269269
$config = $this->mockMailer($config);
270-
/** @var \yii\base\Application $app */
271270
Yii::$app = Yii::createObject($config);
272271

273-
if ($logger !== null) {
272+
if ($logger instanceof \yii\log\Logger) {
274273
Yii::setLogger($logger);
275274
} else {
276275
Yii::setLogger(new Logger());
@@ -502,9 +501,9 @@ protected function resetResponse(Application $app): void
502501
$method = $this->responseCleanMethod;
503502
// First check the current response object.
504503
if (
505-
($app->response->hasEventHandlers(\yii\web\Response::EVENT_BEFORE_SEND)
506-
|| $app->response->hasEventHandlers(\yii\web\Response::EVENT_AFTER_SEND)
507-
|| $app->response->hasEventHandlers(\yii\web\Response::EVENT_AFTER_PREPARE)
504+
($app->response->hasEventHandlers(YiiResponse::EVENT_BEFORE_SEND)
505+
|| $app->response->hasEventHandlers(YiiResponse::EVENT_AFTER_SEND)
506+
|| $app->response->hasEventHandlers(YiiResponse::EVENT_AFTER_PREPARE)
508507
|| count($app->response->getBehaviors()) > 0)
509508
&& $method === self::CLEAN_RECREATE
510509
) {
@@ -549,14 +548,14 @@ protected function resetRequest(Application $app): void
549548
$request->getHeaders()->removeAll();
550549
$request->setBaseUrl(null);
551550
$request->setHostInfo(null);
552-
$request->setPathInfo('');
553-
$request->setScriptFile('');
554-
$request->setScriptUrl('');
555-
$request->setUrl('');
551+
$request->setPathInfo(null);
552+
$request->setScriptFile(null);
553+
$request->setScriptUrl(null);
554+
$request->setUrl(null);
556555
$request->setPort(0);
557556
$request->setSecurePort(0);
558-
$request->setAcceptableContentTypes([]);
559-
$request->setAcceptableLanguages([]);
557+
$request->setAcceptableContentTypes(null);
558+
$request->setAcceptableLanguages(null);
560559
})(),
561560
self::CLEAN_MANUAL => null,
562561
default => throw new \InvalidArgumentException("Unknown method: $method"),

src/Codeception/Lib/Connector/Yii2/ConnectionWatcher.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
namespace Codeception\Lib\Connector\Yii2;
66

7+
use Closure;
8+
use JsonSerializable;
9+
use ReflectionClass;
710
use yii\base\Event;
811
use yii\db\Connection;
9-
use ReflectionClass;
1012

1113
/**
1214
* Class ConnectionWatcher
@@ -15,7 +17,7 @@
1517
*/
1618
class ConnectionWatcher
1719
{
18-
private \Closure $handler;
20+
private Closure $handler;
1921

2022
/** @var Connection[] */
2123
private array $connections = [];
@@ -56,7 +58,7 @@ public function closeAll(): void
5658
}
5759
}
5860

59-
protected function debug(mixed $message): void
61+
protected function debug(string|array|JsonSerializable $message): void
6062
{
6163
$title = (new ReflectionClass($this))->getShortName();
6264
if (is_array($message) || is_object($message)) {

src/Codeception/Lib/Connector/Yii2/FixturesStore.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ class FixturesStore
1111
{
1212
use FixtureTrait;
1313

14-
protected mixed $data;
15-
1614
/**
1715
* Expects fixtures config
1816
*
1917
* FixturesStore constructor.
2018
*/
21-
public function __construct(mixed $data)
19+
public function __construct(protected mixed $data)
2220
{
23-
$this->data = $data;
2421
}
2522

2623
public function fixtures(): mixed
2724
{
2825
return $this->data;
2926
}
3027

28+
/**
29+
* @return array{initDbFixture: array{class: class-string}}
30+
*/
3131
public function globalFixtures(): array
3232
{
3333
return [

src/Codeception/Lib/Connector/Yii2/Logger.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
namespace Codeception\Lib\Connector\Yii2;
66

77
use Codeception\Util\Debug;
8-
use yii\helpers\VarDumper;
98
use yii\base\Exception as YiiException;
9+
use yii\helpers\VarDumper;
1010
use yii\log\Logger as YiiLogger;
1111

1212
class Logger extends YiiLogger
@@ -26,7 +26,7 @@ public function init(): void
2626

2727
/**
2828
* @param string|array|YiiException $message
29-
* @param mixed $level
29+
* @param self::LEVEL_INFO|self::LEVEL_WARNING|self::LEVEL_ERROR $level
3030
* @param mixed $category
3131
*/
3232
public function log($message, $level, $category = 'application'): void

src/Codeception/Lib/Connector/Yii2/TransactionForcer.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@
1515
*/
1616
class TransactionForcer extends ConnectionWatcher
1717
{
18-
private bool $ignoreCollidingDSN;
1918
private array $pdoCache = [];
2019
private array $dsnCache = [];
2120
private array $transactions = [];
2221

23-
public function __construct(bool $ignoreCollidingDSN)
22+
public function __construct(private bool $ignoreCollidingDSN)
2423
{
2524
parent::__construct();
26-
$this->ignoreCollidingDSN = $ignoreCollidingDSN;
2725
}
2826

2927
protected function connectionOpened(Connection $connection): void

src/Codeception/Module/Yii2.php

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Codeception\TestInterface;
1919
use ReflectionClass;
2020
use RuntimeException;
21+
use Symfony\Component\BrowserKit\AbstractBrowser;
2122
use Yii;
2223
use yii\base\Security;
2324
use yii\db\ActiveQueryInterface;
@@ -174,7 +175,6 @@ class Yii2 extends Framework implements ActiveRecord, MultiSession, PartedModule
174175
{
175176
/**
176177
* Application config file must be set.
177-
* @var array
178178
*/
179179
protected array $config = [
180180
'fixturesMethod' => '_fixtures',
@@ -217,9 +217,9 @@ class Yii2 extends Framework implements ActiveRecord, MultiSession, PartedModule
217217

218218
private Logger $yiiLogger;
219219

220-
private function getClient(): ?\Codeception\Lib\Connector\Yii2
220+
private function getClient(): ?Yii2Connector
221221
{
222-
if (isset($this->client) && !($this->client instanceof \Codeception\Lib\Connector\Yii2)) {
222+
if ($this->client instanceof AbstractBrowser && !($this->client instanceof Yii2Connector)) {
223223
throw new RuntimeException('The Yii2 module must be used with the Yii2 browser client');
224224
}
225225
return $this->client ?? null;
@@ -275,20 +275,20 @@ protected function validateConfig(): void
275275
$pathToConfig = codecept_absolute_path($this->config['configFile']);
276276
if (!is_file($pathToConfig)) {
277277
throw new ModuleConfigException(
278-
__CLASS__,
278+
self::class,
279279
"The application config file does not exist: " . $pathToConfig
280280
);
281281
}
282282
$validMethods = implode(", ", Yii2Connector::CLEAN_METHODS);
283283
if (!in_array($this->config['responseCleanMethod'], Yii2Connector::CLEAN_METHODS, true)) {
284284
throw new ModuleConfigException(
285-
__CLASS__,
285+
self::class,
286286
"The response clean method must be one of: " . $validMethods
287287
);
288288
}
289289
if (!in_array($this->config['requestCleanMethod'], Yii2Connector::CLEAN_METHODS, true)) {
290290
throw new ModuleConfigException(
291-
__CLASS__,
291+
self::class,
292292
"The request clean method must be one of: " . $validMethods
293293
);
294294
}
@@ -351,7 +351,7 @@ public function _before(TestInterface $test): void
351351
private function loadFixtures(object $test): void
352352
{
353353
$this->debugSection('Fixtures', 'Loading fixtures');
354-
if (empty($this->loadedFixtures)
354+
if ($this->loadedFixtures === []
355355
&& method_exists($test, $this->_getConfig('fixturesMethod'))
356356
) {
357357
$connectionWatcher = new ConnectionWatcher();
@@ -502,11 +502,10 @@ public function haveFixtures($fixtures): void
502502
* Array of fixture instances
503503
*
504504
* @part fixtures
505-
* @return array
506505
*/
507506
public function grabFixtures()
508507
{
509-
if (!$this->loadedFixtures) {
508+
if ($this->loadedFixtures === []) {
510509
return [];
511510
}
512511

@@ -562,7 +561,6 @@ public function grabFixture($name, $index = null)
562561
* @template T of \yii\db\ActiveRecord
563562
* @param class-string<T> $model
564563
* @param array<string, mixed> $attributes
565-
* @return mixed
566564
* @part orm
567565
*/
568566
public function haveRecord(string $model, $attributes = []): mixed
@@ -713,7 +711,6 @@ public function grabComponent(string $component): null|object
713711
* $I->seeEmailIsSent(3);
714712
* ```
715713
*
716-
* @param int|null $num
717714
* @throws \Codeception\Exception\ModuleException
718715
* @part email
719716
*/
@@ -749,7 +746,6 @@ public function dontSeeEmailIsSent(): void
749746
* ```
750747
*
751748
* @part email
752-
* @return array
753749
* @throws \Codeception\Exception\ModuleException
754750
*/
755751
public function grabSentEmails(): array
@@ -781,8 +777,6 @@ public function grabLastSentEmail(): object
781777

782778
/**
783779
* Returns a list of regex patterns for recognized domain names
784-
*
785-
* @return array
786780
*/
787781
public function getInternalDomains(): array
788782
{
@@ -791,9 +785,9 @@ public function getInternalDomains(): array
791785

792786
private function defineConstants(): void
793787
{
794-
defined('YII_DEBUG') or define('YII_DEBUG', true);
795-
defined('YII_ENV') or define('YII_ENV', 'test');
796-
defined('YII_ENABLE_ERROR_HANDLER') or define('YII_ENABLE_ERROR_HANDLER', false);
788+
defined('YII_DEBUG') || define('YII_DEBUG', true);
789+
defined('YII_ENV') || define('YII_ENV', 'test');
790+
defined('YII_ENABLE_ERROR_HANDLER') || define('YII_ENABLE_ERROR_HANDLER', false);
797791
}
798792

799793
/**

0 commit comments

Comments
 (0)