‪TYPO3CMS  11.5
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\MockObject\MockObject;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪TextExtractorRegistryTest extends UnitTestCase
30 {
37  protected function ‪getTextExtractorRegistry(array $createsTextExtractorInstances = [])
38  {
39  ‪$textExtractorRegistry = $this->getMockBuilder(TextExtractorRegistry::class)
40  ->onlyMethods(['createTextExtractorInstance'])
41  ->getMock();
42 
43  if (!empty($createsTextExtractorInstances)) {
45  ->method('createTextExtractorInstance')
46  ->willReturnMap($createsTextExtractorInstances);
47  }
48 
50  }
51 
56  {
57  $textExtractorClass = ‪StringUtility::getUniqueId('myTextExtractor');
58  $textExtractorInstance = $this->getMockBuilder(TextExtractorInterface::class)
59  ->setMockClassName($textExtractorClass)
60  ->getMock();
61 
62  ‪$textExtractorRegistry = $this->‪getTextExtractorRegistry([[$textExtractorClass, $textExtractorInstance]]);
63 
64  ‪$textExtractorRegistry->registerTextExtractor($textExtractorClass);
65  self::assertContains($textExtractorInstance, ‪$textExtractorRegistry->getTextExtractorInstances());
66  }
67 
72  {
73  $this->expectException(\InvalidArgumentException::class);
74  $this->expectExceptionCode(1422906893);
75 
78  }
79 
84  {
85  $this->expectException(\InvalidArgumentException::class);
86  $this->expectExceptionCode(1422771427);
87 
89  ‪$textExtractorRegistry->registerTextExtractor(__CLASS__);
90  }
91 }
‪TYPO3\CMS\Core\Tests\Unit\Resource\TextExtraction\TextExtractorRegistryTest\registerTextExtractorThrowsExceptionIfClassDoesNotImplementRightInterface
‪registerTextExtractorThrowsExceptionIfClassDoesNotImplementRightInterface()
Definition: TextExtractorRegistryTest.php:83
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorInterface
Definition: TextExtractorInterface.php:24
‪TYPO3\CMS\Core\Tests\Unit\Resource\TextExtraction\TextExtractorRegistryTest
Definition: TextExtractorRegistryTest.php:30
‪TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry
Definition: TextExtractorRegistry.php:26
‪TYPO3\CMS\Core\Tests\Unit\Resource\TextExtraction\TextExtractorRegistryTest\registeredTextExtractorClassCanBeRetrieved
‪registeredTextExtractorClassCanBeRetrieved()
Definition: TextExtractorRegistryTest.php:55
‪TYPO3\CMS\Core\Tests\Unit\Resource\TextExtraction\TextExtractorRegistryTest\getTextExtractorRegistry
‪MockObject TextExtractorRegistry getTextExtractorRegistry(array $createsTextExtractorInstances=[])
Definition: TextExtractorRegistryTest.php:37
‪$textExtractorRegistry
‪$textExtractorRegistry
Definition: ext_localconf.php:55
‪TYPO3\CMS\Core\Tests\Unit\Resource\TextExtraction
Definition: PlainTextExtractorTest.php:18
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static string getUniqueId($prefix='')
Definition: StringUtility.php:128
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:22
‪TYPO3\CMS\Core\Tests\Unit\Resource\TextExtraction\TextExtractorRegistryTest\registerTextExtractorThrowsExceptionIfClassDoesNotExist
‪registerTextExtractorThrowsExceptionIfClassDoesNotExist()
Definition: TextExtractorRegistryTest.php:71