• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CPS-IT / handlebars / 12807032056

16 Jan 2025 10:34AM UTC coverage: 93.103% (-0.08%) from 93.186%
12807032056

push

github

web-flow
Merge pull request #400 from CPS-IT/fix/1.x/test-environment

[BUGFIX] Make functional testing environment in DDEV work

1 of 2 new or added lines in 1 file covered. (50.0%)

972 of 1044 relevant lines covered (93.1%)

3.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.43
/Classes/DependencyInjection/FeatureRegistrationPass.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the TYPO3 CMS extension "handlebars".
7
 *
8
 * Copyright (C) 2024 Elias Häußler <e.haeussler@familie-redlich.de>
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation, either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22
 */
23

24
namespace Fr\Typo3Handlebars\DependencyInjection;
25

26
use Fr\Typo3Handlebars\Configuration;
27
use Fr\Typo3Handlebars\Renderer;
28
use Symfony\Component\DependencyInjection;
29
use TYPO3\CMS\Core;
30

31
/**
32
 * FeatureRegistrationPass
33
 *
34
 * @author Elias Häußler <e.haeussler@familie-redlich.de>
35
 * @license GPL-2.0-or-later
36
 * @internal
37
 */
38
final class FeatureRegistrationPass implements DependencyInjection\Compiler\CompilerPassInterface
39
{
40
    private DependencyInjection\ContainerBuilder $container;
41
    private Core\Configuration\ExtensionConfiguration $extensionConfiguration;
42

43
    public function process(DependencyInjection\ContainerBuilder $container): void
4✔
44
    {
45
        $this->container = $container;
4✔
46
        $this->extensionConfiguration = $this->container->get(Core\Configuration\ExtensionConfiguration::class);
4✔
47

48
        if ($this->isFeatureEnabled('blockHelper')) {
4✔
49
            $this->activateHelper('block', Renderer\Helper\BlockHelper::class);
1✔
50
        }
51
        if ($this->isFeatureEnabled('contentHelper')) {
4✔
52
            $this->activateHelper('content', Renderer\Helper\ContentHelper::class);
1✔
53
        }
54
        if ($this->isFeatureEnabled('extendHelper')) {
4✔
55
            $this->activateHelper('extend', Renderer\Helper\ExtendHelper::class);
1✔
56
        }
57
        if ($this->isFeatureEnabled('renderHelper')) {
4✔
58
            $this->activateHelper('render', Renderer\Helper\RenderHelper::class);
1✔
59
        }
60
        if ($this->isFeatureEnabled('flatTemplateResolver')) {
4✔
61
            $this->activateFlatTemplateResolver();
1✔
62
        }
63
    }
64

65
    /**
66
     * @param class-string<Renderer\Helper\Helper> $className
67
     */
68
    private function activateHelper(string $name, string $className): void
1✔
69
    {
70
        $definition = $this->container->getDefinition($className);
1✔
71
        $definition->addTag('handlebars.helper', [
1✔
72
            'identifier' => $name,
1✔
73
            'method' => 'render',
1✔
74
        ]);
1✔
75
    }
76

77
    private function activateFlatTemplateResolver(): void
1✔
78
    {
79
        $this->container->getDefinition('handlebars.template_resolver')->setClass(Renderer\Template\FlatTemplateResolver::class);
1✔
80
    }
81

82
    private function isFeatureEnabled(string $featureName): bool
4✔
83
    {
84
        $configurationPath = sprintf('features/%s/enable', $featureName);
4✔
85

86
        // Avoid calls to PackageManager during testing
87
        if (Core\Core\Environment::getContext()->isTesting()) {
4✔
NEW
88
            return true;
×
89
        }
90

91
        try {
92
            return (bool)$this->extensionConfiguration->get(Configuration\Extension::KEY, $configurationPath);
4✔
93
        } catch (Core\Exception) {
1✔
94
            return false;
1✔
95
        }
96
    }
97
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc