Skip to content

Cleanup and tests #2567

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

Merged
merged 19 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
ea2da7a
PHPORM-39: Add namespace for tests directory (#2)
alcaeus Jun 29, 2023
b6e8a44
Add classes to cast ObjectId and UUID instances (#1)
alcaeus Jun 29, 2023
bc364b5
PHPORM-44: Throw an exception when Query\Builder::push() is used inco…
GromNaN Jul 11, 2023
60a22f4
PHPORM-45 Add Query\Builder::toMql() to simplify comprehensive query …
GromNaN Jul 12, 2023
843904b
Create UTCDateTime from DateTimeInterface objects (#8)
GromNaN Jul 12, 2023
8562a4b
PHPORM-46 Throw an exception when Query\Builder::orderBy() is used wi…
GromNaN Jul 12, 2023
4658d54
PHPORM-51 Throw an exception when unsupported query builder method is…
GromNaN Jul 12, 2023
78319d4
Optimize calls to debug_backtrace (#11)
GromNaN Jul 13, 2023
bd86f85
Add header documentation for classes & traits that can be used in app…
GromNaN Jul 13, 2023
cf103ba
PHPORM-47 Improve Builder::whereBetween to support CarbonPeriod and r…
GromNaN Jul 19, 2023
9d9c7c8
PHPORM-49 Implement `Query\Builder::whereNot` by encapsulating into `…
GromNaN Jul 19, 2023
52c0ea3
PHPORM-49 Implement `Query\Builder::whereNot` by encapsulating into `…
GromNaN Jul 20, 2023
9cbadea
PHPORM-50 PHPORM-65 Remove call to deprecated Collection::count for c…
GromNaN Jul 26, 2023
03c58ea
PHPORM-67 Accept operators prefixed by $ in Query\Builder::orWhere (#20)
GromNaN Jul 26, 2023
b0b796c
PHPORM-33 Add tests on Query\Builder methods (#14)
GromNaN Jul 26, 2023
2824dc4
PHPORM-64 Remove Query\Builder::whereAll (#16)
GromNaN Jul 26, 2023
3a46876
PHPORM-68 Fix unique validator when the validated value is part of an…
GromNaN Jul 26, 2023
2319d53
PHPORM-53 Fix and test `like` and `regex` operators (#17)
GromNaN Jul 27, 2023
9f1f8f3
PHPORM-35 Add various tests on Model `_id` types (#22)
GromNaN Aug 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
PHPORM-44: Throw an exception when Query\Builder::push() is used inco…
…rrectly (#5)
  • Loading branch information
GromNaN authored Jul 11, 2023
commit bc364b5ed5a053c69c69a9c8ae5206725a84488e
5 changes: 4 additions & 1 deletion src/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -786,9 +786,12 @@ public function push($column, $value = null, $unique = false)
$operator = $unique ? '$addToSet' : '$push';

// Check if we are pushing multiple values.
$batch = (is_array($value) && array_keys($value) === range(0, count($value) - 1));
$batch = is_array($value) && array_is_list($value);

if (is_array($column)) {
if ($value !== null) {
throw new \InvalidArgumentException(sprintf('2nd argument of %s() must be "null" when 1st argument is an array. Got "%s" instead.', __METHOD__, get_debug_type($value)));
}
$query = [$operator => $column];
} elseif ($batch) {
$query = [$operator => [$column => ['$each' => $value]]];
Expand Down
8 changes: 8 additions & 0 deletions tests/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,14 @@ public function testPush()
$this->assertCount(3, $user['messages']);
}

public function testPushRefuses2ndArgumentWhen1stIsAnArray()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('2nd argument of Jenssegers\Mongodb\Query\Builder::push() must be "null" when 1st argument is an array. Got "string" instead.');

DB::collection('users')->push(['tags' => 'tag1'], 'tag2');
}

public function testPull()
{
$message1 = ['from' => 'Jane', 'body' => 'Hi John'];
Expand Down