3 namespace Tests\Wallabag\CoreBundle\Tools
;
5 use PHPUnit\Framework\TestCase
;
6 use Symfony\Component\Finder\Finder
;
7 use Wallabag\CoreBundle\Tools\Utils
;
9 class UtilsTest
extends TestCase
12 * @dataProvider examples
14 public function testCorrectWordsCountForDifferentLanguages($filename, $text, $expectedCount)
16 static::assertSame((float) $expectedCount, Utils
::getReadingTime($text), 'Reading time for: ' . $filename);
19 public function examples()
22 $finder = (new Finder())->in(__DIR__
. '/samples');
23 foreach ($finder->getIterator() as $file) {
24 preg_match('/-----CONTENT-----\s*(.*?)\s*-----READING_TIME-----\s*(.*)/sx', $file->getContents(), $match);
26 if (3 !== \
count($match)) {
27 throw new \
Exception('Sample file "' . $file->getRelativePathname() . '" as wrong definition, see README.');
31 $file->getRelativePathname(),
33 $match[2], // reading time