‪TYPO3CMS  10.4
ExtractorRegistryTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21 
25 class ‪ExtractorRegistryTest extends UnitTestCase
26 {
31  {
32  $extractorClass = 'a9f4d5e4ebb4b03547a2a6094e1170ac';
33  $extractorObject = $this->getMockBuilder(ExtractorInterface::class)
34  ->setMockClassName($extractorClass)
35  ->getMock();
36 
37  ‪$extractorRegistry = $this->‪getMockExtractorRegistry([[$extractorClass, $extractorObject]]);
38 
39  ‪$extractorRegistry->registerExtractionService($extractorClass);
40  self::assertContains($extractorObject, ‪$extractorRegistry->getExtractors());
41  }
42 
47  {
48  $this->expectException(\InvalidArgumentException::class);
49  $this->expectExceptionCode(1422705270);
50 
51  $className = 'e1f9aa4e1cd3aa7ff05dcdccb117156a';
53  ‪$extractorRegistry->registerExtractionService($className);
54  }
55 
60  {
61  $this->expectException(\InvalidArgumentException::class);
62  $this->expectExceptionCode(1422705271);
63 
64  $className = __CLASS__;
66  ‪$extractorRegistry->registerExtractionService($className);
67  }
68 
73  {
74  $extractorClass1 = 'db76010e5c24658c35ea1605cce2391d';
75  $extractorObject1 = $this->getMockBuilder(ExtractorInterface::class)
76  ->setMockClassName($extractorClass1)
77  ->getMock();
78  $extractorObject1->expects(self::any())->method('getPriority')->willReturn(1);
79 
80  $extractorClass2 = 'ad9195e2487eea33c8a2abd5cf33cba4';
81  $extractorObject2 = $this->getMockBuilder(ExtractorInterface::class)
82  ->setMockClassName($extractorClass2)
83  ->getMock();
84  $extractorObject2->expects(self::any())->method('getPriority')->willReturn(10);
85 
86  $extractorClass3 = 'cef9aa4e1cd3aa7ff05dcdccb117156a';
87  $extractorObject3 = $this->getMockBuilder(ExtractorInterface::class)
88  ->setMockClassName($extractorClass3)
89  ->getMock();
90  $extractorObject3->expects(self::any())->method('getPriority')->willReturn(2);
91 
92  $createdExtractorInstances = [
93  [$extractorClass1, $extractorObject1],
94  [$extractorClass2, $extractorObject2],
95  [$extractorClass3, $extractorObject3],
96  ];
97 
98  ‪$extractorRegistry = $this->‪getMockExtractorRegistry($createdExtractorInstances);
99  ‪$extractorRegistry->registerExtractionService($extractorClass1);
100  ‪$extractorRegistry->registerExtractionService($extractorClass2);
101  ‪$extractorRegistry->registerExtractionService($extractorClass3);
102 
103  $extractorInstances = ‪$extractorRegistry->getExtractors();
104 
105  self::assertTrue($extractorInstances[0] instanceof $extractorClass2);
106  self::assertTrue($extractorInstances[1] instanceof $extractorClass3);
107  self::assertTrue($extractorInstances[2] instanceof $extractorClass1);
108  }
109 
114  {
115  $extractorClass1 = 'b70551b2b2db62b6b15a9bbfcbd50614';
116  $extractorObject1 = $this->getMockBuilder(ExtractorInterface::class)
117  ->setMockClassName($extractorClass1)
118  ->getMock();
119  $extractorObject1->expects(self::any())->method('getPriority')->willReturn(1);
120 
121  $extractorClass2 = 'ac318f1659d278b79b38262f23a78d5d';
122  $extractorObject2 = $this->getMockBuilder(ExtractorInterface::class)
123  ->setMockClassName($extractorClass2)
124  ->getMock();
125  $extractorObject2->expects(self::any())->method('getPriority')->willReturn(1);
126 
127  $createdExtractorInstances = [
128  [$extractorClass1, $extractorObject1],
129  [$extractorClass2, $extractorObject2],
130  ];
131 
132  ‪$extractorRegistry = $this->‪getMockExtractorRegistry($createdExtractorInstances);
133  ‪$extractorRegistry->registerExtractionService($extractorClass1);
134  ‪$extractorRegistry->registerExtractionService($extractorClass2);
135 
136  $extractorInstances = ‪$extractorRegistry->getExtractors();
137  self::assertContains($extractorObject1, $extractorInstances);
138  self::assertContains($extractorObject2, $extractorInstances);
139  }
140 
147  protected function ‪getMockExtractorRegistry(array $createsExtractorInstances = [])
148  {
149  ‪$extractorRegistry = $this->getMockBuilder(ExtractorRegistry::class)
150  ->setMethods(['createExtractorInstance'])
151  ->getMock();
152 
153  if (!empty($createsExtractorInstances)) {
154  ‪$extractorRegistry->expects(self::any())
155  ->method('createExtractorInstance')
156  ->willReturnMap($createsExtractorInstances);
157  }
158 
159  return ‪$extractorRegistry;
160  }
161 }
‪TYPO3\CMS\Core\Tests\Unit\Resource\Index\ExtractorRegistryTest\registeredExtractorClassCanBeRetrieved
‪registeredExtractorClassCanBeRetrieved()
Definition: ExtractorRegistryTest.php:30
‪$extractorRegistry
‪$extractorRegistry
Definition: ext_localconf.php:30
‪TYPO3\CMS\Core\Tests\Unit\Resource\Index\ExtractorRegistryTest\registerExtractorClassThrowsExceptionIfClassDoesNotImplementRightInterface
‪registerExtractorClassThrowsExceptionIfClassDoesNotImplementRightInterface()
Definition: ExtractorRegistryTest.php:59
‪TYPO3\CMS\Core\Tests\Unit\Resource\Index\ExtractorRegistryTest
Definition: ExtractorRegistryTest.php:26
‪TYPO3\CMS\Core\Resource\Index\ExtractorInterface
Definition: ExtractorInterface.php:25
‪TYPO3\CMS\Core\Resource\Index\ExtractorRegistry
Definition: ExtractorRegistry.php:25
‪TYPO3\CMS\Core\Tests\Unit\Resource\Index\ExtractorRegistryTest\registeredExtractorClassWithSamePriorityAreAllReturned
‪registeredExtractorClassWithSamePriorityAreAllReturned()
Definition: ExtractorRegistryTest.php:113
‪TYPO3\CMS\Core\Tests\Unit\Resource\Index\ExtractorRegistryTest\getMockExtractorRegistry
‪PHPUnit Framework MockObject MockObject TYPO3 CMS Core Resource Index ExtractorRegistry getMockExtractorRegistry(array $createsExtractorInstances=[])
Definition: ExtractorRegistryTest.php:147
‪TYPO3\CMS\Core\Tests\Unit\Resource\Index
Definition: ExtractorRegistryTest.php:16
‪TYPO3\CMS\Core\Tests\Unit\Resource\Index\ExtractorRegistryTest\registerExtractorClassThrowsExceptionIfClassDoesNotExist
‪registerExtractorClassThrowsExceptionIfClassDoesNotExist()
Definition: ExtractorRegistryTest.php:46
‪TYPO3\CMS\Core\Tests\Unit\Resource\Index\ExtractorRegistryTest\registerExtractorClassWithHighestPriorityIsFirstInResult
‪registerExtractorClassWithHighestPriorityIsFirstInResult()
Definition: ExtractorRegistryTest.php:72