[TASK] Use constructor injection in persistence backend 32/59632/4
authorAlexander Schnitzler <git@alexanderschnitzler.de>
Mon, 4 Feb 2019 15:16:06 +0000 (16:16 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 23 Feb 2019 20:23:53 +0000 (21:23 +0100)
Class Backend does no longer use setter injection but
constructor injection instead.

Releases: master
Resolves: #87643
Change-Id: I4b06be7e3c6011bb0b8661df617017891490e070
Reviewed-on: https://review.typo3.org/c/59632
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/BackendTest.php

index e72376d..9e0f1fa 100644 (file)
@@ -96,61 +96,33 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
     protected $signalSlotDispatcher;
 
     /**
-     * @param \TYPO3\CMS\Extbase\Persistence\Generic\Session $session
-     */
-    public function injectSession(\TYPO3\CMS\Extbase\Persistence\Generic\Session $session)
-    {
-        $this->session = $session;
-    }
-
-    /**
+     * Constructs the backend
+     *
+     * @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager
+     * @param Session $session
      * @param \TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService
-     */
-    public function injectReflectionService(\TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService)
-    {
-        $this->reflectionService = $reflectionService;
-    }
-
-    /**
      * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory $qomFactory
-     */
-    public function injectQomFactory(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory $qomFactory)
-    {
-        $this->qomFactory = $qomFactory;
-    }
-
-    /**
      * @param \TYPO3\CMS\Extbase\Persistence\Generic\Storage\BackendInterface $storageBackend
-     */
-    public function injectStorageBackend(\TYPO3\CMS\Extbase\Persistence\Generic\Storage\BackendInterface $storageBackend)
-    {
-        $this->storageBackend = $storageBackend;
-    }
-
-    /**
      * @param \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory $dataMapFactory
-     */
-    public function injectDataMapFactory(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory $dataMapFactory)
-    {
-        $this->dataMapFactory = $dataMapFactory;
-    }
-
-    /**
      * @param \TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher
      */
-    public function injectSignalSlotDispatcher(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher)
-    {
+    public function __construct(
+        \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager,
+        \TYPO3\CMS\Extbase\Persistence\Generic\Session $session,
+        \TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService,
+        \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory $qomFactory,
+        \TYPO3\CMS\Extbase\Persistence\Generic\Storage\BackendInterface $storageBackend,
+        \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory $dataMapFactory,
+        \TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher
+    ) {
+        $this->configurationManager = $configurationManager;
+        $this->session = $session;
+        $this->reflectionService = $reflectionService;
+        $this->qomFactory = $qomFactory;
+        $this->storageBackend = $storageBackend;
+        $this->dataMapFactory = $dataMapFactory;
         $this->signalSlotDispatcher = $signalSlotDispatcher;
-    }
 
-    /**
-     * Constructs the backend
-     *
-     * @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager
-     */
-    public function __construct(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager)
-    {
-        $this->configurationManager = $configurationManager;
         $this->referenceIndex = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ReferenceIndex::class);
         $this->referenceIndex->enableRuntimeCache();
         $this->aggregateRootObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
index 36142a6..4d6a727 100644 (file)
@@ -31,6 +31,12 @@ use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
  */
 class BackendTest extends UnitTestCase
 {
+    protected function tearDown(): void
+    {
+        GeneralUtility::purgeInstances();
+        parent::tearDown();
+    }
+
     /**
      * @test
      */
@@ -103,7 +109,7 @@ class BackendTest extends UnitTestCase
         $session->expects($this->once())->method('getIdentifierByObject')->with($object)->will($this->returnValue($fakeUuid));
 
         /** @var Backend $backend */
-        $backend = $this->getAccessibleMock(Backend::class, ['dummy'], [$configurationManager]);
+        $backend = $this->getAccessibleMock(Backend::class, ['dummy'], [$configurationManager], '', false);
         $backend->_set('session', $session);
 
         $this->assertEquals($backend->getIdentifierByObject($object), $fakeUuid);
@@ -135,7 +141,7 @@ class BackendTest extends UnitTestCase
         $session->expects($this->once())->method('getIdentifierByObject')->with($object)->will($this->returnValue($fakeUuid));
 
         /** @var Backend $backend */
-        $backend = $this->getAccessibleMock(Backend::class, ['dummy'], [$configurationManager]);
+        $backend = $this->getAccessibleMock(Backend::class, ['dummy'], [$configurationManager], '', false);
         $backend->_set('session', $session);
 
         $this->assertEquals($backend->getIdentifierByObject($proxy), $fakeUuid);