mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-19 00:34:24 +00:00
66 lines
1.7 KiB
PHP
66 lines
1.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Search\Utils;
|
|
|
|
use Chill\MainBundle\Search\Utils\ExtractDateFromPattern;
|
|
use DateTimeImmutable;
|
|
use PHPUnit\Framework\TestCase;
|
|
use function array_map;
|
|
|
|
/**
|
|
* @internal
|
|
* @coversNothing
|
|
*/
|
|
final class ExtractDateFromPatternTest extends TestCase
|
|
{
|
|
public function provideSubjects()
|
|
{
|
|
yield ['15/06/1981', '', 1, '1981-06-15'];
|
|
|
|
yield ['15/06/1981 30/12/1987', '', 2, '1981-06-15', '1987-12-30'];
|
|
|
|
yield ['diallo 15/06/1981', 'diallo', 1, '1981-06-15'];
|
|
|
|
yield ['diallo 31/03/1981', 'diallo', 1, '1981-03-31'];
|
|
|
|
yield ['diallo 15-06-1981', 'diallo', 1, '1981-06-15'];
|
|
|
|
yield ['diallo 1981-12-08', 'diallo', 1, '1981-12-08'];
|
|
|
|
yield ['diallo', 'diallo', 0];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideSubjects
|
|
*/
|
|
public function testExtractDate(string $subject, string $filtered, int $count, ...$datesSearched)
|
|
{
|
|
$extractor = new ExtractDateFromPattern();
|
|
$result = $extractor->extractDates($subject);
|
|
|
|
$this->assertCount($count, $result->getFound());
|
|
$this->assertEquals($filtered, $result->getFilteredSubject());
|
|
$this->assertContainsOnlyInstancesOf(DateTimeImmutable::class, $result->getFound());
|
|
|
|
$dates = array_map(
|
|
static function (DateTimeImmutable $d) {
|
|
return $d->format('Y-m-d');
|
|
},
|
|
$result->getFound()
|
|
);
|
|
|
|
foreach ($datesSearched as $date) {
|
|
$this->assertContains($date, $dates);
|
|
}
|
|
}
|
|
}
|