TextRendererTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of the league/commonmark package.
  5. *
  6. * (c) Colin O'Dell <colinodell@gmail.com>
  7. *
  8. * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
  9. * - (c) John MacFarlane
  10. *
  11. * For the full copyright and license information, please view the LICENSE
  12. * file that was distributed with this source code.
  13. */
  14. namespace League\CommonMark\Tests\Unit\Renderer\Inline;
  15. use League\CommonMark\Exception\InvalidArgumentException;
  16. use League\CommonMark\Node\Inline\AbstractInline;
  17. use League\CommonMark\Node\Inline\Text;
  18. use League\CommonMark\Renderer\Inline\TextRenderer;
  19. use League\CommonMark\Tests\Unit\Renderer\FakeChildNodeRenderer;
  20. use PHPUnit\Framework\TestCase;
  21. final class TextRendererTest extends TestCase
  22. {
  23. private TextRenderer $renderer;
  24. protected function setUp(): void
  25. {
  26. $this->renderer = new TextRenderer();
  27. }
  28. public function testRender(): void
  29. {
  30. $inline = new Text('foo bar');
  31. $fakeRenderer = new FakeChildNodeRenderer();
  32. $result = $this->renderer->render($inline, $fakeRenderer);
  33. $this->assertIsString($result);
  34. $this->assertStringContainsString('foo bar', $result);
  35. }
  36. public function testRenderWithInvalidType(): void
  37. {
  38. $this->expectException(InvalidArgumentException::class);
  39. $inline = $this->getMockForAbstractClass(AbstractInline::class);
  40. $fakeRenderer = new FakeChildNodeRenderer();
  41. $this->renderer->render($inline, $fakeRenderer);
  42. }
  43. }