Merge pull request #121 from Codappix/feature/117-use-extbase-object-manager-for-dataprocessor

FEATURE: Use extbase for processor instantiation
This commit is contained in:
Daniel Siepmann 2018-02-27 19:53:57 +01:00 committed by GitHub
commit 3bfe55cd33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 1 deletions

View file

@ -48,6 +48,12 @@ abstract class AbstractIndexer implements IndexerInterface
*/ */
protected $logger; protected $logger;
/**
* @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
* @inject
*/
protected $objectManager;
/** /**
* Inject log manager to get concrete logger from it. * Inject log manager to get concrete logger from it.
* *
@ -141,7 +147,8 @@ abstract class AbstractIndexer implements IndexerInterface
} else { } else {
$className = $configuration['_typoScriptNodeValue']; $className = $configuration['_typoScriptNodeValue'];
} }
$dataProcessor = GeneralUtility::makeInstance($className);
$dataProcessor = $this->objectManager->get($className);
if ($dataProcessor instanceof ProcessorInterface) { if ($dataProcessor instanceof ProcessorInterface) {
$record = $dataProcessor->processRecord($record, $configuration); $record = $dataProcessor->processRecord($record, $configuration);
} }

View file

@ -205,3 +205,6 @@ class name) as done in the examples above.
By implementing also the same interface as necessary for TYPO3 By implementing also the same interface as necessary for TYPO3
:ref:`t3tsref:cobj-fluidtemplate-properties-dataprocessing`, you are able to reuse the same code :ref:`t3tsref:cobj-fluidtemplate-properties-dataprocessing`, you are able to reuse the same code
also for Fluid to prepare the same record fetched from DB for your fluid. also for Fluid to prepare the same record fetched from DB for your fluid.
Dependency injection is possible inside of processors, as we instantiate through extbase
``ObjectManager``.

View file

@ -26,6 +26,7 @@ use Codappix\SearchCore\Connection\ConnectionInterface;
use Codappix\SearchCore\DataProcessing\CopyToProcessor; use Codappix\SearchCore\DataProcessing\CopyToProcessor;
use Codappix\SearchCore\Domain\Index\AbstractIndexer; use Codappix\SearchCore\Domain\Index\AbstractIndexer;
use Codappix\SearchCore\Tests\Unit\AbstractUnitTestCase; use Codappix\SearchCore\Tests\Unit\AbstractUnitTestCase;
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
class AbstractIndexerTest extends AbstractUnitTestCase class AbstractIndexerTest extends AbstractUnitTestCase
{ {
@ -44,17 +45,25 @@ class AbstractIndexerTest extends AbstractUnitTestCase
*/ */
protected $connection; protected $connection;
/**
* @var ObjectManagerInterface
*/
protected $objectManager;
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
$this->configuration = $this->getMockBuilder(ConfigurationContainerInterface::class)->getMock(); $this->configuration = $this->getMockBuilder(ConfigurationContainerInterface::class)->getMock();
$this->connection = $this->getMockBuilder(ConnectionInterface::class)->getMock(); $this->connection = $this->getMockBuilder(ConnectionInterface::class)->getMock();
$this->objectManager = $this->getMockBuilder(ObjectManagerInterface::class)->getMock();
$this->subject = $this->getMockForAbstractClass(AbstractIndexer::class, [ $this->subject = $this->getMockForAbstractClass(AbstractIndexer::class, [
$this->connection, $this->connection,
$this->configuration $this->configuration
]); ]);
$this->inject($this->subject, 'objectManager', $this->objectManager);
$this->subject->injectLogger($this->getMockedLogger()); $this->subject->injectLogger($this->getMockedLogger());
$this->subject->setIdentifier('testTable'); $this->subject->setIdentifier('testTable');
$this->subject->expects($this->any()) $this->subject->expects($this->any())
@ -73,6 +82,11 @@ class AbstractIndexerTest extends AbstractUnitTestCase
$expectedRecord['new_test_field2'] = 'test' . PHP_EOL . 'test'; $expectedRecord['new_test_field2'] = 'test' . PHP_EOL . 'test';
$expectedRecord['search_abstract'] = ''; $expectedRecord['search_abstract'] = '';
$this->objectManager->expects($this->any())
->method('get')
->with(CopyToProcessor::class)
->willReturn(new CopyToProcessor());
$this->configuration->expects($this->exactly(2)) $this->configuration->expects($this->exactly(2))
->method('get') ->method('get')
->withConsecutive(['indexing.testTable.dataProcessing'], ['indexing.testTable.abstractFields']) ->withConsecutive(['indexing.testTable.dataProcessing'], ['indexing.testTable.abstractFields'])