‪TYPO3CMS  ‪main
ReactionRegistryTest.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\Test;
24 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
25 
26 final class ‪ReactionRegistryTest extends FunctionalTestCase
27 {
28  protected bool ‪$resetSingletonInstances = true;
29 
30  protected array ‪$coreExtensionsToLoad = ['reactions'];
31 
33 
34  protected function ‪setUp(): void
35  {
36  parent::setUp();
37  $reactions = $this->‪buildReactionMock();
38  $this->subject = new ‪ReactionRegistry($reactions);
39  }
40 
41  #[Test]
42  public function ‪getAvailableReactionTypes(): void
43  {
44  $types = iterator_to_array($this->subject->getAvailableReactionTypes()->getIterator());
45  self::assertInstanceOf(CreateRecordReaction::class, reset($types));
46  self::assertCount(1, $types);
47  }
48 
49  #[Test]
50  public function ‪getReactionByType(): void
51  {
52  self::assertInstanceOf(CreateRecordReaction::class, $this->subject->getReactionByType(‪CreateRecordReaction::getType()));
53  self::assertNull($this->subject->getReactionByType('invalid'));
54  }
55 
56  protected function ‪buildReactionMock(): \IteratorAggregate
57  {
58  $class = new class () implements \IteratorAggregate {
59  public function getIterator(): \Traversable
60  {
61  return new \ArrayIterator([‪CreateRecordReaction::getType() => GeneralUtility::makeInstance(CreateRecordReaction::class)]);
62  }
63  };
64 
65  return new $class();
66  }
67 }
‪TYPO3\CMS\Reactions\Reaction\CreateRecordReaction\getType
‪static getType()
Definition: CreateRecordReaction.php:45
‪TYPO3\CMS\Reactions\Tests\Functional\ReactionRegistryTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: ReactionRegistryTest.php:30
‪TYPO3\CMS\Reactions\Tests\Functional\ReactionRegistryTest\setUp
‪setUp()
Definition: ReactionRegistryTest.php:34
‪TYPO3\CMS\Reactions\Tests\Functional\ReactionRegistryTest\getReactionByType
‪getReactionByType()
Definition: ReactionRegistryTest.php:50
‪TYPO3\CMS\Reactions\Tests\Functional\ReactionRegistryTest
Definition: ReactionRegistryTest.php:27
‪TYPO3\CMS\Reactions\Tests\Functional\ReactionRegistryTest\$subject
‪ReactionRegistry $subject
Definition: ReactionRegistryTest.php:32
‪TYPO3\CMS\Reactions\Tests\Functional\ReactionRegistryTest\getAvailableReactionTypes
‪getAvailableReactionTypes()
Definition: ReactionRegistryTest.php:42
‪TYPO3\CMS\Reactions\Tests\Functional\ReactionRegistryTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: ReactionRegistryTest.php:28
‪TYPO3\CMS\Reactions\ReactionRegistry
Definition: ReactionRegistry.php:28
‪TYPO3\CMS\Reactions\Reaction\CreateRecordReaction
Definition: CreateRecordReaction.php:39
‪TYPO3\CMS\Reactions\Tests\Functional\ReactionRegistryTest\buildReactionMock
‪buildReactionMock()
Definition: ReactionRegistryTest.php:56
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Reactions\Tests\Functional