groupId => groupName, as DesignSystemWriter::groupsOf() returns it. */ private static function groups(): array { return [ 'title.decoration.font' => 'divi/font', 'content.decoration.bodyFont' => 'divi/font-body', 'module.decoration.spacing' => 'divi/spacing', 'button.decoration.spacing' => 'divi/spacing', ]; } public function testShortNameFullNameAndPathFindTheGroup(): void { self::assertSame('content.decoration.bodyFont', GroupKeys::resolve(self::groups(), 'font-body')); self::assertSame('content.decoration.bodyFont', GroupKeys::resolve(self::groups(), 'divi/font-body')); self::assertSame('content.decoration.bodyFont', GroupKeys::resolve(self::groups(), 'content.decoration.bodyFont')); self::assertSame('title.decoration.font', GroupKeys::resolve(self::groups(), 'font')); } public function testSeveralGroupsWithTheSameNameNeedThePath(): void { self::assertSame('button.decoration.spacing', GroupKeys::resolve(self::groups(), 'button.decoration.spacing')); foreach (['spacing', 'divi/spacing'] as $key) { try { GroupKeys::resolve(self::groups(), $key); self::fail('Ambiguous group name must throw.'); } catch (InvalidArgumentException $e) { self::assertSame(GroupKeys::AMBIGUOUS, $e->getCode()); self::assertSame( sprintf( 'Gruppe "%s" ist mehrdeutig; bitte den Attributpfad angeben: ' . 'module.decoration.spacing, button.decoration.spacing.', $key ), $e->getMessage() ); } } } public function testUnknownGroup(): void { try { GroupKeys::resolve(self::groups(), 'sizing'); self::fail('Unknown group must throw.'); } catch (InvalidArgumentException $e) { self::assertSame(GroupKeys::UNKNOWN, $e->getCode()); self::assertSame('keine Gruppe "sizing"', $e->getMessage()); } $this->expectException(InvalidArgumentException::class); GroupKeys::resolve([], 'font'); } }