From 35983eb9bbbf78041ff9f6679ca345850f41c5f1 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 4 Jan 2019 11:22:43 +0100 Subject: Improve reading time tests --- tests/Wallabag/CoreBundle/Tools/UtilsTest.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'tests/Wallabag/CoreBundle/Tools/UtilsTest.php') diff --git a/tests/Wallabag/CoreBundle/Tools/UtilsTest.php b/tests/Wallabag/CoreBundle/Tools/UtilsTest.php index 952d076d..c6ed74f0 100644 --- a/tests/Wallabag/CoreBundle/Tools/UtilsTest.php +++ b/tests/Wallabag/CoreBundle/Tools/UtilsTest.php @@ -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; -- cgit v1.2.3