Skip to content

Commit

Permalink
[TASK] Refactor ContentTypeBuilderTest and add error test case
Browse files Browse the repository at this point in the history
  • Loading branch information
NamelessCoder committed Jul 31, 2023
1 parent 610f041 commit b85c895
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 26 deletions.
54 changes: 28 additions & 26 deletions Classes/Integration/ContentTypeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,34 @@ public function configureContentTypeFromTemplateFile(
string $defaultControllerExtensionName = 'FluidTYPO3.Flux',
?string $controllerActionName = null
): ProviderInterface {
/** @var BasicProviderInterface $provider */
$provider = GeneralUtility::makeInstance($providerClassName);
if (!$provider instanceof BasicProviderInterface
|| !$provider instanceof RecordProviderInterface
|| !$provider instanceof ControllerProviderInterface
|| !$provider instanceof FluidProviderInterface
|| !$provider instanceof ContentTypeProviderInterface
) {
throw new \RuntimeException(
sprintf(
'The Flux Provider class "%s" must implement at least the following interfaces to work as '
. 'content type Provider: %s',
$providerClassName,
implode(
',',
[
BasicProviderInterface::class,
RecordProviderInterface::class,
ControllerProviderInterface::class,
FluidProviderInterface::class,
ContentTypeProviderInterface::class
]
)
),
1690816678
);
}

$section = 'Configuration';
$controllerName = 'Content';
$pluginName = null;
Expand Down Expand Up @@ -92,32 +120,6 @@ class_alias($controllerClassName, $localControllerClassName);
$contentType
);

/** @var BasicProviderInterface $provider */
$provider = GeneralUtility::makeInstance($providerClassName);
if (!$provider instanceof BasicProviderInterface
|| !$provider instanceof RecordProviderInterface
|| !$provider instanceof ControllerProviderInterface
|| !$provider instanceof FluidProviderInterface
|| !$provider instanceof ContentTypeProviderInterface
) {
throw new \RuntimeException(
sprintf(
'The Flux Provider class "%s" must implement at least the following interfaces to work as '
. 'content type Provider: %s',
$providerClassName,
implode(
',',
[
BasicProviderInterface::class,
RecordProviderInterface::class,
ControllerProviderInterface::class,
FluidProviderInterface::class,
ContentTypeProviderInterface::class
]
)
)
);
}
$provider->setFieldName('pi_flexform');
$provider->setTableName('tt_content');
$provider->setExtensionKey($providerExtensionName);
Expand Down
10 changes: 10 additions & 0 deletions Tests/Unit/Integration/ContentTypeBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,14 @@ public function testConfigureContentTypeFromTemplateFile(): void
);
$this->assertInstanceOf(Provider::class, $result);
}

public function testThrowsExceptionOnInvalidProviderClass(): void
{
$this->expectExceptionCode(1690816678);
(new ContentTypeBuilder())->configureContentTypeFromTemplateFile(
'FluidTYPO3.Flux',
'/dev/null',
\DateTime::class,
);
}
}

0 comments on commit b85c895

Please sign in to comment.