|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +use Illuminate\Database\Query\Expression; |
| 6 | +use Tpetry\QueryExpressions\Function\Comparison\StrListContains; |
| 7 | + |
| 8 | +it('can check for existence of a column within a column string list') |
| 9 | + ->expect(new StrListContains('haystack', 'needle')) |
| 10 | + ->toBeExecutable(['haystack varchar(255)', 'needle varchar(255)'], options: [ |
| 11 | + 'sqlsrv' => ['position' => 'where'], |
| 12 | + ]) |
| 13 | + ->toBeMysql('FIND_IN_SET(`needle`, `haystack`) > 0') |
| 14 | + ->toBePgsql("(\"haystack\" like \"needle\" or \"haystack\" like ((\"needle\")||',%') or \"haystack\" like ('%,'||(\"needle\")||',%') or \"haystack\" like ('%,'||(\"needle\")))") |
| 15 | + ->toBeSqlite("(\"haystack\" like \"needle\" or \"haystack\" like ((\"needle\")||',%') or \"haystack\" like ('%,'||(\"needle\")||',%') or \"haystack\" like ('%,'||(\"needle\")))") |
| 16 | + ->toBeSqlsrv("([haystack] like [needle] or [haystack] like concat([needle],',%') or [haystack] like concat('%,',[needle],',%') or [haystack] like concat('%,',[needle]))"); |
| 17 | + |
| 18 | +it('can check for existence of an expression within an expression string list') |
| 19 | + ->expect(new StrListContains(new Expression("'a,b,c'"), new Expression("'a'"))) |
| 20 | + ->toBeExecutable(options: [ |
| 21 | + 'sqlsrv' => ['position' => 'where'], |
| 22 | + ]) |
| 23 | + ->toBeMysql("FIND_IN_SET('a', 'a,b,c') > 0") |
| 24 | + ->toBePgsql("('a,b,c' like 'a' or 'a,b,c' like (('a')||',%') or 'a,b,c' like ('%,'||('a')||',%') or 'a,b,c' like ('%,'||('a')))") |
| 25 | + ->toBeSqlite("('a,b,c' like 'a' or 'a,b,c' like (('a')||',%') or 'a,b,c' like ('%,'||('a')||',%') or 'a,b,c' like ('%,'||('a')))") |
| 26 | + ->toBeSqlsrv("('a,b,c' like 'a' or 'a,b,c' like concat('a',',%') or 'a,b,c' like concat('%,','a',',%') or 'a,b,c' like concat('%,','a'))"); |
| 27 | + |
| 28 | +it('can check for existence of a column within an expression string list') |
| 29 | + ->expect(new StrListContains(new Expression("'a,b,c'"), 'needle')) |
| 30 | + ->toBeExecutable(['needle varchar(255)'], options: [ |
| 31 | + 'sqlsrv' => ['position' => 'where'], |
| 32 | + ]) |
| 33 | + ->toBeMysql("FIND_IN_SET(`needle`, 'a,b,c') > 0") |
| 34 | + ->toBePgsql("('a,b,c' like \"needle\" or 'a,b,c' like ((\"needle\")||',%') or 'a,b,c' like ('%,'||(\"needle\")||',%') or 'a,b,c' like ('%,'||(\"needle\")))") |
| 35 | + ->toBeSqlite("('a,b,c' like \"needle\" or 'a,b,c' like ((\"needle\")||',%') or 'a,b,c' like ('%,'||(\"needle\")||',%') or 'a,b,c' like ('%,'||(\"needle\")))") |
| 36 | + ->toBeSqlsrv("('a,b,c' like [needle] or 'a,b,c' like concat([needle],',%') or 'a,b,c' like concat('%,',[needle],',%') or 'a,b,c' like concat('%,',[needle]))"); |
| 37 | + |
| 38 | +it('can check for existence of an expression within a column string list') |
| 39 | + ->expect(new StrListContains('haystack', new Expression("'a'"))) |
| 40 | + ->toBeExecutable(['haystack varchar(255)'], options: [ |
| 41 | + 'sqlsrv' => ['position' => 'where'], |
| 42 | + ]) |
| 43 | + ->toBeMysql("FIND_IN_SET('a', `haystack`) > 0") |
| 44 | + ->toBePgsql("(\"haystack\" like 'a' or \"haystack\" like (('a')||',%') or \"haystack\" like ('%,'||('a')||',%') or \"haystack\" like ('%,'||('a')))") |
| 45 | + ->toBeSqlite("(\"haystack\" like 'a' or \"haystack\" like (('a')||',%') or \"haystack\" like ('%,'||('a')||',%') or \"haystack\" like ('%,'||('a')))") |
| 46 | + ->toBeSqlsrv("([haystack] like 'a' or [haystack] like concat('a',',%') or [haystack] like concat('%,','a',',%') or [haystack] like concat('%,','a'))"); |
0 commit comments