Skip to content

Commit 523b782

Browse files
author
Bernhard Schmitt
committed
Properly implement EnumLabel
1 parent 52bf4b6 commit 523b782

2 files changed

Lines changed: 53 additions & 7 deletions

File tree

Classes/Domain/Enum/EnumLabel.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ final class EnumLabel
1818

1919
private string $packageKey;
2020

21-
private function __construct(
21+
public function __construct(
2222
string $labelIdPrefix,
2323
string $sourceName,
2424
string $packageKey
@@ -30,15 +30,15 @@ private function __construct(
3030

3131
public static function fromEnumName(string $enumName): self
3232
{
33-
list($packageKey, $componentName) = explode('/Presentation/', $enumName);
34-
$pivot = \mb_strrpos($componentName, '/') ?: null;
35-
$componentNamespace = \mb_substr($packageKey, 0, $pivot);
36-
$enumShort = lcfirst(\mb_substr($packageKey, $pivot+1));
33+
list($packageNamespace, $componentName) = explode('\Presentation\\', $enumName);
34+
$pivot = \mb_strrpos($componentName, '\\') ?: null;
35+
$componentNamespace = \mb_substr($componentName, 0, $pivot);
36+
$enumShort = lcfirst(\mb_substr($componentName, $pivot+1));
3737

3838
return new self(
3939
$enumShort . '.',
40-
\str_replace('/', '.', $componentNamespace),
41-
\str_replace('/', '.', $packageKey)
40+
\str_replace('\\', '.', $componentNamespace),
41+
\str_replace('\\', '.', $packageNamespace)
4242
);
4343
}
4444

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php declare(strict_types=1);
2+
namespace PackageFactory\AtomicFusion\PresentationObjects\Tests\Unit\Domain\Enum;
3+
4+
/*
5+
* This file is part of the PackageFactory.AtomicFusion.PresentationObjects package
6+
*/
7+
8+
use Neos\Flow\Tests\UnitTestCase;
9+
use PackageFactory\AtomicFusion\PresentationObjects\Domain\Enum\EnumLabel;
10+
use PHPUnit\Framework\Assert;
11+
12+
/**
13+
* Test cases for EnumLabel
14+
*/
15+
class EnumLabelTest extends UnitTestCase
16+
{
17+
/**
18+
* @param string $enumName
19+
* @param EnumLabel $expectedLabel
20+
* @dataProvider enumProvider
21+
*/
22+
public function testFromEnumName(string $enumName, EnumLabel $expectedLabel): void
23+
{
24+
Assert::assertEquals(
25+
$expectedLabel,
26+
EnumLabel::fromEnumName($enumName)
27+
);
28+
}
29+
30+
/**
31+
* @return array<int, array<int, class-string<mixed>|EnumLabel>>
32+
*/
33+
public function enumProvider(): array
34+
{
35+
return [
36+
[
37+
'Vendor\Site\Presentation\Component\Headline\HeadlineType',
38+
new EnumLabel('headlineType.', 'Component.Headline', 'Vendor.Site')
39+
],
40+
[
41+
'Vendor\Site\Presentation\Component\MyNewComponent\MyStringPseudoEnum',
42+
new EnumLabel('myStringPseudoEnum.', 'Component.MyNewComponent', 'Vendor.Site')
43+
]
44+
];
45+
}
46+
}

0 commit comments

Comments
 (0)