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

Commit 9bda511

Browse files
committed
PHPORM-33 Add tests on Query\Builder methods
1 parent cf103ba commit 9bda511

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
@@ -1386,4 +1386,28 @@ public function havingBetween($column, iterable $values, $boolean = 'and', $not
13861386
{
13871387
throw new \BadMethodCallException('This method is not supported by MongoDB');
13881388
}
1389+
1390+
/** @internal This method is not supported by MongoDB. */
1391+
public function whereIntegerInRaw($column, $values, $boolean = 'and', $not = false)
1392+
{
1393+
throw new \BadMethodCallException('This method is not supported by MongoDB');
1394+
}
1395+
1396+
/** @internal This method is not supported by MongoDB. */
1397+
public function orWhereIntegerInRaw($column, $values)
1398+
{
1399+
throw new \BadMethodCallException('This method is not supported by MongoDB');
1400+
}
1401+
1402+
/** @internal This method is not supported by MongoDB. */
1403+
public function whereIntegerNotInRaw($column, $values, $boolean = 'and')
1404+
{
1405+
throw new \BadMethodCallException('This method is not supported by MongoDB');
1406+
}
1407+
1408+
/** @internal This method is not supported by MongoDB. */
1409+
public function orWhereIntegerNotInRaw($column, $values, $boolean = 'and')
1410+
{
1411+
throw new \BadMethodCallException('This method is not supported by MongoDB');
1412+
}
13891413
}

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
];
@@ -55,11 +80,59 @@ public static function provideQueryBuilderToMql(): iterable
5580
fn (Builder $builder) => $builder->where('foo', '>', $date),
5681
];
5782

58-
yield 'find in array' => [
83+
/** @see DatabaseQueryBuilderTest::testBasicWhereIns */
84+
yield 'whereIn' => [
5985
['find' => [['foo' => ['$in' => ['bar', 'baz']]], []]],
6086
fn (Builder $builder) => $builder->whereIn('foo', ['bar', 'baz']),
6187
];
6288

89+
yield 'whereIn associative array' => [
90+
['find' => [['id' => ['$in' => [45582, 2, 3]]], []]],
91+
fn (Builder $builder) => $builder->whereIn('id', ['issue' => 45582, 'id' => 2, 3]),
92+
];
93+
94+
$array = [['issue' => 45582], ['id' => 2], [3]];
95+
yield 'whereIn nested array' => [
96+
['find' => [['id' => ['$in' => $array]], []]],
97+
fn (Builder $builder) => $builder->whereIn('id', $array),
98+
];
99+
100+
yield 'orWhereIn' => [
101+
['find' => [
102+
['$or' => [
103+
['id' => 1],
104+
['id' => ['$in' => [1, 2, 3]]],
105+
]],
106+
[], // options
107+
]],
108+
fn (Builder $builder) => $builder->where('id', '=', 1)
109+
->orWhereIn('id', [1, 2, 3]),
110+
];
111+
112+
/** @see DatabaseQueryBuilderTest::testBasicWhereNotIns */
113+
yield 'whereNotIn' => [
114+
['find' => [['id' => ['$nin' => [1, 2, 3]]], []]],
115+
fn (Builder $builder) => $builder->whereNotIn('id', [1, 2, 3]),
116+
];
117+
118+
yield 'orWhereNotIn' => [
119+
['find' => [
120+
['$or' => [
121+
['id' => 1],
122+
['id' => ['$nin' => [1, 2, 3]]],
123+
]],
124+
[], // options
125+
]],
126+
fn (Builder $builder) => $builder->where('id', '=', 1)
127+
->orWhereNotIn('id', [1, 2, 3]),
128+
];
129+
130+
/** @see DatabaseQueryBuilderTest::testEmptyWhereIns */
131+
yield 'whereIn empty array' => [
132+
['find' => [['id' => ['$in' => []]], []]],
133+
fn (Builder $builder) => $builder->whereIn('id', []),
134+
];
135+
63136
yield 'find limit offset select' => [
64137
['find' => [[], ['limit' => 10, 'skip' => 5, 'projection' => ['foo' => 1, 'bar' => 1]]]],
65138
fn (Builder $builder) => $builder->limit(10)->offset(5)->select('foo', 'bar'),
@@ -251,11 +324,25 @@ function (Builder $builder) {
251324
->orWhereNotBetween('id', collect([3, 4])),
252325
];
253326

327+
/** @see DatabaseQueryBuilderTest::testBasicSelectDistinct */
254328
yield 'distinct' => [
255329
['distinct' => ['foo', [], []]],
256330
fn (Builder $builder) => $builder->distinct('foo'),
257331
];
258332

333+
yield 'select distinct' => [
334+
['distinct' => ['foo', [], []]],
335+
fn (Builder $builder) => $builder->select('foo', 'bar')
336+
->distinct(),
337+
];
338+
339+
/** @see DatabaseQueryBuilderTest::testBasicSelectDistinctOnColumns */
340+
yield 'select distinct on' => [
341+
['distinct' => ['foo', [], []]],
342+
fn (Builder $builder) => $builder->distinct('foo')
343+
->select('foo', 'bar'),
344+
];
345+
259346
yield 'groupBy' => [
260347
['aggregate' => [
261348
[['$group' => ['_id' => ['foo' => '$foo'], 'foo' => ['$last' => '$foo']]]],
@@ -361,6 +448,18 @@ public static function getEloquentMethodsNotSupported()
361448
yield 'having' => [fn (Builder $builder) => $builder->having('baz', '=', 1)];
362449
yield 'havingBetween' => [fn (Builder $builder) => $builder->havingBetween('last_login_date', ['2018-11-16', '2018-12-16'])];
363450
yield 'orHavingRaw' => [fn (Builder $builder) => $builder->orHavingRaw('user_foo < user_bar')];
451+
452+
/** @see DatabaseQueryBuilderTest::testWhereIntegerInRaw */
453+
yield 'whereIntegerInRaw' => [fn (Builder $builder) => $builder->whereIntegerInRaw('id', ['1a', 2])];
454+
455+
/** @see DatabaseQueryBuilderTest::testOrWhereIntegerInRaw */
456+
yield 'orWhereIntegerInRaw' => [fn (Builder $builder) => $builder->orWhereIntegerInRaw('id', ['1a', 2])];
457+
458+
/** @see DatabaseQueryBuilderTest::testWhereIntegerNotInRaw */
459+
yield 'whereIntegerNotInRaw' => [fn (Builder $builder) => $builder->whereIntegerNotInRaw('id', ['1a', 2])];
460+
461+
/** @see DatabaseQueryBuilderTest::testOrWhereIntegerNotInRaw */
462+
yield 'orWhereIntegerNotInRaw' => [fn (Builder $builder) => $builder->orWhereIntegerNotInRaw('id', ['1a', 2])];
364463
}
365464

366465
private static function getBuilder(): Builder

0 commit comments

Comments
 (0)