Skip to content

Commit

Permalink
pkp#9899 test mail swap functionality added
Browse files Browse the repository at this point in the history
  • Loading branch information
touhidurabir committed Jun 13, 2024
1 parent 84649f2 commit be70b99
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/PKPTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use PKP\core\Dispatcher;
use PKP\core\Registry;
use PKP\db\DAORegistry;
use Illuminate\Support\Facades\Config as FacadesConfig;

abstract class PKPTestCase extends TestCase
{
Expand Down Expand Up @@ -239,6 +240,21 @@ protected function localeToRegExp(string $translation): string
$escapedPieces = array_map(fn ($piece) => preg_quote($piece, '/'), $pieces);
return '/^' . implode('.*?', $escapedPieces) . '$/u';
}

/**
* Swap the mail driver with something better for test
* Default will be to `log` driver so that no mail would be set
*
* We need to use this as we have override the default mail manager with some custom
* methods (e.g. `compileParams`, ...) which not available to core mail fake test class
* that is `Illuminate\Support\Testing\Fakes\MailFake` which cause test exception.
*/
protected function swapMailDriver(string $driver = 'log'): void
{
$mailConfig = app()->get('config')['mail'];
$mailConfig['default'] = $driver;
FacadesConfig::set('mail', $mailConfig);
}
}

if (!PKP_STRICT_MODE) {
Expand Down

0 comments on commit be70b99

Please sign in to comment.