InlinesOnlyFunctionalTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace League\CommonMark\Tests\Functional\Extension\InlinesOnly;
  12. use League\CommonMark\Environment\Environment;
  13. use League\CommonMark\Extension\InlinesOnly\InlinesOnlyExtension;
  14. use League\CommonMark\MarkdownConverter;
  15. use PHPUnit\Framework\TestCase;
  16. /**
  17. * Tests the extension against sample files
  18. */
  19. final class InlinesOnlyFunctionalTest extends TestCase
  20. {
  21. private MarkdownConverter $converter;
  22. protected function setUp(): void
  23. {
  24. $environment = new Environment();
  25. $environment->addExtension(new InlinesOnlyExtension());
  26. $this->converter = new MarkdownConverter($environment);
  27. }
  28. /**
  29. * @dataProvider dataProvider
  30. *
  31. * @param string $markdown Markdown to parse
  32. * @param string $html Expected result
  33. */
  34. public function testExample(string $markdown, string $html): void
  35. {
  36. $actualResult = $this->converter->convert($markdown);
  37. $failureMessage = 'Unexpected result';
  38. $failureMessage .= "\n=== markdown ===============\n" . $markdown;
  39. $failureMessage .= "\n=== expected ===============\n" . $html;
  40. $failureMessage .= "\n=== got ====================\n" . $actualResult;
  41. $this->assertEquals($html, $actualResult, $failureMessage);
  42. }
  43. /**
  44. * @return array<array<string>>
  45. */
  46. public function dataProvider(): array
  47. {
  48. $markdown = \file_get_contents(__DIR__ . '/inlines.md');
  49. $html = \file_get_contents(__DIR__ . '/inlines.html');
  50. return [
  51. [$markdown, $html],
  52. ];
  53. }
  54. }