‪TYPO3CMS  9.5
SendEmailCommandTest.php
Go to the documentation of this file.
1 <?php
2 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 
18 use Symfony\Component\Console\Tester\CommandTester;
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪SendEmailCommandTest extends UnitTestCase
27 {
31  public function ‪executeWillFlushTheQueue()
32  {
33  $realTransport = $this->getMockBuilder(\Swift_Transport::class)->getMock();
34 
35  $spool = $this->getMockBuilder(\Swift_Spool::class)->getMock();
36  $spool
37  ->expects($this->once())
38  ->method('flushQueue')
39  ->with($realTransport)
40  ->will($this->returnValue(5))
41  ;
42  $spoolTransport = new \Swift_Transport_SpoolTransport(new \Swift_Events_SimpleEventDispatcher(), $spool);
43 
44  $mailer = $this->getMockBuilder(Mailer::class)
45  ->disableOriginalConstructor()
46  ->setMethods(['getTransport', 'getRealTransport'])
47  ->getMock();
48 
49  $mailer
50  ->expects($this->any())
51  ->method('getTransport')
52  ->will($this->returnValue($spoolTransport));
53 
54  $mailer
55  ->expects($this->any())
56  ->method('getRealTransport')
57  ->will($this->returnValue($realTransport));
58 
60  $command = $this->getMockBuilder(SendEmailCommand::class)
61  ->setConstructorArgs(['swiftmailer:spool:send'])
62  ->setMethods(['getMailer'])
63  ->getMock();
64 
65  $command
66  ->expects($this->any())
67  ->method('getMailer')
68  ->will($this->returnValue($mailer));
69 
70  $tester = new CommandTester($command);
71  $tester->execute([], []);
72 
73  $this->assertTrue(strpos($tester->getDisplay(), '5 emails sent') > 0);
74  }
75 }
‪TYPO3\CMS\Core\Command\SendEmailCommand
Definition: SendEmailCommand.php:34
‪TYPO3\CMS\Core\Tests\Unit\Command
Definition: SendEmailCommandTest.php:3
‪TYPO3\CMS\Core\Mail\Mailer
Definition: Mailer.php:29
‪TYPO3\CMS\Core\Tests\Unit\Command\SendEmailCommandTest
Definition: SendEmailCommandTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\Command\SendEmailCommandTest\executeWillFlushTheQueue
‪executeWillFlushTheQueue()
Definition: SendEmailCommandTest.php:31