From dca7c446877d1e4143db9deb86a499df40af59ef Mon Sep 17 00:00:00 2001 From: Sam Mousa Date: Mon, 24 Feb 2025 10:18:00 +0100 Subject: [PATCH 01/10] feat: allow mails to be intercepted using events --- src/Codeception/Lib/Connector/Yii2.php | 30 ++++++++++++++++++- .../Lib/Connector/Yii2/TestMailer.php | 3 +- src/Codeception/Module/Yii2.php | 12 ++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/Codeception/Lib/Connector/Yii2.php b/src/Codeception/Lib/Connector/Yii2.php index b7df1d5..c6cc874 100644 --- a/src/Codeception/Lib/Connector/Yii2.php +++ b/src/Codeception/Lib/Connector/Yii2.php @@ -18,6 +18,9 @@ use yii\base\ExitException; use yii\base\Security; use yii\base\UserException; +use yii\mail\BaseMailer; +use yii\mail\MailerInterface; +use yii\mail\MailEvent; use yii\mail\MessageInterface; use yii\web\Application; use yii\web\ErrorHandler; @@ -30,6 +33,19 @@ class Yii2 extends Client { use Shared\PhpSuperGlobalsConverter; + const MAIL_METHODS = [ + self::MAIL_CATCH, + self::MAIL_EVENT_AFTER, + self::MAIL_EVENT_BEFORE, + self::MAIL_IGNORE + ]; + + public const MAIL_CATCH = 'catch'; + public const MAIL_EVENT_AFTER = 'after'; + public const MAIL_EVENT_BEFORE = 'before'; + public const MAIL_IGNORE = 'ignore'; + + const CLEAN_METHODS = [ self::CLEAN_RECREATE, self::CLEAN_CLEAR, @@ -64,6 +80,10 @@ class Yii2 extends Client */ public $configFile; + /** + * @var self::MAIL_CATCH|self::MAIL_IGNORE|self::MAIL_AFTER|self::MAIL_BEFORE $mailMethod method for handling mails + */ + public $mailMethod; /** * @var string method for cleaning the response object before each request */ @@ -267,7 +287,15 @@ public function startApp(?\yii\log\Logger $logger = null): void unset($config['container']); } - $config = $this->mockMailer($config); + match ($this->mailMethod) { + self::MAIL_CATCH => $config= $this->mockMailer($config), + self::MAIL_EVENT_AFTER => $config['components']['mailer']['on ' . BaseMailer::EVENT_AFTER_SEND] = fn(MailEvent $event) => $this->emails[] = $event->message, + self::MAIL_EVENT_BEFORE => $config['components']['mailer']['on ' . BaseMailer::EVENT_BEFORE_SEND] = function(MailEvent $event) { + $this->emails[] = $event->message; + return true; + }, + self::MAIL_IGNORE => null// Do nothing + } Yii::$app = Yii::createObject($config); if ($logger instanceof \yii\log\Logger) { diff --git a/src/Codeception/Lib/Connector/Yii2/TestMailer.php b/src/Codeception/Lib/Connector/Yii2/TestMailer.php index 230e15a..69d51f4 100644 --- a/src/Codeception/Lib/Connector/Yii2/TestMailer.php +++ b/src/Codeception/Lib/Connector/Yii2/TestMailer.php @@ -6,10 +6,11 @@ use Closure; use yii\mail\BaseMailer; +use yii\symfonymailer\Message; class TestMailer extends BaseMailer { - public $messageClass = \yii\symfonymailer\Message::class; + public $messageClass = Message::class; public Closure $callback; diff --git a/src/Codeception/Module/Yii2.php b/src/Codeception/Module/Yii2.php index fdd47b8..2b62aef 100644 --- a/src/Codeception/Module/Yii2.php +++ b/src/Codeception/Module/Yii2.php @@ -86,6 +86,11 @@ * changes will get discarded. * * `recreateApplication` - (default: `false`) whether to recreate the whole * application before each request + * * `mailMethod` - (default: `catch`) Method for handling email via the 'mailer' + * component. `ignore` will not do anything with mail, this means mails are not + * inspectable by the test runner, using `before` or `after` will use mailer + * events; making the mails inspectable but also allowing your default mail + * handling to work * * You can use this module by setting params in your `functional.suite.yml`: * @@ -187,6 +192,7 @@ class Yii2 extends Framework implements ActiveRecord, MultiSession, PartedModule 'requestCleanMethod' => Yii2Connector::CLEAN_RECREATE, 'recreateComponents' => [], 'recreateApplication' => false, + 'mailMethod' => Yii2Connector::MAIL_CATCH, 'closeSessionOnRecreateApplication' => true, 'applicationClass' => null, ]; @@ -289,6 +295,12 @@ protected function validateConfig(): void "The response clean method must be one of: " . $validMethods ); } + if (!in_array($this->config['mailMethod'], Yii2Connector::MAIL_METHODS, true)) { + throw new ModuleConfigException( + self::class, + "The mail method must be one of: " . $validMethods + ); + } if (!in_array($this->config['requestCleanMethod'], Yii2Connector::CLEAN_METHODS, true)) { throw new ModuleConfigException( self::class, From 5bcf28ea3bd500e595f37be5d01757d45017f0ff Mon Sep 17 00:00:00 2001 From: Sam Mousa Date: Mon, 24 Feb 2025 10:22:34 +0100 Subject: [PATCH 02/10] chore: add missing ; --- src/Codeception/Lib/Connector/Yii2.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Codeception/Lib/Connector/Yii2.php b/src/Codeception/Lib/Connector/Yii2.php index c6cc874..45001e0 100644 --- a/src/Codeception/Lib/Connector/Yii2.php +++ b/src/Codeception/Lib/Connector/Yii2.php @@ -295,7 +295,7 @@ public function startApp(?\yii\log\Logger $logger = null): void return true; }, self::MAIL_IGNORE => null// Do nothing - } + }; Yii::$app = Yii::createObject($config); if ($logger instanceof \yii\log\Logger) { From 907f28016a667204df7e4da73f9fc00ffd2204d9 Mon Sep 17 00:00:00 2001 From: Sam Mousa Date: Mon, 24 Feb 2025 16:32:21 +0100 Subject: [PATCH 03/10] chore: fix merge mistake --- src/Codeception/Lib/Connector/Yii2.php | 12 ++++++------ src/Codeception/Module/Yii2.php | 3 +-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Codeception/Lib/Connector/Yii2.php b/src/Codeception/Lib/Connector/Yii2.php index d1a6f4a..9616b99 100644 --- a/src/Codeception/Lib/Connector/Yii2.php +++ b/src/Codeception/Lib/Connector/Yii2.php @@ -15,20 +15,16 @@ use Symfony\Component\BrowserKit\CookieJar; use Symfony\Component\BrowserKit\History; use Symfony\Component\BrowserKit\Request as BrowserkitRequest; -use yii\web\Request as YiiRequest; use Symfony\Component\BrowserKit\Response; use Yii; -use yii\base\Component; use yii\base\Event; use yii\base\ExitException; use yii\base\Security; use yii\base\UserException; use yii\mail\BaseMessage; -use yii\mail\MailEvent; use yii\web\Application; -use yii\web\ErrorHandler; use yii\web\IdentityInterface; -use yii\web\Request; +use yii\web\Request as YiiRequest; use yii\web\Response as YiiResponse; use yii\web\User; @@ -308,7 +304,11 @@ public function startApp(?\yii\log\Logger $logger = null): void } $config = $this->mockMailer($config); - Yii::$app = Yii::createObject($config); + $app = Yii::createObject($config); + if (!$app instanceof \yii\base\Application) { + throw new ModuleConfigException($this, "Failed to initialize Yii2 app"); + } + \Yii::$app = $app; if ($logger instanceof \yii\log\Logger) { Yii::setLogger($logger); diff --git a/src/Codeception/Module/Yii2.php b/src/Codeception/Module/Yii2.php index fb6a585..30f6403 100644 --- a/src/Codeception/Module/Yii2.php +++ b/src/Codeception/Module/Yii2.php @@ -22,14 +22,13 @@ use Symfony\Component\BrowserKit\History; use Yii; use yii\base\Security; -use yii\web\Application as WebApplication; use yii\db\ActiveQueryInterface; use yii\db\ActiveRecordInterface; use yii\helpers\Url; use yii\mail\BaseMessage; use yii\mail\MessageInterface; use yii\test\Fixture; -use yii\web\Application; +use yii\web\Application as WebApplication; use yii\web\IdentityInterface; /** From 93c851db96d97942893322ed6f04769f3e22cc7e Mon Sep 17 00:00:00 2001 From: Sam Mousa Date: Mon, 24 Feb 2025 16:58:04 +0100 Subject: [PATCH 04/10] chore: cleanup --- src/Codeception/Lib/Connector/Yii2.php | 53 +++++++++++++++----------- src/Codeception/Module/Yii2.php | 20 +++------- 2 files changed, 36 insertions(+), 37 deletions(-) diff --git a/src/Codeception/Lib/Connector/Yii2.php b/src/Codeception/Lib/Connector/Yii2.php index 9616b99..864a92d 100644 --- a/src/Codeception/Lib/Connector/Yii2.php +++ b/src/Codeception/Lib/Connector/Yii2.php @@ -21,7 +21,9 @@ use yii\base\ExitException; use yii\base\Security; use yii\base\UserException; -use yii\mail\BaseMessage; +use yii\mail\BaseMailer; +use yii\mail\MailEvent; +use yii\mail\MessageInterface; use yii\web\Application; use yii\web\IdentityInterface; use yii\web\Request as YiiRequest; @@ -36,20 +38,21 @@ class Yii2 extends Client { use Shared\PhpSuperGlobalsConverter; - const MAIL_METHODS = [ + + public const array MAIL_METHODS = [ self::MAIL_CATCH, self::MAIL_EVENT_AFTER, self::MAIL_EVENT_BEFORE, self::MAIL_IGNORE ]; - public const MAIL_CATCH = 'catch'; - public const MAIL_EVENT_AFTER = 'after'; - public const MAIL_EVENT_BEFORE = 'before'; - public const MAIL_IGNORE = 'ignore'; + public const string MAIL_CATCH = 'catch'; + public const string MAIL_EVENT_AFTER = 'after'; + public const string MAIL_EVENT_BEFORE = 'before'; + public const string MAIL_IGNORE = 'ignore'; - const CLEAN_METHODS = [ + const array CLEAN_METHODS = [ self::CLEAN_RECREATE, self::CLEAN_CLEAR, self::CLEAN_FORCE_RECREATE, @@ -59,55 +62,55 @@ class Yii2 extends Client * Clean the response object by recreating it. * This might lose behaviors / event handlers / other changes that are done in the application bootstrap phase. */ - const CLEAN_RECREATE = 'recreate'; + const string CLEAN_RECREATE = 'recreate'; /** * Same as recreate but will not warn when behaviors / event handlers are lost. */ - const CLEAN_FORCE_RECREATE = 'force_recreate'; + const string CLEAN_FORCE_RECREATE = 'force_recreate'; /** * Clean the response object by resetting specific properties via its' `clear()` method. * This will keep behaviors / event handlers, but could inadvertently leave some changes intact. * @see \yii\web\Response::clear() */ - const CLEAN_CLEAR = 'clear'; + const string CLEAN_CLEAR = 'clear'; /** * Do not clean the response, instead the test writer will be responsible for manually resetting the response in * between requests during one test */ - const CLEAN_MANUAL = 'manual'; + const string CLEAN_MANUAL = 'manual'; /** * @var string application config file */ - public $configFile; + public string $configFile; /** - * @var self::MAIL_CATCH|self::MAIL_IGNORE|self::MAIL_AFTER|self::MAIL_BEFORE $mailMethod method for handling mails + * @var self::MAIL_CATCH|self::MAIL_IGNORE|self::MAIL_EVENT_AFTER|self::MAIL_EVENT_BEFORE method for handling mails */ - public $mailMethod; + public string $mailMethod; /** * @var string method for cleaning the response object before each request */ - public $responseCleanMethod; + public string $responseCleanMethod; /** * @var string method for cleaning the request object before each request */ - public $requestCleanMethod; + public string $requestCleanMethod; /** * @var string[] List of component names that must be recreated before each request */ - public $recreateComponents = []; + public array $recreateComponents = []; /** * This option is there primarily for backwards compatibility. * It means you cannot make any modification to application state inside your app, since they will get discarded. * @var bool whether to recreate the whole application before each request */ - public $recreateApplication = false; + public bool $recreateApplication = false; /** * @var bool whether to close the session in between requests inside a single test, if recreateApplication is set to true @@ -122,7 +125,7 @@ class Yii2 extends Client /** - * @var list + * @var list */ private array $emails = []; @@ -224,7 +227,7 @@ public function getInternalDomains(): array /** * @internal - * @return list List of sent emails + * @return list List of sent emails */ public function getEmails(): array { @@ -303,7 +306,13 @@ public function startApp(?\yii\log\Logger $logger = null): void unset($config['container']); } - $config = $this->mockMailer($config); + match ($this->mailMethod) { + self::MAIL_CATCH => $config= $this->mockMailer($config), + self::MAIL_EVENT_AFTER => $config['components']['mailer']['on ' . BaseMailer::EVENT_AFTER_SEND] = fn(MailEvent $event) => $this->emails[] = $event->message, + self::MAIL_EVENT_BEFORE => $config['components']['mailer']['on ' . BaseMailer::EVENT_BEFORE_SEND] = fn(MailEvent $event) => $this->emails[] = $event->message, + self::MAIL_IGNORE => null// Do nothing + }; + $app = Yii::createObject($config); if (!$app instanceof \yii\base\Application) { throw new ModuleConfigException($this, "Failed to initialize Yii2 app"); @@ -468,7 +477,7 @@ protected function mockMailer(array $config): array $mailerConfig = [ 'class' => TestMailer::class, - 'callback' => function (BaseMessage $message): void { + 'callback' => function (MessageInterface $message): void { $this->emails[] = $message; } ]; diff --git a/src/Codeception/Module/Yii2.php b/src/Codeception/Module/Yii2.php index 30f6403..cc50c8a 100644 --- a/src/Codeception/Module/Yii2.php +++ b/src/Codeception/Module/Yii2.php @@ -193,24 +193,14 @@ * recreateComponents: list, * recreateApplication: bool, * closeSessionOnRecreateApplication: bool, + * mailMethod: Yii2Connector::MAIL_CATCH|Yii2Connector::MAIL_IGNORE|Yii2Connector::MAIL_EVENT_AFTER|Yii2Connector::MAIL_EVENT_BEFORE, * applicationClass: class-string<\yii\base\Application>|null * } * - * @phpstan-type ValidConfig array{ - * fixturesMethod: string, - * cleanup: bool, - * ignoreCollidingDSN: bool, + * @phpstan-type ValidConfig (ModuleConfig & array{ * transaction: bool|null, - * entryScript: string, - * entryUrl: string, * configFile: string, - * responseCleanMethod: Yii2Connector::CLEAN_CLEAR|Yii2Connector::CLEAN_MANUAL|Yii2Connector::CLEAN_RECREATE, - * requestCleanMethod: Yii2Connector::CLEAN_CLEAR|Yii2Connector::CLEAN_MANUAL|Yii2Connector::CLEAN_RECREATE, - * recreateComponents: list, - * recreateApplication: bool, - * closeSessionOnRecreateApplication: bool, - * applicationClass: class-string<\yii\base\Application>|null - * } + * }) * @phpstan-type SessionBackup array{cookie: array, session: array, headers: array, clientContext: array{ cookieJar: CookieJar, history: History }} * @phpstan-type ClientConfig array{ * configFile: string, @@ -808,7 +798,7 @@ public function dontSeeEmailIsSent(): void * ``` * * @part email - * @return list List of sent emails + * @return list List of sent emails * @throws \Codeception\Exception\ModuleException */ public function grabSentEmails(): array @@ -831,7 +821,7 @@ public function grabSentEmails(): array * ``` * @part email */ - public function grabLastSentEmail(): BaseMessage|null + public function grabLastSentEmail(): MessageInterface|null { $this->seeEmailIsSent(); $messages = $this->grabSentEmails(); From d53611637e9ce5291bd13ea1a5704f60828cd12c Mon Sep 17 00:00:00 2001 From: Sam Mousa Date: Mon, 24 Feb 2025 17:22:11 +0100 Subject: [PATCH 05/10] fix: load mailmethod config --- src/Codeception/Module/Yii2.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Codeception/Module/Yii2.php b/src/Codeception/Module/Yii2.php index cc50c8a..ec05487 100644 --- a/src/Codeception/Module/Yii2.php +++ b/src/Codeception/Module/Yii2.php @@ -368,6 +368,7 @@ private function configureClient(array $settings): void $client->recreateApplication = $settings['recreateApplication']; $client->closeSessionOnRecreateApplication = $settings['closeSessionOnRecreateApplication']; $client->applicationClass = $settings['applicationClass']; + $client->mailMethod = $settings['mailMethod']; $client->resetApplication(); } From ab5ccc555c1907b7d19253a6435433f35bb76fe5 Mon Sep 17 00:00:00 2001 From: Sam Mousa Date: Mon, 24 Feb 2025 17:46:00 +0100 Subject: [PATCH 06/10] fix: phpstan types --- src/Codeception/Module/Yii2.php | 57 ++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/src/Codeception/Module/Yii2.php b/src/Codeception/Module/Yii2.php index ec05487..a4eefb4 100644 --- a/src/Codeception/Module/Yii2.php +++ b/src/Codeception/Module/Yii2.php @@ -179,38 +179,43 @@ * * Maintainer: **samdark** * Stability: **stable** - * + * @phpstan-type ClientConfig array{ + * responseCleanMethod: Yii2Connector::CLEAN_CLEAR|Yii2Connector::CLEAN_MANUAL|Yii2Connector::CLEAN_RECREATE, + * requestCleanMethod: Yii2Connector::CLEAN_CLEAR|Yii2Connector::CLEAN_MANUAL|Yii2Connector::CLEAN_RECREATE, + * mailMethod: Yii2Connector::MAIL_CATCH|Yii2Connector::MAIL_IGNORE|Yii2Connector::MAIL_EVENT_AFTER|Yii2Connector::MAIL_EVENT_BEFORE, + * recreateComponents: list, + * recreateApplication: bool, + * closeSessionOnRecreateApplication: bool, + * applicationClass: class-string<\yii\base\Application>|null, + * configFile: string + * } * @phpstan-type ModuleConfig array{ - * fixturesMethod: string, - * cleanup: bool, - * ignoreCollidingDSN: bool, - * transaction: bool|null, - * entryScript: string, - * entryUrl: string, - * configFile: string|null, - * responseCleanMethod: Yii2Connector::CLEAN_CLEAR|Yii2Connector::CLEAN_MANUAL|Yii2Connector::CLEAN_RECREATE, - * requestCleanMethod: Yii2Connector::CLEAN_CLEAR|Yii2Connector::CLEAN_MANUAL|Yii2Connector::CLEAN_RECREATE, - * recreateComponents: list, - * recreateApplication: bool, - * closeSessionOnRecreateApplication: bool, - * mailMethod: Yii2Connector::MAIL_CATCH|Yii2Connector::MAIL_IGNORE|Yii2Connector::MAIL_EVENT_AFTER|Yii2Connector::MAIL_EVENT_BEFORE, - * applicationClass: class-string<\yii\base\Application>|null + * configFile: string|null, + * fixturesMethod: string, + * cleanup: bool, + * ignoreCollidingDSN: bool, + * transaction: bool|null, + * entryScript: string, + * entryUrl: string, + * responseCleanMethod: Yii2Connector::CLEAN_CLEAR|Yii2Connector::CLEAN_MANUAL|Yii2Connector::CLEAN_RECREATE, + * requestCleanMethod: Yii2Connector::CLEAN_CLEAR|Yii2Connector::CLEAN_MANUAL|Yii2Connector::CLEAN_RECREATE, + * mailMethod: Yii2Connector::MAIL_CATCH|Yii2Connector::MAIL_IGNORE|Yii2Connector::MAIL_EVENT_AFTER|Yii2Connector::MAIL_EVENT_BEFORE, + * recreateComponents: list, + * recreateApplication: bool, + * closeSessionOnRecreateApplication: bool, + * applicationClass: class-string<\yii\base\Application>|null * } * * @phpstan-type ValidConfig (ModuleConfig & array{ * transaction: bool|null, - * configFile: string, + * configFile: string * }) - * @phpstan-type SessionBackup array{cookie: array, session: array, headers: array, clientContext: array{ cookieJar: CookieJar, history: History }} - * @phpstan-type ClientConfig array{ - * configFile: string, - * responseCleanMethod: Yii2Connector::CLEAN_CLEAR|Yii2Connector::CLEAN_MANUAL|Yii2Connector::CLEAN_RECREATE, - * requestCleanMethod: Yii2Connector::CLEAN_CLEAR|Yii2Connector::CLEAN_MANUAL|Yii2Connector::CLEAN_RECREATE, - * recreateComponents: list, - * recreateApplication: bool, - * closeSessionOnRecreateApplication: bool, - * applicationClass: class-string<\yii\base\Application>|null - * } + * @phpstan-type SessionBackup array{ + * cookie: array, + * session: array, + * headers: array, + * clientContext: array{ cookieJar: CookieJar, history: History } + * } */ class Yii2 extends Framework implements ActiveRecord, MultiSession, PartedModule { From 7adc7f7bda798139818853569c9b1d3fd3d5d9cf Mon Sep 17 00:00:00 2001 From: Sam Mousa Date: Wed, 26 Feb 2025 15:08:16 +0100 Subject: [PATCH 07/10] fix: dont add mails that were not sent --- src/Codeception/Lib/Connector/Yii2.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Codeception/Lib/Connector/Yii2.php b/src/Codeception/Lib/Connector/Yii2.php index 864a92d..97c9a57 100644 --- a/src/Codeception/Lib/Connector/Yii2.php +++ b/src/Codeception/Lib/Connector/Yii2.php @@ -308,7 +308,11 @@ public function startApp(?\yii\log\Logger $logger = null): void match ($this->mailMethod) { self::MAIL_CATCH => $config= $this->mockMailer($config), - self::MAIL_EVENT_AFTER => $config['components']['mailer']['on ' . BaseMailer::EVENT_AFTER_SEND] = fn(MailEvent $event) => $this->emails[] = $event->message, + self::MAIL_EVENT_AFTER => $config['components']['mailer']['on ' . BaseMailer::EVENT_AFTER_SEND] = function(MailEvent $event): void { + if ($event->isSuccessful) { + $this->emails[] = $event->message; + } + }, self::MAIL_EVENT_BEFORE => $config['components']['mailer']['on ' . BaseMailer::EVENT_BEFORE_SEND] = fn(MailEvent $event) => $this->emails[] = $event->message, self::MAIL_IGNORE => null// Do nothing }; From d5eb9a5babac17f58e3ec09bf7213ba6d098e82f Mon Sep 17 00:00:00 2001 From: Sam Mousa Date: Wed, 26 Feb 2025 15:49:55 +0100 Subject: [PATCH 08/10] chore(cs): fix phpstan types --- src/Codeception/Module/Yii2.php | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/src/Codeception/Module/Yii2.php b/src/Codeception/Module/Yii2.php index 8ed3ab2..a85ec08 100644 --- a/src/Codeception/Module/Yii2.php +++ b/src/Codeception/Module/Yii2.php @@ -175,16 +175,7 @@ * * Maintainer: **samdark** * Stability: **stable** - * @phpstan-type ClientConfig array{ - * responseCleanMethod: Yii2Connector::CLEAN_CLEAR|Yii2Connector::CLEAN_MANUAL|Yii2Connector::CLEAN_RECREATE, - * requestCleanMethod: Yii2Connector::CLEAN_CLEAR|Yii2Connector::CLEAN_MANUAL|Yii2Connector::CLEAN_RECREATE, - * mailMethod: Yii2Connector::MAIL_CATCH|Yii2Connector::MAIL_IGNORE|Yii2Connector::MAIL_EVENT_AFTER|Yii2Connector::MAIL_EVENT_BEFORE, - * recreateComponents: list, - * recreateApplication: bool, - * closeSessionOnRecreateApplication: bool, - * applicationClass: class-string<\yii\base\Application>|null, - * configFile: string - * } + * * @phpstan-type ModuleConfig array{ * configFile: string|null, * fixturesMethod: string, @@ -193,7 +184,6 @@ * transaction: bool|null, * entryScript: string, * entryUrl: string, - * configFile: string, * responseCleanMethod: Yii2Connector::CLEAN_CLEAR|Yii2Connector::CLEAN_MANUAL|Yii2Connector::CLEAN_RECREATE, * requestCleanMethod: Yii2Connector::CLEAN_CLEAR|Yii2Connector::CLEAN_MANUAL|Yii2Connector::CLEAN_RECREATE, * mailMethod: Yii2Connector::MAIL_CATCH|Yii2Connector::MAIL_IGNORE|Yii2Connector::MAIL_EVENT_AFTER|Yii2Connector::MAIL_EVENT_BEFORE, @@ -202,6 +192,7 @@ * closeSessionOnRecreateApplication: bool, * applicationClass: class-string<\yii\base\Application>|null * } + * * @phpstan-type ClientConfig array{ * configFile: string, * responseCleanMethod: Yii2Connector::CLEAN_CLEAR|Yii2Connector::CLEAN_MANUAL|Yii2Connector::CLEAN_RECREATE, @@ -214,15 +205,9 @@ * } * * @phpstan-type ValidConfig (ModuleConfig & array{ - * transaction: bool|null, - * configFile: string - * }) - * @phpstan-type SessionBackup array{ - * cookie: array, - * session: array, - * headers: array, - * clientContext: array{ cookieJar: CookieJar, history: History } - * } + * transaction: bool|null, +* configFile: string +* }) */ final class Yii2 extends Framework implements ActiveRecord, PartedModule { From d853a393d1368a32cac099e51da7e224d5200d22 Mon Sep 17 00:00:00 2001 From: Sam Mousa Date: Wed, 26 Feb 2025 15:51:44 +0100 Subject: [PATCH 09/10] chore(cs): fix cs --- src/Codeception/Module/Yii2.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Codeception/Module/Yii2.php b/src/Codeception/Module/Yii2.php index a85ec08..4abfb65 100644 --- a/src/Codeception/Module/Yii2.php +++ b/src/Codeception/Module/Yii2.php @@ -206,8 +206,8 @@ * * @phpstan-type ValidConfig (ModuleConfig & array{ * transaction: bool|null, -* configFile: string -* }) + * configFile: string + * }) */ final class Yii2 extends Framework implements ActiveRecord, PartedModule { From 602a67cf56e75fe3d95e9cadc351dada90a11d1d Mon Sep 17 00:00:00 2001 From: Sam Mousa Date: Wed, 26 Feb 2025 15:54:31 +0100 Subject: [PATCH 10/10] chore(sa): regenerate baseline --- phpstan-baseline.neon | 60 ------------------------------------------- 1 file changed, 60 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index ce4877d..7e2667d 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1092,12 +1092,6 @@ parameters: count: 1 path: tests/_support/FunctionalTester.php - - - message: '#^Method tests\\FunctionalTester\:\:createAndSetCsrfCookie\(\) should return array\ but returns mixed\.$#' - identifier: return.type - count: 1 - path: tests/_support/FunctionalTester.php - - message: '#^Method tests\\FunctionalTester\:\:dontSee\(\) has parameter \$selector with no value type specified in iterable type array\.$#' identifier: missingType.iterableValue @@ -1194,12 +1188,6 @@ parameters: count: 1 path: tests/_support/FunctionalTester.php - - - message: '#^Method tests\\FunctionalTester\:\:getInternalDomains\(\) should return non\-empty\-list\ but returns mixed\.$#' - identifier: return.type - count: 1 - path: tests/_support/FunctionalTester.php - - message: '#^Method tests\\FunctionalTester\:\:grabAttributeFrom\(\) has parameter \$cssOrXpath with no type specified\.$#' identifier: missingType.parameter @@ -1212,48 +1200,18 @@ parameters: count: 1 path: tests/_support/FunctionalTester.php - - - message: '#^Method tests\\FunctionalTester\:\:grabFixture\(\) should return yii\\db\\ActiveRecord\|yii\\test\\Fixture\|null but returns mixed\.$#' - identifier: return.type - count: 1 - path: tests/_support/FunctionalTester.php - - message: '#^Method tests\\FunctionalTester\:\:grabFixtures\(\) has invalid return type tests\\_generated\\Fixture\.$#' identifier: class.notFound count: 1 path: tests/_support/FunctionalTester.php - - - message: '#^Method tests\\FunctionalTester\:\:grabFixtures\(\) should return array\ but returns mixed\.$#' - identifier: return.type - count: 1 - path: tests/_support/FunctionalTester.php - - - - message: '#^Method tests\\FunctionalTester\:\:grabLastSentEmail\(\) should return yii\\mail\\BaseMessage\|null but returns mixed\.$#' - identifier: return.type - count: 1 - path: tests/_support/FunctionalTester.php - - message: '#^Method tests\\FunctionalTester\:\:grabMultiple\(\) has parameter \$cssOrXpath with no type specified\.$#' identifier: missingType.parameter count: 1 path: tests/_support/FunctionalTester.php - - - message: '#^Method tests\\FunctionalTester\:\:grabMultiple\(\) should return array\ but returns mixed\.$#' - identifier: return.type - count: 1 - path: tests/_support/FunctionalTester.php - - - - message: '#^Method tests\\FunctionalTester\:\:grabPageSource\(\) should return string but returns mixed\.$#' - identifier: return.type - count: 1 - path: tests/_support/FunctionalTester.php - - message: '#^Method tests\\FunctionalTester\:\:grabRecord\(\) has invalid return type tests\\_generated\\ActiveRecordInterface\.$#' identifier: class.notFound @@ -1266,30 +1224,12 @@ parameters: count: 1 path: tests/_support/FunctionalTester.php - - - message: '#^Method tests\\FunctionalTester\:\:grabRecord\(\) should return array\|yii\\db\\ActiveRecordInterface\|null but returns mixed\.$#' - identifier: return.type - count: 1 - path: tests/_support/FunctionalTester.php - - - - message: '#^Method tests\\FunctionalTester\:\:grabSentEmails\(\) has invalid return type tests\\_generated\\BaseMessage\.$#' - identifier: class.notFound - count: 1 - path: tests/_support/FunctionalTester.php - - message: '#^Method tests\\FunctionalTester\:\:grabSentEmails\(\) has invalid return type tests\\_generated\\MessageInterface\.$#' identifier: class.notFound count: 1 path: tests/_support/FunctionalTester.php - - - message: '#^Method tests\\FunctionalTester\:\:grabSentEmails\(\) should return list\ but returns mixed\.$#' - identifier: return.type - count: 1 - path: tests/_support/FunctionalTester.php - - message: '#^Method tests\\FunctionalTester\:\:grabTextFrom\(\) has parameter \$cssOrXPathOrRegex with no type specified\.$#' identifier: missingType.parameter