wallabag/tests/Wallabag/CoreBundle/Tools/UtilsTest.php

40 lines
1.1 KiB
PHP
Raw Normal View History

<?php
namespace Tests\Wallabag\CoreBundle\Tools;
2017-12-16 21:17:42 +00:00
use PHPUnit\Framework\TestCase;
use Symfony\Component\Finder\Finder;
use Wallabag\CoreBundle\Tools\Utils;
2017-12-16 21:17:42 +00:00
class UtilsTest extends TestCase
{
/**
* @dataProvider examples
*/
2019-01-04 10:22:43 +00:00
public function testCorrectWordsCountForDifferentLanguages($filename, $text, $expectedCount)
{
2019-01-04 10:22:43 +00:00
static::assertSame((float) $expectedCount, Utils::getReadingTime($text), 'Reading time for: ' . $filename);
}
public function examples()
{
$examples = [];
2017-07-01 07:52:38 +00:00
$finder = (new Finder())->in(__DIR__ . '/samples');
foreach ($finder->getIterator() as $file) {
2019-01-04 10:22:43 +00:00
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;
}
}