-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix compatibility with Laravel 10.30 — lowercase the $passthru
array values
#2661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,24 +30,33 @@ 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', | ||
'pull', | ||
'push', | ||
'raw', | ||
'sum', | ||
'toSql', | ||
'tomql', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. replaced as it is not supported |
||
// Kept for compatibility with Laravel < 10.3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here I was trying to conditionally set the method names casing 😆 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simple and verbose solutions are often good enough. |
||
'doesntExist', | ||
'getBindings', | ||
'getConnection', | ||
'getGrammar', | ||
'insertGetId', | ||
'insertOrIgnore', | ||
'insertUsing', | ||
'toMql', | ||
]; | ||
|
||
/** @inheritdoc */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MongoDB\Laravel\Tests\Eloquent; | ||
|
||
use BadMethodCallException; | ||
use Generator; | ||
use MongoDB\Laravel\Eloquent\Builder; | ||
use MongoDB\Laravel\Query\Builder as QueryBuilder; | ||
use MongoDB\Laravel\Tests\Models\User; | ||
use MongoDB\Laravel\Tests\TestCase; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use RuntimeException; | ||
|
||
use function assert; | ||
|
||
final class CallBuilderTest extends TestCase | ||
{ | ||
protected function tearDown(): void | ||
{ | ||
User::truncate(); | ||
} | ||
|
||
#[Dataprovider('provideFunctionNames')] | ||
public function testCallingABuilderMethodDoesNotReturnTheBuilderInstance(string $method, string $className, $parameters = []): void | ||
{ | ||
$builder = User::query()->newQuery(); | ||
assert($builder instanceof Builder); | ||
|
||
self::assertNotInstanceOf(expected: $className, actual: $builder->{$method}(...$parameters)); | ||
} | ||
|
||
public static function provideFunctionNames(): Generator | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. provide supported methods, which should not return a Builder instance. |
||
{ | ||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. verify that certain methods are not supported, checking both the exception type and its message |
||
$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', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can create a separate issue to support this, once this PR get merged. |
||
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], | ||
]; | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If #2659 is merged, this method will never be called. Would it be better to remove it? Possibly by leaving a comment.
Or maybe discard #2659 and keep this PR as a fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you said in the comment in #2659 makes sense, the latter part.
Personally I like to be specific/remove magic, but that's the way Laravel works and we need to align with that.
In short, close #2659 in favour of this one.