1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-09-15 18:57:05 +00:00

Improve reading time tests

This commit is contained in:
Jeremy Benoist 2019-01-04 11:22:43 +01:00
parent 5becf260fa
commit 35983eb9bb
No known key found for this signature in database
GPG key ID: BCA73962457ACC3C
9 changed files with 41 additions and 9 deletions

View 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;