/** * {@inheritdoc} */ public function check(ThemeInterface $theme, array $previousThemes = []) { if (0 === count($theme->getParents())) { return; } $previousThemes = array_merge($previousThemes, [$theme]); foreach ($theme->getParents() as $parent) { if (in_array($parent, $previousThemes, true)) { throw new CircularDependencyFoundException(array_merge($previousThemes, [$parent])); } $this->check($parent, $previousThemes); } }
/** * {@inheritdoc} */ public function getThemeHierarchy(ThemeInterface $theme = null) { if (null === $theme) { return []; } $parents = []; foreach ($theme->getParents() as $parent) { $parents = array_merge($parents, $this->getThemeHierarchy($parent)); } return array_merge([$theme], $parents); }
function it_finds_circular_dependency_if_theme_parents_are_cycled(ThemeInterface $firstTheme, ThemeInterface $secondTheme, ThemeInterface $thirdTheme, ThemeInterface $fourthTheme) { $firstTheme->getParents()->willReturn([$secondTheme, $thirdTheme]); $secondTheme->getParents()->willReturn([$thirdTheme]); $thirdTheme->getParents()->willReturn([$fourthTheme]); $fourthTheme->getParents()->willReturn([$secondTheme]); $firstTheme->getName()->willReturn('first/theme'); $secondTheme->getName()->willReturn('second/theme'); $thirdTheme->getName()->willReturn('third/theme'); $fourthTheme->getName()->willReturn('fourth/theme'); $this->shouldThrow(CircularDependencyFoundException::class)->during('check', [$firstTheme]); }
function it_ensures_cohesion_between_parent_themes(ThemeLoaderInterface $themeLoader, ThemeRepositoryInterface $themeRepository, ThemeMergerInterface $themeMerger, ThemeInterface $loadedTheme, ThemeInterface $loadedParentTheme, ThemeInterface $existingParentTheme) { $themeRepository->findAll()->willReturn([$existingParentTheme]); $existingParentTheme->getName()->willReturn('parent-theme/name'); $themeLoader->load()->willReturn([$loadedTheme, $loadedParentTheme]); $loadedTheme->getName()->willReturn('theme/name'); $loadedTheme->getParents()->willReturn([$loadedParentTheme]); $themeRepository->findOneByName('theme/name')->willReturn(null); $loadedParentTheme->getName()->willReturn('parent-theme/name'); $loadedParentTheme->getParents()->willReturn([]); $themeRepository->findOneByName('parent-theme/name')->willReturn($existingParentTheme); $loadedTheme->removeParent($loadedParentTheme)->shouldBeCalled(); $loadedTheme->addParent($existingParentTheme)->shouldBeCalled(); $themeMerger->merge($existingParentTheme, $loadedParentTheme)->willReturn($existingParentTheme); $themeRepository->add($loadedTheme)->shouldBeCalled(); $themeRepository->add($existingParentTheme)->shouldBeCalled(); $themeRepository->add($loadedParentTheme)->shouldNotBeCalled(); $this->synchronize(); }
function it_returns_theme_list_in_hierarchized_order(ThemeInterface $firstTheme, ThemeInterface $secondTheme) { $firstTheme->getParents()->willReturn([$secondTheme]); $secondTheme->getParents()->willReturn([]); $this->getThemeHierarchy($firstTheme)->shouldReturn([$firstTheme, $secondTheme]); }