Skip to content

Commit

Permalink
some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Apr 16, 2024
1 parent ceafe48 commit 7c9b171
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion tests/ConditionSqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,10 @@ public function testLikeCondition(): void
};

self::assertSame([1], $findIdsLikeFx('name', 'John'));
self::assertSame([1], $findIdsLikeFx('name', 'john'));
self::assertSame([], $findIdsLikeFx('name', 'Joh'));
self::assertSame([1, 3], $findIdsLikeFx('name', 'Jo%'));
self::assertSame([2, 4, 5], $findIdsLikeFx('name', 'Jo%', true));
self::assertSame([1], $findIdsLikeFx('name', 'john'));
self::assertSame([1], $findIdsLikeFx('name', '%John%'));
self::assertSame([1], $findIdsLikeFx('name', 'Jo%n'));
self::assertSame([1], $findIdsLikeFx('name', 'J%n'));
Expand Down Expand Up @@ -580,6 +580,26 @@ public function testRegexpCondition(): void
self::markTestIncomplete('MSSQL has no REGEXP support yet');
}

$findIdsRegexFx = static function (string $field, string $value, bool $negated = false) use ($u) {
$t = (clone $u)->addCondition($field, ($negated ? 'not ' : '') . 'regexp', $value);

return array_keys($t->export(null, 'id'));
};

self::assertSame([1], $findIdsRegexFx('name', 'John'));
self::assertSame([1], $findIdsRegexFx('name', 'john'));
self::assertSame([1], $findIdsRegexFx('name', 'Joh'));
self::assertSame([1], $findIdsRegexFx('name', 'ohn'));

self::assertSame([1], $findIdsRegexFx('c', '.*1.*'));
self::assertSame([2], $findIdsRegexFx('c', '.*2000.*'));
self::assertSame([2, 3], $findIdsRegexFx('c', '.*0.*'));
self::assertSame([1], $findIdsRegexFx('c', '.*0.*', true));
self::assertSame([1, 2], $findIdsRegexFx('rating', '.*\.5$'));
self::assertSame([2], $findIdsRegexFx('rating', '^2\.5$'));

return;

$t = (clone $u)->addCondition('name', 'regexp', 'John');

Check failure on line 603 in tests/ConditionSqlTest.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Unreachable statement - code above always terminates.

Check failure on line 603 in tests/ConditionSqlTest.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Unreachable statement - code above always terminates.
self::assertCount(1, $t->export());

Expand Down

0 comments on commit 7c9b171

Please sign in to comment.