[BUGFIX] Make ImageService independent from object manager 41/55041/7
authorFrans Saris <franssaris@gmail.com>
Tue, 12 Dec 2017 10:45:19 +0000 (11:45 +0100)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Tue, 12 Dec 2017 14:22:43 +0000 (15:22 +0100)
Resolves: #83295
Related: #82414
Releases: master
Change-Id: I048e8a406b04227e28021b4ad0082c6a6b174708
Reviewed-on: https://review.typo3.org/55041
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
typo3/sysext/extbase/Classes/Service/ImageService.php
typo3/sysext/extbase/Tests/Unit/Service/ImageScriptServiceTest.php

index 4234b5f..9af53cf 100644 (file)
@@ -19,6 +19,7 @@ use TYPO3\CMS\Core\Resource\File;
 use TYPO3\CMS\Core\Resource\FileInterface;
 use TYPO3\CMS\Core\Resource\FileReference;
 use TYPO3\CMS\Core\Resource\ProcessedFile;
+use TYPO3\CMS\Core\Resource\ResourceFactory;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
 
@@ -28,29 +29,25 @@ use TYPO3\CMS\Core\Utility\MathUtility;
 class ImageService implements \TYPO3\CMS\Core\SingletonInterface
 {
     /**
-     * @var \TYPO3\CMS\Core\Resource\ResourceFactory
+     * @var ResourceFactory
      */
     protected $resourceFactory;
 
     /**
-     * @var \TYPO3\CMS\Extbase\Service\EnvironmentService
+     * @var EnvironmentService
      */
     protected $environmentService;
 
     /**
-     * @param \TYPO3\CMS\Core\Resource\ResourceFactory $resourceFactory
-     */
-    public function injectResourceFactory(\TYPO3\CMS\Core\Resource\ResourceFactory $resourceFactory)
-    {
-        $this->resourceFactory = $resourceFactory;
-    }
-
-    /**
-     * @param \TYPO3\CMS\Extbase\Service\EnvironmentService $environmentService
+     * ImageService constructor.
+     *
+     * @param EnvironmentService|null $environmentService
+     * @param ResourceFactory|null $resourceFactory
      */
-    public function injectEnvironmentService(\TYPO3\CMS\Extbase\Service\EnvironmentService $environmentService)
+    public function __construct(EnvironmentService $environmentService = null, ResourceFactory $resourceFactory = null)
     {
-        $this->environmentService = $environmentService;
+        $this->environmentService = $environmentService ?? GeneralUtility::makeInstance(EnvironmentService::class);
+        $this->resourceFactory = $resourceFactory ?? ResourceFactory::getInstance();
     }
 
     /**
index c7e4d96..7f983b0 100644 (file)
@@ -41,9 +41,8 @@ class ImageScriptServiceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestC
      */
     protected function setUp()
     {
-        $this->subject = new ImageService();
         $this->environmentService = $this->createMock(EnvironmentService::class);
-        $this->inject($this->subject, 'environmentService', $this->environmentService);
+        $this->subject = new ImageService($this->environmentService);
         GeneralUtility::flushInternalRuntimeCaches();
         $_SERVER['HTTP_HOST'] = 'foo.bar';
     }