Skip to content

Commit 8f01929

Browse files
committed
[BUGFIX] Deactivate PlantUmlServer calls for tests
When the docker container is used in testing pipelines to test if documentation renders without warnings, the plantuml server sometimes makes the tests fail by not being available. This PR disables the plantuml server calls in testing-mode that is when option --fail-on-log is set.
1 parent 8790de1 commit 8f01929

File tree

8 files changed

+117
-18
lines changed

8 files changed

+117
-18
lines changed

Documentation/Index.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,32 @@ to extend the tool.
4545
Developer/Index
4646
Migration/Index
4747
KnownProblems/Index
48+
49+
.. uml::
50+
51+
class Foo1 {
52+
You can use
53+
several lines
54+
..
55+
as you want
56+
and group
57+
==
58+
things together.
59+
__
60+
You can have as many groups
61+
as you want
62+
--
63+
End of class
64+
}
65+
66+
class User {
67+
.. Simple Getter ..
68+
+ getName()
69+
+ getAddress()
70+
.. Some setter ..
71+
+ setName()
72+
__ private data __
73+
int age
74+
-- encrypted --
75+
String password
76+
}

packages/typo3-docs-theme/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"require": {
1313
"brotkrueml/twig-codehighlight": "dev-main",
14+
"phpdocumentor/guides-graphs": "dev-main",
1415
"phpdocumentor/guides-theme-bootstrap": "dev-main",
1516
"t3docs/typo3-version-handling": "self.version"
1617
},

packages/typo3-docs-theme/resources/config/typo3-docs-theme.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use Brotkrueml\TwigCodeHighlight\Extension as CodeHighlight;
66
use phpDocumentor\Guides\Event\PostRenderProcess;
7+
use phpDocumentor\Guides\Event\PreParseProcess;
8+
use phpDocumentor\Guides\Graphs\Renderer\DiagramRenderer;
9+
use phpDocumentor\Guides\Graphs\Renderer\PlantumlServerRenderer;
710
use phpDocumentor\Guides\RestructuredText\Directives\BaseDirective;
811
use phpDocumentor\Guides\RestructuredText\Directives\SubDirective;
912
use phpDocumentor\Guides\RestructuredText\Parser\Interlink\InterlinkParser;
@@ -15,7 +18,9 @@
1518

1619
use T3Docs\Typo3DocsTheme\Directives\T3FieldListTableDirective;
1720
use T3Docs\Typo3DocsTheme\Directives\YoutubeDirective;
21+
use T3Docs\Typo3DocsTheme\EventListeners\TestingModeActivator;
1822
use T3Docs\Typo3DocsTheme\Parser\ExtendedInterlinkParser;
23+
use T3Docs\Typo3DocsTheme\Renderer\DecoratingPlantumlRenderer;
1924
use T3Docs\Typo3DocsTheme\TextRoles\IssueReferenceTextRole;
2025
use T3Docs\Typo3DocsTheme\TextRoles\PhpTextRole;
2126
use T3Docs\Typo3DocsTheme\Twig\TwigExtension;
@@ -41,6 +46,10 @@
4146
->set(PhpTextRole::class)
4247
->tag('phpdoc.guides.parser.rst.text_role')
4348

49+
->set(DecoratingPlantumlRenderer::class)
50+
->decorate(PlantumlServerRenderer::class)
51+
->public()
52+
4453
->set(GroupTabDirective::class)
4554
->set(T3FieldListTableDirective::class)
4655
->set(YoutubeDirective::class)
@@ -58,5 +67,8 @@
5867
->autowire()
5968

