Skip to content

Commit 3cdf9ba

Browse files
committed
test: add missing regexp extract tests for SQLite
- Add regexpExtract test with full match without capture groups - Add regexpExtract test with full match (groupIndex = 0 or null) - Align SQLite regexp test coverage with MySQL/MariaDB
1 parent 6bce6d1 commit 3cdf9ba

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

tests/sqlite/HelpersTests.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -814,9 +814,16 @@ public function testRegexpHelpers(): void
814814
$this->assertStringContainsString(' ', $row['phone_formatted']);
815815
$this->assertStringNotContainsString('-', $row['phone_formatted']);
816816

817-
// Test regexpExtract - extract domain from email
818-
// Note: regexp_extract requires REGEXP extension with regexp_extract function
819-
// If not available, the query will fail with PDOException
817+
// Test regexpExtract - extract domain from email (full match without capture groups)
818+
$row = $db->find()
819+
->from('t_regexp')
820+
->select(['domain_match' => Db::regexpExtract('email', '@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}')])
821+
->where('id', $id1)
822+
->getOne();
823+
// regexp_extract returns the matched substring (full match)
824+
$this->assertStringContainsString('@example.com', $row['domain_match']);
825+
826+
// Test regexpExtract - extract domain from email with capture group
820827
$row = $db->find()
821828
->from('t_regexp')
822829
->select(['domain' => Db::regexpExtract('email', '@([a-zA-Z0-9.-]+\\.[a-zA-Z]{2,})', 1)])
@@ -825,6 +832,14 @@ public function testRegexpHelpers(): void
825832
$this->assertNotNull($row['domain']);
826833
$this->assertEquals('example.com', $row['domain']);
827834

835+
// Test regexpExtract with full match (groupIndex = 0 or null)
836+
$row = $db->find()
837+
->from('t_regexp')
838+
->select(['full_match' => Db::regexpExtract('email', '^[a-zA-Z0-9._%+-]+@')])
839+
->where('id', $id1)
840+
->getOne();
841+
$this->assertStringContainsString('user@', $row['full_match']);
842+
828843
// Test regexpMatch in WHERE clause with negation
829844
$results = $db->find()
830845
->from('t_regexp')

0 commit comments

Comments
 (0)