-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delegate factory rendering to interface in kickstarter
- Loading branch information
Bernhard Schmitt
committed
Nov 16, 2022
1 parent
27046ff
commit b28563f
Showing
8 changed files
with
161 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the PackageFactory.AtomicFusion.PresentationObjects package | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PackageFactory\AtomicFusion\PresentationObjects\Domain; | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
use PackageFactory\AtomicFusion\PresentationObjects\Domain\Component\Component; | ||
|
||
/** | ||
* The dummy presentation object factory renderer | ||
*/ | ||
#[Flow\Proxy(false)] | ||
final class DummyFactoryRenderer implements FactoryRendererInterface | ||
{ | ||
public function renderFactoryContent(Component $component): string | ||
{ | ||
return '<?php | ||
' . $component->name->renderClassComment() . ' | ||
declare(strict_types=1); | ||
namespace ' . $component->name->getPhpNamespace() . '; | ||
use PackageFactory\AtomicFusion\PresentationObjects\Fusion\AbstractComponentPresentationObjectFactory; | ||
final class ' . $component->name->getSimpleFactoryName() . ' extends AbstractComponentPresentationObjectFactory | ||
{ | ||
} | ||
'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the PackageFactory.AtomicFusion.PresentationObjects package | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PackageFactory\AtomicFusion\PresentationObjects\Domain; | ||
|
||
use PackageFactory\AtomicFusion\PresentationObjects\Domain\Component\Component; | ||
|
||
interface FactoryRendererInterface | ||
{ | ||
public function renderFactoryContent(Component $component): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the PackageFactory.AtomicFusion.PresentationObjects package | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PackageFactory\AtomicFusion\PresentationObjects\Tests\Unit\Domain; | ||
|
||
use Neos\Flow\Tests\UnitTestCase; | ||
use PackageFactory\AtomicFusion\PresentationObjects\Domain\Component\Component; | ||
use PackageFactory\AtomicFusion\PresentationObjects\Domain\Component\ComponentName; | ||
use PackageFactory\AtomicFusion\PresentationObjects\Domain\DummyFactoryRenderer; | ||
use PackageFactory\AtomicFusion\PresentationObjects\Domain\FusionNamespace; | ||
use PackageFactory\AtomicFusion\PresentationObjects\Domain\PackageKey; | ||
use PackageFactory\AtomicFusion\PresentationObjects\Domain\Component\Props; | ||
use PHPUnit\Framework\Assert; | ||
|
||
/** | ||
* Test cases for DummyFactoryRenderer | ||
*/ | ||
class DummyFactoryRendererTest extends UnitTestCase | ||
{ | ||
private ?Component $component = null; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$componentName = new ComponentName( | ||
new PackageKey('Vendor.Site'), | ||
FusionNamespace::default(), | ||
'MyNewComponent', | ||
); | ||
$this->component = new Component( | ||
$componentName, | ||
Props::fromInputArray( | ||
$componentName, | ||
[ | ||
'bool:bool', | ||
'nullableBool:?bool', | ||
'float:float', | ||
'nullableFloat:?float', | ||
'int:int', | ||
'nullableInt:?int', | ||
'string:string', | ||
'nullableString:?string', | ||
'uri:Uri', | ||
'nullableUri:?Uri', | ||
'image:ImageSource', | ||
'nullableImage:?ImageSource', | ||
'subComponent:MyComponent', | ||
'nullableSubComponent:?MyComponent', | ||
'componentArray:array<MyComponent>', | ||
'enum:MyStringEnum', | ||
'nullableEnum:?MyStringEnum', | ||
'slot:slot', | ||
'nullableSlot:?slot', | ||
] | ||
) | ||
); | ||
} | ||
|
||
public function testGetFactoryContent(): void | ||
{ | ||
Assert::assertSame( | ||
'<?php | ||
/* | ||
* This file is part of the Vendor.Site package. | ||
*/ | ||
declare(strict_types=1); | ||
namespace Vendor\Site\Presentation\Component\MyNewComponent; | ||
use PackageFactory\AtomicFusion\PresentationObjects\Fusion\AbstractComponentPresentationObjectFactory; | ||
final class MyNewComponentFactory extends AbstractComponentPresentationObjectFactory | ||
{ | ||
} | ||
', | ||
(new DummyFactoryRenderer())->renderFactoryContent($this->component) | ||
); | ||
} | ||
} |