88
99class TemplatesHelperTest extends TestCase
1010{
11+ private const DIR_HELPER_TEMPLATES = '/helper_templates ' ;
12+ const DIR_EXPECTED_TEMPLATES = '/expected_templates ' ;
13+
1114 public function testExceptionIsRaisedForInvalidTemplatesDirectory ()
1215 {
1316 $ this ->expectException (InvalidTemplatesDirectoryException::class);
@@ -16,15 +19,16 @@ public function testExceptionIsRaisedForInvalidTemplatesDirectory()
1619
1720 private function getTemplatesHelperInstance ()
1821 {
19- return new TemplatesHelper (__DIR__ . ' /helper_templates ' );
22+ return new TemplatesHelper (__DIR__ . self :: DIR_HELPER_TEMPLATES );
2023 }
2124
2225 public function testGetAllTemplates ()
2326 {
2427 $ templatesHelper = $ this ->getTemplatesHelperInstance ();
28+ $ expectedTemplatesCount = count (glob (__DIR__ . self ::DIR_HELPER_TEMPLATES . "/* " ));
2529
2630 $ returnedTemplates = $ templatesHelper ->getTemplates ('regardless of what comes here ' );
27- $ this ->assertCount (2 , $ returnedTemplates );
31+ $ this ->assertCount ($ expectedTemplatesCount , $ returnedTemplates );
2832 }
2933
3034 public function testGetAllTemplatesRegexIsPrepared ()
@@ -54,7 +58,9 @@ public function testGetMostMatchingTemplateToTextRegexIsPrepared()
5458 private function checkPreparedTemplates (array $ templatesArray ): bool
5559 {
5660 foreach ($ templatesArray as $ templatePath => $ template ) {
57- $ this ->assertStringContainsString ('(?<variable>.*) ' , $ template );
61+ $ expectedTemplate = $ this ->getExpectedTemplate ($ templatePath );
62+
63+ $ this ->assertEquals ($ expectedTemplate , $ template );
5864 $ this ->assertTrue ($ this ->isValidRegex ($ template ));
5965 }
6066
@@ -71,4 +77,16 @@ private function isValidRegex(string $pattern): bool
7177
7278 return true ;
7379 }
80+
81+ private function getExpectedTemplate (string $ templatePath )
82+ {
83+ return file_get_contents (
84+ str_replace (
85+ self ::DIR_HELPER_TEMPLATES ,
86+ self ::DIR_EXPECTED_TEMPLATES ,
87+ $ templatePath
88+ )
89+ );
90+ }
91+
7492}
0 commit comments