. */ 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 { yield [ // Null cases 0, null, [], 0, null, [1], 0, 42, [1, 2], // Ints 1, 1, [1], 1, 2, [2, 1], 2, 1, [2, 1], 2, 2, [2, 1, 2], 5, 3, [2, 1, 2, 1, 2, 3], 1, 2, [2, 1, 2, 1, 2, 1, 2, 1, 2, 1], // Strings 1, 'a', ['a'], 1, 'b', ['b', 'a'], 2, 'a', ['b', 'a'], 2, 'b', ['b', 'a', 'b'], 5, '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)); } }