Skip to content

Commit 2938f8b

Browse files
authored
Merge pull request #979 from phpDocumentor/backport/973
[TASK] Add test to prove proper error handling for plantuml
2 parents 0fadca0 + a504ecd commit 2938f8b

File tree

8 files changed

+65
-11
lines changed

8 files changed

+65
-11
lines changed

packages/guides-graphs/src/Graphs/Renderer/PlantumlServerRenderer.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use phpDocumentor\Guides\RenderContext;
1717
use Psr\Log\LoggerInterface;
18+
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
1819
use Symfony\Contracts\HttpClient\HttpClientInterface;
1920

2021
use function Jawira\PlantUml\encodep;
@@ -35,24 +36,36 @@ public function render(RenderContext $renderContext, string $diagram): string|nu
3536

3637
$url = $this->plantumlServerUrl . '/svg/' . $encodedDiagram;
3738

38-
$response = $this->httpClient->request(
39-
'GET',
40-
$url,
41-
);
39+
try {
40+
$response = $this->httpClient->request(
41+
'GET',
42+
$url,
43+
);
44+
45+
if ($response->getStatusCode() !== 200) {
46+
$this->logger->warning(
47+
sprintf(
48+
'Failed to render diagram using url: %s. The server returned status code %s. ',
49+
$url,
50+
$response->getStatusCode(),
51+
),
52+
$renderContext->getLoggerInformation(),
53+
);
4254

43-
if ($response->getStatusCode() !== 200) {
55+
return null;
56+
}
57+
58+
return $response->getContent();
59+
} catch (TransportExceptionInterface) {
4460
$this->logger->warning(
4561
sprintf(
46-
'Failed to render diagram using url: %s. The server returned status code %s. ',
62+
'Failed to render diagram using url: %s. ',
4763
$url,
48-
$response->getStatusCode(),
4964
),
5065
$renderContext->getLoggerInformation(),
5166
);
5267

5368
return null;
5469
}
55-
56-
return $response->getContent();
5770
}
5871
}

packages/guides-restructured-text/tests/unit/Parser/Productions/RuleTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected function givenInlineMarkupRule(): InlineMarkupRule
6767
$inlineTokenParser->method('parse')->willReturnCallback(
6868
static fn (string $arg): InlineCompoundNode => new InlineCompoundNode([
6969
new PlainTextInlineNode($arg),
70-
])
70+
]),
7171
);
7272

7373
return new InlineMarkupRule($inlineTokenParser);

packages/guides-restructured-text/tests/unit/Parser/Productions/SectionRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ private function getInlineTokenParserMock(): InlineParser
182182
{
183183
$inlineTokenParser = $this->createMock(InlineParser::class);
184184
$inlineTokenParser->method('parse')->willReturnCallback(
185-
static fn (string $arg): InlineCompoundNode => InlineCompoundNode::getPlainTextInlineNode($arg)
185+
static fn (string $arg): InlineCompoundNode => InlineCompoundNode::getPlainTextInlineNode($arg),
186186
);
187187

188188
return $inlineTokenParser;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- content start -->
2+
<div class="section" id="uml-directive">
3+
<h1>Uml Directive</h1>
4+
<figure
5+
class="uml-diagram"
6+
style="width: 1000" ><figcaption>Figure 1-1: Application flow</figcaption></figure>
7+
<figure
8+
class="uml-diagram"
9+
style="width: 1000" ><figcaption>Figure 1-1: Application flow</figcaption></figure>
10+
</div>
11+
<!-- content end -->
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
app.WARNING: Failed to render diagram using url: https://this-does-not-exist-phpdoc.com/svg/u-9ApaaiBbRGjLF8Byb8BN86ywmKSbEBYnFJKxcu0000. {"rst-file":"index"} []
2+
app.WARNING: Failed to render diagram using url: https://this-does-not-exist-phpdoc.com/svg/u-9ApaaiBbRGjLF8Byb8BN86ywmKSbEBYnFJKxcu0000. {"rst-file":"index"} []
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@startuml
2+
3+
class -> otherClass : message
4+
5+
@enduml
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<guides xmlns="https://www.phpdoc.org/guides"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="https://www.phpdoc.org/guides packages/guides-cli/resources/schema/guides.xsd">
5+
<extension class="phpDocumentor\Guides\Graphs">
6+
<renderer>plantuml-server</renderer>
7+
<plantuml-server>https://this-does-not-exist-phpdoc.com</plantuml-server>
8+
</extension>
9+
</guides>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
==============
2+
Uml Directive
3+
==============
4+
5+
.. uml:: /Plantuml/something.plantuml
6+
:align: center
7+
:caption: Figure 1-1: Application flow
8+
:width: 1000
9+
10+
11+
.. uml:: Plantuml/something.plantuml
12+
:align: center
13+
:caption: Figure 1-1: Application flow
14+
:width: 1000

0 commit comments

Comments
 (0)