|
13 | 13 | use Yii;
|
14 | 14 | use yii\base\ExitException;
|
15 | 15 | use yii\base\Security;
|
| 16 | +use yii\mail\MessageInterface; |
16 | 17 | use yii\web\Application;
|
17 | 18 | use yii\web\ErrorHandler;
|
18 | 19 | use yii\web\HttpException;
|
@@ -79,6 +80,8 @@ class Yii2 extends Client
|
79 | 80 | */
|
80 | 81 | public $recreateApplication = false;
|
81 | 82 |
|
| 83 | + |
| 84 | + private $emails = []; |
82 | 85 | /**
|
83 | 86 | * @return \yii\web\Application
|
84 | 87 | */
|
@@ -179,16 +182,7 @@ public function getInternalDomains()
|
179 | 182 | */
|
180 | 183 | public function getEmails()
|
181 | 184 | {
|
182 |
| - $app = $this->getApplication(); |
183 |
| - if ($app->has('mailer', true)) { |
184 |
| - $mailer = $app->get('mailer'); |
185 |
| - if ($mailer instanceof TestMailer) { |
186 |
| - return $app->get('mailer')->getSentMessages(); |
187 |
| - } else { |
188 |
| - throw new ConfigurationException("Mailer module is not mocked, can't test emails"); |
189 |
| - } |
190 |
| - } |
191 |
| - return []; |
| 185 | + return $this->emails; |
192 | 186 | }
|
193 | 187 |
|
194 | 188 | public function getComponent($name)
|
@@ -257,7 +251,6 @@ public function startApp()
|
257 | 251 | $config = $this->mockMailer($config);
|
258 | 252 | /** @var \yii\web\Application $app */
|
259 | 253 | Yii::$app = Yii::createObject($config);
|
260 |
| - |
261 | 254 | Yii::setLogger(new Logger());
|
262 | 255 | }
|
263 | 256 |
|
@@ -417,7 +410,10 @@ protected function mockMailer(array $config)
|
417 | 410 | ];
|
418 | 411 |
|
419 | 412 | $mailerConfig = [
|
420 |
| - 'class' => 'Codeception\Lib\Connector\Yii2\TestMailer', |
| 413 | + 'class' => TestMailer::class, |
| 414 | + 'callback' => function (MessageInterface $message) { |
| 415 | + $this->emails[] = $message; |
| 416 | + } |
421 | 417 | ];
|
422 | 418 |
|
423 | 419 | if (isset($config['components']['mailer']) && is_array($config['components']['mailer'])) {
|
|
0 commit comments