6069
->set(CopyResources::class)
61-
->tag('event_listener', ['event' => PostRenderProcess::class]);
70+
->tag('event_listener', ['event' => PostRenderProcess::class])
71+
72+
->set(TestingModeActivator::class)
73+
->tag('event_listener', ['event' => PreParseProcess::class]);
6274
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace T3Docs\Typo3DocsTheme\EventListeners;
4+
5+
use phpDocumentor\Guides\Event\PreParseProcess;
6+
use phpDocumentor\Guides\Settings\SettingsManager;
7+
use Psr\Log\LoggerInterface;
8+
use T3Docs\Typo3DocsTheme\Renderer\DecoratingPlantumlRenderer;
9+
10+
/**
11+
* Disables HTTP calls that can fail tests
12+
*/
13+
final class TestingModeActivator
14+
{
15+
public function __construct(
16+
private readonly SettingsManager $settingsManager,
17+
private readonly DecoratingPlantumlRenderer $decoratingPlantumlRenderer
18+
) {}
19+
20+
public function __invoke(PreParseProcess $event): void
21+
{
22+
// We are in test mode
23+
if ($this->settingsManager->getProjectSettings()->isFailOnError()) {
24+
$this->decoratingPlantumlRenderer->setDisabled(true);
25+
}
26+
}
27+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace T3Docs\Typo3DocsTheme\Renderer;
6+
7+
use phpDocumentor\Guides\Graphs\Renderer\DiagramRenderer;
8+
use phpDocumentor\Guides\Graphs\Renderer\PlantumlServerRenderer;
9+
10+
final class DecoratingPlantumlRenderer implements DiagramRenderer
11+
{
12+
private bool $disabled = false;
13+
14+
15+
public function __construct(private readonly PlantumlServerRenderer $innerRenderer) {}
16+
17+
public function render(string $diagram): string|null
18+
{
19+
if ($this->disabled) {
20+
return 'The PlantUML renderer is not available in test mode.';
21+
}
22+
return $this->innerRenderer->render($diagram);
23+
}
24+
25+
public function isDisabled(): bool
26+
{
27+
return $this->disabled;
28+
}
29+
30+
public function setDisabled(bool $disabled): void
31+
{
32+
$this->disabled = $disabled;
33+
}
34+
}

tests/ApplicationTestCase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use phpDocumentor\Guides\Bootstrap\DependencyInjection\BootstrapExtension;
88
use phpDocumentor\Guides\Cli\DependencyInjection\ApplicationExtension;
99
use phpDocumentor\Guides\Cli\DependencyInjection\ContainerFactory;
10+
use phpDocumentor\Guides\Graphs\DependencyInjection\GraphsExtension;
1011
use phpDocumentor\Guides\Markdown\DependencyInjection\MarkdownExtension;
1112
use PHPUnit\Framework\TestCase;
1213
use Symfony\Component\DependencyInjection\Container;
@@ -45,6 +46,7 @@ protected function prepareContainer(string|null $configurationFile = null, array
4546
new Typo3DocsThemeExtension(),
4647
new Typo3GuidesExtension(),
4748
new GuidesPhpDomainExtension(),
49+
new GraphsExtension(),
4850
...$extraExtensions,
4951
]);
5052

tests/Integration/IntegrationTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use T3Docs\GuidesExtension\Command\RunDecorator;
1515
use T3Docs\Typo3DocsTheme\ApplicationTestCase;
1616

17+
use T3Docs\Typo3DocsTheme\Renderer\DecoratingPlantumlRenderer;
18+
1719
use function array_filter;
1820
use function array_merge;
1921
use function array_walk;
@@ -62,6 +64,10 @@ private function compareHtmlIntegration(string $outputPath, string $inputPath, s
6264
$command = $this->getContainer()->get(Run::class);
6365
assert($command instanceof Run || $command instanceof RunDecorator);
6466

67+
$plantuml = $this->getContainer()->get(DecoratingPlantumlRenderer::class);
68+
assert($plantuml instanceof DecoratingPlantumlRenderer);
69+
$plantuml->setDisabled(true);
70+
6571
$input = new ArrayInput(
6672
[
6773
'input' => $inputPath,

tests/Integration/tests/directive-uml/expected/index.html

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,11 @@
22
<section class="section" id="uml-directive">
33
<h1>UML-directive<a class="headerlink" href="#uml-directive" data-bs-toggle="modal" data-bs-target="#linkReferenceModal" title="Reference this headline"></a></h1>
44

5-
artifact Foo1 {
6-
folder Foo2
7-
}
8-
9-
folder Foo3 {
10-
artifact Foo4
11-
}
12-
13-
frame Foo5 {
14-
database Foo6
15-
}
16-
17-
cloud vpc {
18-
node ec2 {
19-
stack stack
20-
}
21-
}
5+
<figure
6+
class="uml-diagram"
7+
>
8+
The PlantUML renderer is not available in test mode.
9+
</figure>
2210
</section>
2311

2412
<!-- content end -->

0 commit comments

Comments
 (0)