[TASK] Shorten the extend class in all unit tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Resource / TextExtraction / TextExtractorRegistryTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Resource\TextExtraction;
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 TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorInterface;
18 use TYPO3\CMS\Core\Resource\TextExtraction\TextExtractorRegistry;
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20
21 /**
22 * Test cases for TextExtractorRegistry
23 */
24 class TextExtractorRegistryTest extends UnitTestCase
25 {
26 /**
27 * Initialize a TextExtractorRegistry and mock createTextExtractorInstance()
28 *
29 * @param array $createsTextExtractorInstances
30 * @return \PHPUnit_Framework_MockObject_MockObject|TextExtractorRegistry
31 */
32 protected function getTextExtractorRegistry(array $createsTextExtractorInstances = [])
33 {
34 $textExtractorRegistry = $this->getMockBuilder(TextExtractorRegistry::class)
35 ->setMethods(['createTextExtractorInstance'])
36 ->getMock();
37
38 if (!empty($createsTextExtractorInstances)) {
39 $textExtractorRegistry->expects($this->any())
40 ->method('createTextExtractorInstance')
41 ->will($this->returnValueMap($createsTextExtractorInstances));
42 }
43
44 return $textExtractorRegistry;
45 }
46
47 /**
48 * @test
49 */
50 public function registeredTextExtractorClassCanBeRetrieved()
51 {
52 $textExtractorClass = $this->getUniqueId('myTextExtractor');
53 $textExtractorInstance = $this->getMockBuilder(TextExtractorInterface::class)
54 ->setMockClassName($textExtractorClass)
55 ->getMock();
56
57 $textExtractorRegistry = $this->getTextExtractorRegistry([[$textExtractorClass, $textExtractorInstance]]);
58
59 $textExtractorRegistry->registerTextExtractor($textExtractorClass);
60 $this->assertContains($textExtractorInstance, $textExtractorRegistry->getTextExtractorInstances(), '', false, false);
61 }
62
63 /**
64 * @test
65 */
66 public function registerTextExtractorThrowsExceptionIfClassDoesNotExist()
67 {
68 $this->expectException(\InvalidArgumentException::class);
69 $this->expectExceptionCode(1422906893);
70
71 $textExtractorRegistry = $this->getTextExtractorRegistry();
72 $textExtractorRegistry->registerTextExtractor($this->getUniqueId());
73 }
74
75 /**
76 * @test
77 */
78 public function registerTextExtractorThrowsExceptionIfClassDoesNotImplementRightInterface()
79 {
80 $this->expectException(\InvalidArgumentException::class);
81 $this->expectExceptionCode(1422771427);
82
83 $textExtractorRegistry = $this->getTextExtractorRegistry();
84 $textExtractorRegistry->registerTextExtractor(__CLASS__);
85 }
86 }