Skip to content

Commit

Permalink
[TASK] Use constructor DI for viewhelper
Browse files Browse the repository at this point in the history
  • Loading branch information
linawolf committed Jul 13, 2024
1 parent 7a4dba9 commit 9ae202f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
9 changes: 2 additions & 7 deletions Classes/ViewHelpers/GravatarViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,16 @@ class GravatarViewHelper extends AbstractTagBasedViewHelper
* @var string
*/
protected $tagName = 'img';

protected UriFactory $uriFactory;

public function injectUriFactory(UriFactory $uriFactory): void
public function __construct(private readonly UriFactory $uriFactory)
{
$this->uriFactory = $uriFactory;
parent::__construct();
}

/**
* Initialize arguments
*/
public function initializeArguments(): void
{
parent::initializeArguments();

$this->registerUniversalTagAttributes();
$this->registerArgument('emailAddress', 'string', '', true)
->registerArgument('defaultImageUri', 'string', '', false)
Expand Down
3 changes: 2 additions & 1 deletion Tests/Functional/ViewHelpers/GravatarViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use T3docs\BlogExample\ViewHelpers\GravatarViewHelper;
use TYPO3\CMS\Core\Http\UriFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
Expand All @@ -36,7 +37,7 @@ protected function setUp(): void
{
parent::setUp();

$this->subject = new GravatarViewHelper();
$this->subject = new GravatarViewHelper(GeneralUtility::makeInstance(UriFactory::class));
}

public static function renderDataProvider(): array
Expand Down

0 comments on commit 9ae202f

Please sign in to comment.