]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - tests/Wallabag/CoreBundle/Tools/UtilsTest.php
Improve reading time tests
[github/wallabag/wallabag.git] / tests / Wallabag / CoreBundle / Tools / UtilsTest.php
index 952d076d1b7c0f7a208fd561fb75a6d4da44ae11..c6ed74f07e35574e3432ab96ebd63f38ff107e23 100644 (file)
@@ -11,9 +11,9 @@ class UtilsTest extends TestCase
     /**
      * @dataProvider examples
      */
-    public function testCorrectWordsCountForDifferentLanguages($text, $expectedCount)
+    public function testCorrectWordsCountForDifferentLanguages($filename, $text, $expectedCount)
     {
-        static::assertSame((float) $expectedCount, Utils::getReadingTime($text));
+        static::assertSame((float) $expectedCount, Utils::getReadingTime($text), 'Reading time for: ' . $filename);
     }
 
     public function examples()
@@ -21,7 +21,17 @@ class UtilsTest extends TestCase
         $examples = [];
         $finder = (new Finder())->in(__DIR__ . '/samples');
         foreach ($finder->getIterator() as $file) {
-            $examples[] = [$file->getContents(), 1];
+            preg_match('/-----CONTENT-----\s*(.*?)\s*-----READING_TIME-----\s*(.*)/sx', $file->getContents(), $match);
+
+            if (3 !== \count($match)) {
+                throw new \Exception('Sample file "' . $file->getRelativePathname() . '" as wrong definition, see README.');
+            }
+
+            $examples[] = [
+                $file->getRelativePathname(),
+                $match[1], // content
+                $match[2], // reading time
+            ];
         }
 
         return $examples;