[FEATURE] Integrate Swift Mailer's spool transport
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Command / SendEmailCommandTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Functional\Command;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use Symfony\Component\Console\Tester\CommandTester;
18 use TYPO3\CMS\Core\Command\SendEmailCommand;
19
20 /**
21 * Testcase for the TYPO3\CMS\Core\Command\SendEmailCommand class.
22 */
23 class SendEmailCommandTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
24 {
25 /**
26 * @test
27 */
28 public function executeWillFlushTheQueue()
29 {
30 $realTransport = $this->getMockBuilder(\Swift_Transport::class)->getMock();
31
32 $spool = $this->getMockBuilder(\Swift_Spool::class)->getMock();
33 $spool
34 ->expects($this->once())
35 ->method('flushQueue')
36 ->with($realTransport)
37 ->will($this->returnValue(5))
38 ;
39 $spoolTransport = new \Swift_Transport_SpoolTransport(new \Swift_Events_SimpleEventDispatcher(), $spool);
40
41 $mailer = $this->getMockBuilder(\TYPO3\CMS\Core\Mail\Mailer::class)
42 ->disableOriginalConstructor()
43 ->setMethods(['getTransport', 'getRealTransport'])
44 ->getMock();
45
46 $mailer
47 ->expects($this->any())
48 ->method('getTransport')
49 ->will($this->returnValue($spoolTransport));
50
51 $mailer
52 ->expects($this->any())
53 ->method('getRealTransport')
54 ->will($this->returnValue($realTransport));
55
56 $command = $this->getMockBuilder(SendEmailCommand::class)
57 ->setConstructorArgs(['swiftmailer:spool:send'])
58 ->setMethods(['getMailer'])
59 ->getMock();
60
61 $command
62 ->expects($this->any())
63 ->method('getMailer')
64 ->will($this->returnValue($mailer));
65
66 $tester = new CommandTester($command);
67 $tester->execute([], []);
68
69 $this->assertStringEndsWith("5 emails sent\n", $tester->getDisplay());
70 }
71 }