. */ namespace App\Tests\Doctrine; use App\Doctrine\SQLiteRegexExtension; use PHPUnit\Framework\TestCase; class SQLiteRegexExtensionTest extends TestCase { public function regexpDataProvider(): \Generator { yield [1, 'a', 'a']; yield [0, 'a', 'b']; yield [1, 'a', 'ba']; yield [1, 'a', 'ab']; yield [1, 'a', 'baa']; yield [1, '^a$', 'a']; yield [0, '^a$', 'ab']; yield [1, '^a\d+$', 'a123']; } /** * @dataProvider regexpDataProvider */ public function testRegexp(int $expected, string $pattern, string $value): void { $this->assertSame($expected, SQLiteRegexExtension::regexp($pattern, $value)); } public function fieldDataProvider(): \Generator { // Null cases yield [0, null, []]; yield [0, null, [1]]; yield [0, 42, [1, 2]]; // Ints yield [1, 1, [1]]; yield [1, 2, [2, 1]]; yield [2, 1, [2, 1]]; yield [6, 3, [2, 1, 2, 1, 2, 3]]; yield [1, 2, [2, 1, 2, 1, 2, 1, 2, 1, 2, 1]]; yield [3, 5, [2, 1, 5, 3]]; // Strings yield [1, 'a', ['a']]; yield [1, 'b', ['b', 'a']]; yield [2, 'a', ['b', 'a']]; yield [1, 'b', ['b', 'a', 'b']]; yield [6, 'c', ['b', 'a', 'b', 'a', 'b', 'c']]; } /** * @dataProvider fieldDataProvider */ public function testField(int $expected, string|int|null $value, array $array): void { $this->assertSame($expected, SQLiteRegexExtension::field($value, ...$array)); } /** * @dataProvider fieldDataProvider */ public function testField2(int $expected, string|int|null $value, array $array): void { //Should be the same as field, but with the array comma imploded $string = implode(',', $array); $this->assertSame($expected, SQLiteRegexExtension::field2($value, $string)); } }