Skip to content
This repository was archived by the owner on Aug 22, 2023. It is now read-only.

Commit 6ebcdb5

Browse files
committed
PHPORM-33 Add tests on Query\Builder methods
1 parent 03c58ea commit 6ebcdb5

File tree

2 files changed

+125
-2
lines changed

2 files changed

+125
-2
lines changed

src/Query/Builder.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,4 +1378,28 @@ public function havingBetween($column, iterable $values, $boolean = 'and', $not
13781378
{
13791379
throw new \BadMethodCallException('This method is not supported by MongoDB');
13801380
}
1381+
1382+
/** @internal This method is not supported by MongoDB. */
1383+
public function whereIntegerInRaw($column, $values, $boolean = 'and', $not = false)
1384+
{
1385+
throw new \BadMethodCallException('This method is not supported by MongoDB');
1386+
}
1387+
1388+
/** @internal This method is not supported by MongoDB. */
1389+
public function orWhereIntegerInRaw($column, $values)
1390+
{
1391+
throw new \BadMethodCallException('This method is not supported by MongoDB');
1392+
}
1393+
1394+
/** @internal This method is not supported by MongoDB. */
1395+
public function whereIntegerNotInRaw($column, $values, $boolean = 'and')
1396+
{
1397+
throw new \BadMethodCallException('This method is not supported by MongoDB');
1398+
}
1399+
1400+
/** @internal This method is not supported by MongoDB. */
1401+
public function orWhereIntegerNotInRaw($column, $values, $boolean = 'and')
1402+
{
1403+
throw new \BadMethodCallException('This method is not supported by MongoDB');
1404+
}
13811405
}

tests/Query/BuilderTest.php

Lines changed: 101 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,32 @@ public static function provideQueryBuilderToMql(): iterable
4545
*/
4646
$date = new DateTimeImmutable('2016-07-12 15:30:00');
4747

48-
yield 'find' => [
48+
/** @see DatabaseQueryBuilderTest::testBasicSelectWithGetColumns */
49+
yield 'find all' => [
50+
['find' => [[], []]],
51+
fn (Builder $builder) => $builder->select('*'),
52+
];
53+
54+
yield 'find default null' => [
55+
['find' => [['foo' => null], []]],
56+
fn (Builder $builder) => $builder->where('foo'),
57+
];
58+
59+
yield 'find all with select' => [
60+
['find' => [[], ['projection' => ['foo' => 1, 'bar' => 1]]]],
61+
fn (Builder $builder) => $builder->select('foo', 'bar'),
62+
];
63+
64+
/** @see DatabaseQueryBuilderTest::testAddingSelects */
65+
yield 'addSelect' => [
66+
['find' => [[], ['projection' => ['foo' => 1, 'bar' => 1, 'baz' => 1, 'boom' => 1]]]],
67+
fn (Builder $builder) => $builder->select('foo')
68+
->addSelect('bar')
69+
->addSelect(['baz', 'boom'])
70+
->addSelect('bar'),
71+
];
72+
73+
yield 'find equals' => [
4974
['find' => [['foo' => 'bar'], []]],
5075
fn (Builder $builder) => $builder->where('foo', 'bar'),
5176
];
@@ -66,11 +91,59 @@ public static function provideQueryBuilderToMql(): iterable
6691
fn (Builder $builder) => $builder->where('foo', '>', $date),
6792
];
6893

