‪TYPO3CMS  ‪main
FileSpoolTest.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 PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
22 use Symfony\Component\Mailer\Envelope;
23 use Symfony\Component\Mailer\Transport\NullTransport;
24 use Symfony\Component\Mime\Address;
25 use Symfony\Component\Mime\RawMessage;
28 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
29 
30 final class ‪FileSpoolTest extends UnitTestCase
31 {
32  protected bool ‪$resetSingletonInstances = true;
33 
35 
36  protected function ‪setUp(): void
37  {
38  parent::setUp();
39  $this->subject = new ‪FileSpool(‪Environment::getVarPath() . '/spool/');
40  $this->subject->setMessageLimit(10);
41  $this->subject->setTimeLimit(1);
42  }
43 
44  #[DataProvider('messageCountProvider')]
45  #[Test]
46  public function ‪spoolsMessagesCorrectly(int $count): void
47  {
48  for ($i = 1; $i <= $count; $i++) {
49  $this->subject->send(
50  new RawMessage('test message ' . $i),
51  new Envelope(new Address('sender@example.com'), [new Address('recipient@example.com')])
52  );
53  }
54 
55  self::assertEquals($count, $this->subject->flushQueue(new NullTransport()));
56  }
57 
63  public static function ‪messageCountProvider(): array
64  {
65  return [
66  'spools 0 messages' => [0],
67  'spools 1 message' => [1],
68  'spools 2 messages' => [2],
69  ];
70  }
71 }
‪TYPO3\CMS\Core\Tests\Unit\Mail\FileSpoolTest\messageCountProvider
‪static array messageCountProvider()
Definition: FileSpoolTest.php:63
‪TYPO3\CMS\Core\Tests\Unit\Mail
‪TYPO3\CMS\Core\Core\Environment\getVarPath
‪static getVarPath()
Definition: Environment.php:197
‪TYPO3\CMS\Core\Tests\Unit\Mail\FileSpoolTest
Definition: FileSpoolTest.php:31
‪TYPO3\CMS\Core\Mail\FileSpool
Definition: FileSpool.php:39
‪TYPO3\CMS\Core\Tests\Unit\Mail\FileSpoolTest\spoolsMessagesCorrectly
‪spoolsMessagesCorrectly(int $count)
Definition: FileSpoolTest.php:46
‪TYPO3\CMS\Core\Tests\Unit\Mail\FileSpoolTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: FileSpoolTest.php:32
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Core\Tests\Unit\Mail\FileSpoolTest\setUp
‪setUp()
Definition: FileSpoolTest.php:36
‪TYPO3\CMS\Core\Tests\Unit\Mail\FileSpoolTest\$subject
‪FileSpool $subject
Definition: FileSpoolTest.php:34