Parsedown = new Parsedown(new State([ StrictMode::enabled(), InlineTypes::initial()->removing([Url::class]), ])); parent::__construct($name, $data, $dataName); } /** * @dataProvider data * @param int $_ * @param string $__ * @param string $markdown * @param string $expectedHtml * @return void * @throws \PHPUnit\Framework\AssertionFailedError * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException */ public function testExample($_, $__, $markdown, $expectedHtml) { $actualHtml = $this->Parsedown->text($markdown); $this->assertEquals($expectedHtml, $actualHtml); } /** * @return string * @throws \PHPUnit\Framework\AssertionFailedError */ public function getSpec() { $specPath = __DIR__ .'/'.self::SPEC_LOCAL_CACHE; if ( \is_file($specPath) && \time() - \filemtime($specPath) < self::SPEC_CACHE_SECONDS ) { $spec = \file_get_contents($specPath); } else { $spec = \file_get_contents(self::SPEC_URL); \file_put_contents($specPath, $spec); } if ($spec === false) { $this->fail('Unable to load CommonMark spec from ' . self::SPEC_URL); } return $spec; } /** * @return array * @throws \PHPUnit\Framework\AssertionFailedError */ public function data() { $spec = $this->getSpec(); $spec = \str_replace("\r\n", "\n", $spec); /** @var string */ $spec = \strstr($spec, '', true); $matches = []; \preg_match_all('/^`{32} example\n((?s).*?)\n\.\n(?:|((?s).*?)\n)`{32}$|^#{1,6} *(.*?)$/m', $spec, $matches, \PREG_SET_ORDER); $data = []; $currentId = 0; $currentSection = ''; /** @var array{0: string, 1: string, 2?: string, 3?: string} $match */ foreach ($matches as $match) { if (isset($match[3])) { $currentSection = $match[3]; } else { $currentId++; $markdown = \str_replace('→', "\t", $match[1]); $expectedHtml = isset($match[2]) ? \str_replace('→', "\t", $match[2]) : ''; $data[$currentId] = [ 'id' => $currentId, 'section' => $currentSection, 'markdown' => $markdown, 'expectedHtml' => $expectedHtml ]; } } return $data; } }