‪TYPO3CMS  ‪main
TextExtractorRegistryTest.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;
21 use PHPUnit\Framework\MockObject\MockObject;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
30 final class ‪TextExtractorRegistryTest extends UnitTestCase
31 {
35  protected function ‪getTextExtractorRegistry(array $createsTextExtractorInstances = []): ‪TextExtractorRegistry&MockObject
36  {
37  ‪$textExtractorRegistry = $this->getMockBuilder(TextExtractorRegistry::class)
38  ->onlyMethods(['createTextExtractorInstance'])
39  ->getMock();
40 
41  if (!empty($createsTextExtractorInstances)) {
43  ->method('createTextExtractorInstance')
44  ->willReturnMap($createsTextExtractorInstances);
45  }
46 
48  }
49 
50  #[Test]
52  {
53  $textExtractorClass = ‪StringUtility::getUniqueId('myTextExtractor');
54  $textExtractorInstance = $this->getMockBuilder(TextExtractorInterface::class)
55  ->setMockClassName($textExtractorClass)
56  ->getMock();
57 
58  ‪$textExtractorRegistry = $this->‪getTextExtractorRegistry([[$textExtractorClass, $textExtractorInstance]]);
59 
60  ‪$textExtractorRegistry->registerTextExtractor($textExtractorClass);
61  self::assertContains($textExtractorInstance, ‪$textExtractorRegistry->getTextExtractorInstances());
62  }
63 
64  #[Test]
66  {
67  $this->expectException(\InvalidArgumentException::class);
68  $this->expectExceptionCode(1422906893);
69 
72  }
73 
74  #[Test]
76  {
77  $this->expectException(\InvalidArgumentException::class);
78  $this->expectExceptionCode(1422771427);
79 
81  ‪$textExtractorRegistry->registerTextExtractor(__CLASS__);
82  }
83 }
‪TYPO3\CMS\Core\Tests\Unit\Resource\TextExtraction\TextExtractorRegistryTest\registerTextExtractorThrowsExceptionIfClassDoesNotImplementRightInterface
‪registerTextExtractorThrowsExceptionIfClassDoesNotImplementRightInterface()
Definition: TextExtractorRegistryTest.php:75
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorInterface
Definition: TextExtractorInterface.php:24
‪TYPO3\CMS\Core\Tests\Unit\Resource\TextExtraction\TextExtractorRegistryTest
Definition: TextExtractorRegistryTest.php:31
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry
Definition: TextExtractorRegistry.php:26
‪TYPO3\CMS\Core\Tests\Unit\Resource\TextExtraction\TextExtractorRegistryTest\registeredTextExtractorClassCanBeRetrieved
‪registeredTextExtractorClassCanBeRetrieved()
Definition: TextExtractorRegistryTest.php:51
‪$textExtractorRegistry
‪$textExtractorRegistry
Definition: ext_localconf.php:51
‪TYPO3\CMS\Core\Tests\Unit\Resource\TextExtraction
Definition: PlainTextExtractorTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Resource\TextExtraction\TextExtractorRegistryTest\getTextExtractorRegistry
‪getTextExtractorRegistry(array $createsTextExtractorInstances=[])
Definition: TextExtractorRegistryTest.php:35
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:24
‪TYPO3\CMS\Core\Tests\Unit\Resource\TextExtraction\TextExtractorRegistryTest\registerTextExtractorThrowsExceptionIfClassDoesNotExist
‪registerTextExtractorThrowsExceptionIfClassDoesNotExist()
Definition: TextExtractorRegistryTest.php:65
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static getUniqueId(string $prefix='')
Definition: StringUtility.php:57