69-
yield 'find in array' => [
94+
/** @see DatabaseQueryBuilderTest::testBasicWhereIns */
95+
yield 'whereIn' => [
7096
['find' => [['foo' => ['$in' => ['bar', 'baz']]], []]],
7197
fn (Builder $builder) => $builder->whereIn('foo', ['bar', 'baz']),
7298
];
7399

100+
yield 'whereIn associative array' => [
101+
['find' => [['id' => ['$in' => [45582, 2, 3]]], []]],
102+
fn (Builder $builder) => $builder->whereIn('id', ['issue' => 45582, 'id' => 2, 3]),
103+
];
104+
105+
$array = [['issue' => 45582], ['id' => 2], [3]];
106+
yield 'whereIn nested array' => [
107+
['find' => [['id' => ['$in' => $array]], []]],
108+
fn (Builder $builder) => $builder->whereIn('id', $array),
109+
];
110+
111+
yield 'orWhereIn' => [
112+
['find' => [
113+
['$or' => [
114+
['id' => 1],
115+
['id' => ['$in' => [1, 2, 3]]],
116+
]],
117+
[], // options
118+
]],
119+
fn (Builder $builder) => $builder->where('id', '=', 1)
120+
->orWhereIn('id', [1, 2, 3]),
121+
];
122+
123+
/** @see DatabaseQueryBuilderTest::testBasicWhereNotIns */
124+
yield 'whereNotIn' => [
125+
['find' => [['id' => ['$nin' => [1, 2, 3]]], []]],
126+
fn (Builder $builder) => $builder->whereNotIn('id', [1, 2, 3]),
127+
];
128+
129+
yield 'orWhereNotIn' => [
130+
['find' => [
131+
['$or' => [
132+
['id' => 1],
133+
['id' => ['$nin' => [1, 2, 3]]],
134+
]],
135+
[], // options
136+
]],
137+
fn (Builder $builder) => $builder->where('id', '=', 1)
138+
->orWhereNotIn('id', [1, 2, 3]),
139+
];
140+
141+
/** @see DatabaseQueryBuilderTest::testEmptyWhereIns */
142+
yield 'whereIn empty array' => [
143+
['find' => [['id' => ['$in' => []]], []]],
144+
fn (Builder $builder) => $builder->whereIn('id', []),
145+
];
146+
74147
yield 'find limit offset select' => [
75148
['find' => [[], ['limit' => 10, 'skip' => 5, 'projection' => ['foo' => 1, 'bar' => 1]]]],
76149
fn (Builder $builder) => $builder->limit(10)->offset(5)->select('foo', 'bar'),
@@ -452,11 +525,25 @@ function (Builder $builder) {
452525
->orWhereNotBetween('id', collect([3, 4])),
453526
];
454527

528+
/** @see DatabaseQueryBuilderTest::testBasicSelectDistinct */
455529
yield 'distinct' => [
456530
['distinct' => ['foo', [], []]],
457531
fn (Builder $builder) => $builder->distinct('foo'),
458532
];
459533

534+
yield 'select distinct' => [
535+
['distinct' => ['foo', [], []]],
536+
fn (Builder $builder) => $builder->select('foo', 'bar')
537+
->distinct(),
538+
];
539+
540+
/** @see DatabaseQueryBuilderTest::testBasicSelectDistinctOnColumns */
541+
yield 'select distinct on' => [
542+
['distinct' => ['foo', [], []]],
543+
fn (Builder $builder) => $builder->distinct('foo')
544+
->select('foo', 'bar'),
545+
];
546+
460547
yield 'groupBy' => [
461548
['aggregate' => [
462549
[['$group' => ['_id' => ['foo' => '$foo'], 'foo' => ['$last' => '$foo']]]],
@@ -562,6 +649,18 @@ public static function getEloquentMethodsNotSupported()
562649
yield 'having' => [fn (Builder $builder) => $builder->having('baz', '=', 1)];
563650
yield 'havingBetween' => [fn (Builder $builder) => $builder->havingBetween('last_login_date', ['2018-11-16', '2018-12-16'])];
564651
yield 'orHavingRaw' => [fn (Builder $builder) => $builder->orHavingRaw('user_foo < user_bar')];
652+
653+
/** @see DatabaseQueryBuilderTest::testWhereIntegerInRaw */
654+
yield 'whereIntegerInRaw' => [fn (Builder $builder) => $builder->whereIntegerInRaw('id', ['1a', 2])];
655+
656+
/** @see DatabaseQueryBuilderTest::testOrWhereIntegerInRaw */
657+
yield 'orWhereIntegerInRaw' => [fn (Builder $builder) => $builder->orWhereIntegerInRaw('id', ['1a', 2])];
658+
659+
/** @see DatabaseQueryBuilderTest::testWhereIntegerNotInRaw */
660+
yield 'whereIntegerNotInRaw' => [fn (Builder $builder) => $builder->whereIntegerNotInRaw('id', ['1a', 2])];
661+
662+
/** @see DatabaseQueryBuilderTest::testOrWhereIntegerNotInRaw */
663+
yield 'orWhereIntegerNotInRaw' => [fn (Builder $builder) => $builder->orWhereIntegerNotInRaw('id', ['1a', 2])];
565664
}
566665

567666
private static function getBuilder(): Builder

0 commit comments

Comments
 (0)