‪TYPO3CMS  11.5
SendEmailCommandTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Prophecy\Argument;
21 use Prophecy\PhpUnit\ProphecyTrait;
22 use Symfony\Component\Console\Tester\CommandTester;
23 use Symfony\Component\Mailer\Transport\TransportInterface;
27 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
28 
32 class ‪SendEmailCommandTest extends UnitTestCase
33 {
34  use ProphecyTrait;
35 
39  public function ‪executeWillFlushTheQueue(): void
40  {
41  $delayedTransportProphecy = $this->prophesize(DelayedTransportInterface::class);
42  $delayedTransportProphecy->flushQueue(Argument::any())->willReturn(5);
43  $realTransportProphecy = $this->prophesize(TransportInterface::class);
44 
45  $mailer = $this->getMockBuilder(Mailer::class)
46  ->disableOriginalConstructor()
47  ->onlyMethods(['getTransport', 'getRealTransport'])
48  ->getMock();
49 
50  $mailer
51  ->method('getTransport')
52  ->willReturn($delayedTransportProphecy->reveal());
53 
54  $mailer
55  ->method('getRealTransport')
56  ->willReturn($realTransportProphecy->reveal());
57 
58  $command = $this->getMockBuilder(SendEmailCommand::class)
59  ->setConstructorArgs(['mailer:spool:send'])
60  ->onlyMethods(['getMailer'])
61  ->getMock();
62 
63  $command
64  ->method('getMailer')
65  ->willReturn($mailer);
66 
67  $tester = new CommandTester($command);
68  $tester->execute([], []);
69 
70  self::assertTrue(strpos($tester->getDisplay(), '5 emails sent') > 0);
71  }
72 }
‪TYPO3\CMS\Core\Command\SendEmailCommand
Definition: SendEmailCommand.php:38
‪TYPO3\CMS\Core\Tests\Unit\Command
Definition: SendEmailCommandTest.php:18
‪TYPO3\CMS\Core\Mail\Mailer
Definition: Mailer.php:38
‪TYPO3\CMS\Core\Mail\DelayedTransportInterface
Definition: DelayedTransportInterface.php:26
‪TYPO3\CMS\Core\Tests\Unit\Command\SendEmailCommandTest
Definition: SendEmailCommandTest.php:33
‪TYPO3\CMS\Core\Tests\Unit\Command\SendEmailCommandTest\executeWillFlushTheQueue
‪executeWillFlushTheQueue()
Definition: SendEmailCommandTest.php:38