]> git.immae.eu Git - github/wallabag/wallabag.git/blame - tests/Wallabag/CoreBundle/Tools/UtilsTest.php
Improve reading time tests
[github/wallabag/wallabag.git] / tests / Wallabag / CoreBundle / Tools / UtilsTest.php
CommitLineData
5b6888b1
AK
1<?php
2
3namespace Tests\Wallabag\CoreBundle\Tools;
4
bd91bd5c 5use PHPUnit\Framework\TestCase;
5b6888b1
AK
6use Symfony\Component\Finder\Finder;
7use Wallabag\CoreBundle\Tools\Utils;
8
bd91bd5c 9class UtilsTest extends TestCase
5b6888b1
AK
10{
11 /**
12 * @dataProvider examples
13 */
35983eb9 14 public function testCorrectWordsCountForDifferentLanguages($filename, $text, $expectedCount)
5b6888b1 15 {
35983eb9 16 static::assertSame((float) $expectedCount, Utils::getReadingTime($text), 'Reading time for: ' . $filename);
5b6888b1
AK
17 }
18
19 public function examples()
20 {
21 $examples = [];
f808b016 22 $finder = (new Finder())->in(__DIR__ . '/samples');
5b6888b1 23 foreach ($finder->getIterator() as $file) {
35983eb9
JB
24 preg_match('/-----CONTENT-----\s*(.*?)\s*-----READING_TIME-----\s*(.*)/sx', $file->getContents(), $match);
25
26 if (3 !== \count($match)) {
27 throw new \Exception('Sample file "' . $file->getRelativePathname() . '" as wrong definition, see README.');
28 }
29
30 $examples[] = [
31 $file->getRelativePathname(),
32 $match[1], // content
33 $match[2], // reading time
34 ];
5b6888b1
AK
35 }
36
37 return $examples;
38 }
39}