Skip to content

Commit abcba92

Browse files
TreggatsGromNaN
authored andcommitted
lowercase the $passthru array values
1 parent 25bd203 commit abcba92

File tree

4 files changed

+209
-9
lines changed

4 files changed

+209
-9
lines changed

phpcs.xml.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,7 @@
3434
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint"/>
3535
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint"/>
3636
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint"/>
37+
38+
<exclude name="Generic.Formatting.MultipleStatementAlignment" />
3739
</rule>
3840
</ruleset>

src/Eloquent/Builder.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,33 @@ class Builder extends EloquentBuilder
3030
'avg',
3131
'count',
3232
'dd',
33-
'doesntExist',
33+
'doesntexist',
3434
'dump',
3535
'exists',
36-
'getBindings',
37-
'getConnection',
38-
'getGrammar',
36+
'getbindings',
37+
'getconnection',
38+
'getgrammar',
3939
'insert',
40-
'insertGetId',
41-
'insertOrIgnore',
42-
'insertUsing',
40+
'insertgetid',
41+
'insertorignore',
42+
'insertusing',
4343
'max',
4444
'min',
4545
'pluck',
4646
'pull',
4747
'push',
4848
'raw',
4949
'sum',
50-
'toSql',
50+
'tomql',
51+
// Kept for compatibility with Laravel < 10.3
52+
'doesntExist',
53+
'getBindings',
54+
'getConnection',
55+
'getGrammar',
56+
'insertGetId',
57+
'insertOrIgnore',
58+
'insertUsing',
59+
'toMql',
5160
];
5261

5362
/** @inheritdoc */

tests/Eloquent/CallBuilderTest.php

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MongoDB\Laravel\Tests\Eloquent;
6+
7+
use BadMethodCallException;
8+
use Generator;
9+
use MongoDB\Laravel\Eloquent\Builder;
10+
use MongoDB\Laravel\Query\Builder as QueryBuilder;
11+
use MongoDB\Laravel\Tests\Models\User;
12+
use MongoDB\Laravel\Tests\TestCase;
13+
use PHPUnit\Framework\Attributes\DataProvider;
14+
use PHPUnit\Framework\Attributes\Test;
15+
use RuntimeException;
16+
17+
use function assert;
18+
19+
final class CallBuilderTest extends TestCase
20+
{
21+
protected function tearDown(): void
22+
{
23+
User::truncate();
24+
}
25+
26+
#[Dataprovider('provideFunctionNames')]
27+
public function testCallingABuilderMethodDoesNotReturnTheBuilderInstance(string $method, string $className, $parameters = []): void
28+
{
29+
$builder = User::query()->newQuery();
30+
assert($builder instanceof Builder);
31+
32+
self::assertNotInstanceOf(expected: $className, actual: $builder->{$method}(...$parameters));
33+
}
34+
35+
public static function provideFunctionNames(): Generator
36+
{
37+
yield 'does not exist' => [
38+
'doesntExist',
39+
Builder::class,
40+
];
41+
42+
yield 'get bindings' => [
43+
'getBindings',
44+
Builder::class,
45+
];
46+
47+
yield 'get connection' => [
48+
'getConnection',
49+
Builder::class,
50+
];
51+
52+
yield 'get grammar' => [
53+
'getGrammar',
54+
Builder::class,
55+
];
56+
57+
yield 'insert get id' => [
58+
'insertGetId',
59+
Builder::class,
60+
[['user' => 'foo']],
61+
];
62+
63+
yield 'to Mql' => [
64+
'toMql',
65+
Builder::class,
66+
];
67+
68+
yield 'average' => [
69+
'average',
70+
Builder::class,
71+
['name'],
72+
];
73+
74+
yield 'avg' => [
75+
'avg',
76+
Builder::class,
77+
['name'],
78+
];
79+
80+
yield 'count' => [
81+
'count',
82+
Builder::class,
83+
['name'],
84+
];
85+
86+
yield 'exists' => [
87+
'exists',
88+
Builder::class,
89+
];
90+
91+
yield 'insert' => [
92+
'insert',
93+
Builder::class,
94+
[['name']],
95+
];
96+
97+
yield 'max' => [
98+
'max',
99+
Builder::class,
100+
['name'],
101+
];
102+
103+
yield 'min' => [
104+
'min',
105+
Builder::class,
106+
['name'],
107+
];
108+
109+
yield 'pluck' => [
110+
'pluck',
111+
Builder::class,
112+
['name'],
113+
];
114+
115+
yield 'pull' => [
116+
'pull',
117+
Builder::class,
118+
['name'],
119+
];
120+
121+
yield 'push' => [
122+
'push',
123+
Builder::class,
124+
['name'],
125+
];
126+
127+
yield 'raw' => [
128+
'raw',
129+
Builder::class,
130+
];
131+
132+
yield 'sum' => [
133+
'sum',
134+
Builder::class,
135+
['name'],
136+
];
137+
}
138+
139+
#[Test]
140+
#[DataProvider('provideUnsupportedMethods')]
141+
public function callingUnsupportedMethodThrowsAnException(string $method, string $exceptionClass, string $exceptionMessage, $parameters = []): void
142+
{
143+
$builder = User::query()->newQuery();
144+
assert($builder instanceof Builder);
145+
146+
$this->expectException($exceptionClass);
147+
$this->expectExceptionMessage($exceptionMessage);
148+
149+
$builder->{$method}(...$parameters);
150+
}
151+
152+
public static function provideUnsupportedMethods(): Generator
153+
{
154+
yield 'insert or ignore' => [
155+
'insertOrIgnore',
156+
RuntimeException::class,
157+
'This database engine does not support inserting while ignoring errors',
158+
[['name' => 'Jane']],
159+
];
160+
161+
yield 'insert using' => [
162+
'insertUsing',
163+
BadMethodCallException::class,
164+
'This method is not supported by MongoDB. Try "toMql()" instead',
165+
[[['name' => 'Jane']], fn (QueryBuilder $builder) => $builder],
166+
];
167+
168+
yield 'to sql' => [
169+
'toSql',
170+
BadMethodCallException::class,
171+
'This method is not supported by MongoDB. Try "toMql()" instead',
172+
[[['name' => 'Jane']], fn (QueryBuilder $builder) => $builder],
173+
];
174+
175+
yield 'dd' => [
176+
'dd',
177+
BadMethodCallException::class,
178+
'This method is not supported by MongoDB. Try "toMql()" instead',
179+
[[['name' => 'Jane']], fn (QueryBuilder $builder) => $builder],
180+
];
181+
182+
yield 'dump' => [
183+
'dump',
184+
BadMethodCallException::class,
185+
'This method is not supported by MongoDB. Try "toMql()" instead',
186+
[[['name' => 'Jane']], fn (QueryBuilder $builder) => $builder],
187+
];
188+
}
189+
}

tests/Eloquent/MassPrunableTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Eloquent;
5+
namespace MongoDB\Laravel\Tests\Eloquent;
66

77
use Illuminate\Database\Console\PruneCommand;
88
use Illuminate\Database\Eloquent\MassPrunable;

0 commit comments

Comments
 (0)