diff --git a/phpcs.xml.dist b/phpcs.xml.dist
index 36cc870e9..23bc44ab7 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml.dist
@@ -34,5 +34,7 @@
+
+
diff --git a/src/Eloquent/Builder.php b/src/Eloquent/Builder.php
index 4d210c873..909207959 100644
--- a/src/Eloquent/Builder.php
+++ b/src/Eloquent/Builder.php
@@ -30,16 +30,16 @@ class Builder extends EloquentBuilder
'avg',
'count',
'dd',
- 'doesntExist',
+ 'doesntexist',
'dump',
'exists',
- 'getBindings',
- 'getConnection',
- 'getGrammar',
+ 'getbindings',
+ 'getconnection',
+ 'getgrammar',
'insert',
- 'insertGetId',
- 'insertOrIgnore',
- 'insertUsing',
+ 'insertgetid',
+ 'insertorignore',
+ 'insertusing',
'max',
'min',
'pluck',
@@ -47,7 +47,16 @@ class Builder extends EloquentBuilder
'push',
'raw',
'sum',
- 'toSql',
+ 'tomql',
+ // Kept for compatibility with Laravel < 10.3
+ 'doesntExist',
+ 'getBindings',
+ 'getConnection',
+ 'getGrammar',
+ 'insertGetId',
+ 'insertOrIgnore',
+ 'insertUsing',
+ 'toMql',
];
/** @inheritdoc */
diff --git a/tests/Eloquent/CallBuilderTest.php b/tests/Eloquent/CallBuilderTest.php
new file mode 100644
index 000000000..226fe1f25
--- /dev/null
+++ b/tests/Eloquent/CallBuilderTest.php
@@ -0,0 +1,107 @@
+newQuery();
+ assert($builder instanceof Builder);
+
+ self::assertNotInstanceOf(expected: $className, actual: $builder->{$method}(...$parameters));
+ }
+
+ public static function provideFunctionNames(): Generator
+ {
+ yield 'does not exist' => ['doesntExist', Builder::class];
+ yield 'get bindings' => ['getBindings', Builder::class];
+ yield 'get connection' => ['getConnection', Builder::class];
+ yield 'get grammar' => ['getGrammar', Builder::class];
+ yield 'insert get id' => ['insertGetId', Builder::class, [['user' => 'foo']]];
+ yield 'to Mql' => ['toMql', Builder::class];
+ yield 'average' => ['average', Builder::class, ['name']];
+ yield 'avg' => ['avg', Builder::class, ['name']];
+ yield 'count' => ['count', Builder::class, ['name']];
+ yield 'exists' => ['exists', Builder::class];
+ yield 'insert' => ['insert', Builder::class, [['name']]];
+ yield 'max' => ['max', Builder::class, ['name']];
+ yield 'min' => ['min', Builder::class, ['name']];
+ yield 'pluck' => ['pluck', Builder::class, ['name']];
+ yield 'pull' => ['pull', Builder::class, ['name']];
+ yield 'push' => ['push', Builder::class, ['name']];
+ yield 'raw' => ['raw', Builder::class];
+ yield 'sum' => ['sum', Builder::class, ['name']];
+ }
+
+ #[Test]
+ #[DataProvider('provideUnsupportedMethods')]
+ public function callingUnsupportedMethodThrowsAnException(string $method, string $exceptionClass, string $exceptionMessage, $parameters = []): void
+ {
+ $builder = User::query()->newQuery();
+ assert($builder instanceof Builder);
+
+ $this->expectException($exceptionClass);
+ $this->expectExceptionMessage($exceptionMessage);
+
+ $builder->{$method}(...$parameters);
+ }
+
+ public static function provideUnsupportedMethods(): Generator
+ {
+ yield 'insert or ignore' => [
+ 'insertOrIgnore',
+ RuntimeException::class,
+ 'This database engine does not support inserting while ignoring errors',
+ [['name' => 'Jane']],
+ ];
+
+ yield 'insert using' => [
+ 'insertUsing',
+ BadMethodCallException::class,
+ 'This method is not supported by MongoDB. Try "toMql()" instead',
+ [[['name' => 'Jane']], fn (QueryBuilder $builder) => $builder],
+ ];
+
+ yield 'to sql' => [
+ 'toSql',
+ BadMethodCallException::class,
+ 'This method is not supported by MongoDB. Try "toMql()" instead',
+ [[['name' => 'Jane']], fn (QueryBuilder $builder) => $builder],
+ ];
+
+ yield 'dd' => [
+ 'dd',
+ BadMethodCallException::class,
+ 'This method is not supported by MongoDB. Try "toMql()" instead',
+ [[['name' => 'Jane']], fn (QueryBuilder $builder) => $builder],
+ ];
+
+ yield 'dump' => [
+ 'dump',
+ BadMethodCallException::class,
+ 'This method is not supported by MongoDB. Try "toMql()" instead',
+ [[['name' => 'Jane']], fn (QueryBuilder $builder) => $builder],
+ ];
+ }
+}
diff --git a/tests/Eloquent/MassPrunableTest.php b/tests/Eloquent/MassPrunableTest.php
index a93f864e5..0f6f2ab15 100644
--- a/tests/Eloquent/MassPrunableTest.php
+++ b/tests/Eloquent/MassPrunableTest.php
@@ -2,7 +2,7 @@
declare(strict_types=1);
-namespace Eloquent;
+namespace MongoDB\Laravel\Tests\Eloquent;
use Illuminate\Database\Console\PruneCommand;
use Illuminate\Database\Eloquent\MassPrunable;