Skip to content

Commit e3942be

Browse files
committed
fix 100% code coverage
1 parent df277c9 commit e3942be

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/TagEngine/TagEngineTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace LordSimal\CustomHtmlElements\Test\TagEngine;
55

6+
use LordSimal\CustomHtmlElements\Error\RegexException;
67
use LordSimal\CustomHtmlElements\TagEngine;
78
use PHPUnit\Framework\TestCase;
89

@@ -22,6 +23,7 @@ public function testGetInstance(): void
2223
'tag_directories' => [
2324
dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Tags' . DIRECTORY_SEPARATOR,
2425
dirname(__DIR__) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR,
26+
dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Tags' . DIRECTORY_SEPARATOR,
2527
],
2628
];
2729
$instance = TagEngine::getInstance($options);
@@ -30,4 +32,32 @@ public function testGetInstance(): void
3032
$sameInstance = TagEngine::getInstance();
3133
$this->assertSame($instance, $sameInstance);
3234
}
35+
36+
public function testThrowsRegexException(): void
37+
{
38+
$options = [
39+
'tag_directories' => [
40+
dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Tags' . DIRECTORY_SEPARATOR,
41+
dirname(__DIR__) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR,
42+
],
43+
];
44+
$instance = TagEngine::getInstance($options);
45+
46+
$test = '';
47+
$pcreLimit = 100000;
48+
for($i = 0; $i < $pcreLimit; $i++) {
49+
$test .= '<c-tag>Test';
50+
}
51+
for($i = 0; $i < $pcreLimit; $i++) {
52+
$test .= '</c-tag>';
53+
}
54+
55+
try {
56+
$instance->parse($test);
57+
} catch (RegexException $e) {
58+
$this->assertEquals('Backtrack limit was exhausted', $e->getMessage());
59+
$this->assertNotEmpty($e->getRegex());
60+
$this->assertNotEmpty($e->getSource());
61+
}
62+
}
3363
}

0 commit comments

Comments
 (0)