Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyholm committed May 13, 2021
1 parent 7a5b6c6 commit 9dce7f0
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public function asString(): string
{
$output = $this->message;
if ($this->getFile() !== null) {
$output .= sprintf(' in "%s"', $this->file);
$output .= sprintf(' in file "%s"', $this->file);

if ($this->line !== null) {
$output .= sprintf(' at line "%d"', $this->line);
$output .= sprintf(' at line %d', $this->line);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Parser/DocumentParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ private function flush(): void
);
} catch (Throwable $e) {
$this->environment->getErrorManager()->error(
sprintf('Error while processing "%s" directive: %s', $currentDirective->getName(), $e->getMessage()),
sprintf('Error while processing "%s" directive: "%s"', $currentDirective->getName(), $e->getMessage()),
$this->environment->getCurrentFileName(),
$this->currentLineNumber ?? null,
$e
Expand Down
4 changes: 2 additions & 2 deletions tests/BuilderWithErrors/BuilderWithErrorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public function testNoContentDirectiveError(): void
, $bodyHtml);

self::assertEquals(
['Error while processing "note" directive in "no_content_directive" around line 6: Content expected, none found.'],
$this->builder->getErrorManager()->getErrors()
'Error while processing "note" directive: "Content expected, none found." in file "no_content_directive" at line 6',
$this->builder->getErrorManager()->getErrors()[0]->asString()
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/EnvironmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function getMissingSectionTests(): iterable
];

yield 'with_current_filename' => [
'Unknown reference section "doc" in "current_doc_filename"',
'Unknown reference section "doc" in file "current_doc_filename"',
'current_doc_filename',
];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/tests/main-directive/main-directive.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Exception: Exception
Unknown directive: "latex-main" for line ".. latex-main::"
Unknown directive "latex-main": .. latex-main::
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
forgot a blank line

does not appear to be a complete table row
in file (unknown)

+-----------+----------------+----------------------------+
| Type | Options | Description |
Expand All @@ -13,4 +12,4 @@
+-----------+----------------+----------------------------+
| currency | currency (m) | A currency string |
+-----------+----------------+----------------------------+
forgot a blank line
forgot a blank line in file "(unknown)"
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
Exception: Exception
Malformed table: content "l" appears in the "gap" on row "Second row Other colllOther col"
in file (unknown)

=========== ========== =========
First col Second col Third col
Second row Other colllOther col
Third row Other col Last col
=========== ========== =========
=========== ========== ========= in file "(unknown)"
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Exception: Exception
Unknown directive: "unknown-directive" for line ".. unknown-directive::"
Unknown directive "unknown-directive": .. unknown-directive::
10 changes: 8 additions & 2 deletions tests/Parser/DocumentParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\Common\EventManager;
use Doctrine\RST\Directives\Directive;
use Doctrine\RST\Environment;
use Doctrine\RST\ErrorManager;
use Doctrine\RST\NodeFactory\NodeFactory;
use Doctrine\RST\Parser;
use Doctrine\RST\Parser\DocumentParser;
Expand All @@ -22,6 +23,7 @@ public function testErrorWhenDirectiveThrowsException(): void
$nodeFactory = $this->createMock(NodeFactory::class);
$eventManager = $this->createMock(EventManager::class);
$codeBlockDirective = $this->createMock(Directive::class);
$errorManager = $this->createMock(ErrorManager::class);

$docParser = new DocumentParser(
$parser,
Expand All @@ -41,8 +43,12 @@ public function testErrorWhenDirectiveThrowsException(): void
->willReturn('code-block-name');

$environment->expects(self::once())
->method('addError')
->with('Error while processing "code-block-name" directive: Invalid something something!');
->method('getErrorManager')
->willReturn($errorManager);

$errorManager->expects(self::once())
->method('error')
->with('Error while processing "code-block-name" directive: "Invalid something something!"');

$docParser->parse('.. code-block:: php');
}
Expand Down

0 comments on commit 9dce7f0

Please sign in to comment.