-
Notifications
You must be signed in to change notification settings - Fork 1.5k
DOCSP-35962: sorts #2879
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
DOCSP-35962: sorts #2879
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0c44e6c
DOCSP-35962: sorts
rustagir 8cb7389
add note about params
rustagir 8ca26d0
CC suggestion
rustagir 12e6d55
move to test
rustagir 0787f2b
Add fixtures to the tests
GromNaN 9b63d29
JT PR fix to link and update code
rustagir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use MongoDB\Laravel\Eloquent\Model; | ||
|
||
class Movie extends Model | ||
{ | ||
protected $connection = 'mongodb'; | ||
protected $collection = 'movies'; | ||
protected $fillable = ['title', 'year', 'runtime', 'imdb', 'plot']; | ||
} |
97 changes: 97 additions & 0 deletions
97
docs/includes/fundamentals/read-operations/ReadOperationsTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\Movie; | ||
use MongoDB\Laravel\Tests\TestCase; | ||
|
||
class ReadOperationsTest extends TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
require_once __DIR__ . '/Movie.php'; | ||
|
||
parent::setUp(); | ||
|
||
Movie::truncate(); | ||
Movie::insert([ | ||
['year' => 2010, 'imdb' => ['rating' => 9]], | ||
['year' => 2010, 'imdb' => ['rating' => 9.5]], | ||
['year' => 2010, 'imdb' => ['rating' => 7]], | ||
['year' => 1999, 'countries' => ['Indonesia', 'Canada'], 'title' => 'Title 1'], | ||
['year' => 1999, 'countries' => ['Indonesia'], 'title' => 'Title 2'], | ||
['year' => 1999, 'countries' => ['Indonesia'], 'title' => 'Title 3'], | ||
['year' => 1999, 'countries' => ['Indonesia'], 'title' => 'Title 4'], | ||
['year' => 1999, 'countries' => ['Canada'], 'title' => 'Title 5'], | ||
['year' => 1999, 'runtime' => 30], | ||
]); | ||
} | ||
|
||
/** | ||
* @runInSeparateProcess | ||
* @preserveGlobalState disabled | ||
*/ | ||
public function testFindFilter(): void | ||
{ | ||
// start-query | ||
$movies = Movie::where('year', 2010) | ||
->where('imdb.rating', '>', 8.5) | ||
->get(); | ||
// end-query | ||
|
||
$this->assertNotNull($movies); | ||
$this->assertCount(2, $movies); | ||
} | ||
|
||
/** | ||
* @runInSeparateProcess | ||
* @preserveGlobalState disabled | ||
*/ | ||
public function testSkipLimit(): void | ||
{ | ||
// start-skip-limit | ||
$movies = Movie::where('year', 1999) | ||
->skip(2) | ||
->take(3) | ||
->get(); | ||
// end-skip-limit | ||
|
||
$this->assertNotNull($movies); | ||
$this->assertCount(3, $movies); | ||
} | ||
|
||
/** | ||
* @runInSeparateProcess | ||
* @preserveGlobalState disabled | ||
*/ | ||
public function testSort(): void | ||
{ | ||
// start-sort | ||
$movies = Movie::where('countries', 'Indonesia') | ||
->orderBy('year') | ||
->orderBy('title', 'desc') | ||
->get(); | ||
// end-sort | ||
|
||
$this->assertNotNull($movies); | ||
$this->assertCount(4, $movies); | ||
} | ||
|
||
/** | ||
* @runInSeparateProcess | ||
* @preserveGlobalState disabled | ||
*/ | ||
public function testFirst(): void | ||
{ | ||
// start-first | ||
$movie = Movie::where('runtime', 30) | ||
->orderBy('_id') | ||
->first(); | ||
// end-first | ||
|
||
$this->assertNotNull($movie); | ||
$this->assertInstanceOf(Movie::class, $movie); | ||
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. I've renamed |
||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I've added fixtures to make the tests work. But I had to update the expected number of results, so we don't have too much data to load.
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.
Thanks for fixing the tests!