Skip to content

[TASK] Add test to prove proper error handling for plantuml #979

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use phpDocumentor\Guides\RenderContext;
use Psr\Log\LoggerInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;

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

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

$response = $this->httpClient->request(
'GET',
$url,
);
try {
$response = $this->httpClient->request(
'GET',
$url,
);

if ($response->getStatusCode() !== 200) {
$this->logger->warning(
sprintf(
'Failed to render diagram using url: %s. The server returned status code %s. ',
$url,
$response->getStatusCode(),
),
$renderContext->getLoggerInformation(),
);

if ($response->getStatusCode() !== 200) {
return null;
}

return $response->getContent();
} catch (TransportExceptionInterface) {
$this->logger->warning(
sprintf(
'Failed to render diagram using url: %s. The server returned status code %s. ',
'Failed to render diagram using url: %s. ',
$url,
$response->getStatusCode(),
),
$renderContext->getLoggerInformation(),
);

return null;
}

return $response->getContent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected function givenInlineMarkupRule(): InlineMarkupRule
$inlineTokenParser->method('parse')->willReturnCallback(
static fn (string $arg): InlineCompoundNode => new InlineCompoundNode([
new PlainTextInlineNode($arg),
])
]),
);

return new InlineMarkupRule($inlineTokenParser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private function getInlineTokenParserMock(): InlineParser
{
$inlineTokenParser = $this->createMock(InlineParser::class);
$inlineTokenParser->method('parse')->willReturnCallback(
static fn (string $arg): InlineCompoundNode => InlineCompoundNode::getPlainTextInlineNode($arg)
static fn (string $arg): InlineCompoundNode => InlineCompoundNode::getPlainTextInlineNode($arg),
);

return $inlineTokenParser;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- content start -->
<div class="section" id="uml-directive">
<h1>Uml Directive</h1>
<figure
class="uml-diagram"
style="width: 1000" ><figcaption>Figure 1-1: Application flow</figcaption></figure>
<figure
class="uml-diagram"
style="width: 1000" ><figcaption>Figure 1-1: Application flow</figcaption></figure>
</div>
<!-- content end -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
app.WARNING: Failed to render diagram using url: https://this-does-not-exist-phpdoc.com/svg/u-9ApaaiBbRGjLF8Byb8BN86ywmKSbEBYnFJKxcu0000. {"rst-file":"index"} []
app.WARNING: Failed to render diagram using url: https://this-does-not-exist-phpdoc.com/svg/u-9ApaaiBbRGjLF8Byb8BN86ywmKSbEBYnFJKxcu0000. {"rst-file":"index"} []
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@startuml

class -> otherClass : message

@enduml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<guides xmlns="https://www.phpdoc.org/guides"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.phpdoc.org/guides packages/guides-cli/resources/schema/guides.xsd">
<extension class="phpDocumentor\Guides\Graphs">
<renderer>plantuml-server</renderer>
<plantuml-server>https://this-does-not-exist-phpdoc.com</plantuml-server>
</extension>
</guides>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
==============
Uml Directive
==============

.. uml:: /Plantuml/something.plantuml
:align: center
:caption: Figure 1-1: Application flow
:width: 1000


.. uml:: Plantuml/something.plantuml
:align: center
:caption: Figure 1-1: Application flow
:width: 1000