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

Commit 655949d

Browse files
committed
PHPORM-33 Add tests on Query\Builder methods
1 parent 52c0ea3 commit 655949d

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
@@ -1376,4 +1376,28 @@ public function havingBetween($column, iterable $values, $boolean = 'and', $not
13761376
{
13771377
throw new \BadMethodCallException('This method is not supported by MongoDB');
13781378
}
1379+
1380+
/** @internal This method is not supported by MongoDB. */
1381+
public function whereIntegerInRaw($column, $values, $boolean = 'and', $not = false)
1382+
{
1383+
throw new \BadMethodCallException('This method is not supported by MongoDB');
1384+
}
1385+
1386+
/** @internal This method is not supported by MongoDB. */
1387+
public function orWhereIntegerInRaw($column, $values)
1388+
{
1389+
throw new \BadMethodCallException('This method is not supported by MongoDB');
1390+
}
1391+
1392+
/** @internal This method is not supported by MongoDB. */
1393+
public function whereIntegerNotInRaw($column, $values, $boolean = 'and')
1394+
{
1395+
throw new \BadMethodCallException('This method is not supported by MongoDB');
1396+
}
1397+
1398+
/** @internal This method is not supported by MongoDB. */
1399+
public function orWhereIntegerNotInRaw($column, $values, $boolean = 'and')
1400+
{
1401+
throw new \BadMethodCallException('This method is not supported by MongoDB');
1402+
}
13791403
}

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'),
@@ -439,11 +512,25 @@ function (Builder $builder) {
439512
->orWhereNotBetween('id', collect([3, 4])),
440513
];
441514

515+
/** @see DatabaseQueryBuilderTest::testBasicSelectDistinct */
442516
yield 'distinct' => [
443517
['distinct' => ['foo', [], []]],
444518
fn (Builder $builder) => $builder->distinct('foo'),
445519
];
446520

521+
yield 'select distinct' => [
522+
['distinct' => ['foo', [], []]],
523+
fn (Builder $builder) => $builder->select('foo', 'bar')
524+
->distinct(),
525+
];
526+
527+
/** @see DatabaseQueryBuilderTest::testBasicSelectDistinctOnColumns */
528+
yield 'select distinct on' => [
529+
['distinct' => ['foo', [], []]],
530+
fn (Builder $builder) => $builder->distinct('foo')
531+
->select('foo', 'bar'),
532+
];
533+
447534
yield 'groupBy' => [
448535
['aggregate' => [
449536
[['$group' => ['_id' => ['foo' => '$foo'], 'foo' => ['$last' => '$foo']]]],
@@ -549,6 +636,18 @@ public static function getEloquentMethodsNotSupported()
549636
yield 'having' => [fn (Builder $builder) => $builder->having('baz', '=', 1)];
550637
yield 'havingBetween' => [fn (Builder $builder) => $builder->havingBetween('last_login_date', ['2018-11-16', '2018-12-16'])];
551638
yield 'orHavingRaw' => [fn (Builder $builder) => $builder->orHavingRaw('user_foo < user_bar')];
639+
640+
/** @see DatabaseQueryBuilderTest::testWhereIntegerInRaw */
641+
yield 'whereIntegerInRaw' => [fn (Builder $builder) => $builder->whereIntegerInRaw('id', ['1a', 2])];
642+
643+
/** @see DatabaseQueryBuilderTest::testOrWhereIntegerInRaw */
644+
yield 'orWhereIntegerInRaw' => [fn (Builder $builder) => $builder->orWhereIntegerInRaw('id', ['1a', 2])];
645+
646+
/** @see DatabaseQueryBuilderTest::testWhereIntegerNotInRaw */
647+
yield 'whereIntegerNotInRaw' => [fn (Builder $builder) => $builder->whereIntegerNotInRaw('id', ['1a', 2])];
648+
649+
/** @see DatabaseQueryBuilderTest::testOrWhereIntegerNotInRaw */
650+
yield 'orWhereIntegerNotInRaw' => [fn (Builder $builder) => $builder->orWhereIntegerNotInRaw('id', ['1a', 2])];
552651
}
553652

554653
private static function getBuilder(): Builder

0 commit comments

Comments
 (0)