-
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 4 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']; | ||
} |
95 changes: 95 additions & 0 deletions
95
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,95 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\Cargo; | ||
|
||
// <add your imports here including any models and facades> | ||
|
||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Schema\SQLiteBuilder; | ||
use Illuminate\Support\Facades\Schema; | ||
use MongoDB\Laravel\Tests\TestCase; | ||
|
||
use function assert; | ||
|
||
class ReadOperationsTest extends TestCase | ||
{ | ||
|
||
/** | ||
* @runInSeparateProcess | ||
* @preserveGlobalState disabled | ||
*/ | ||
public function testFindFilter(): void | ||
{ | ||
require_once __DIR__ . '/Movie.php'; | ||
|
||
// 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 | ||
{ | ||
require_once __DIR__ . '/Movie.php'; | ||
|
||
// 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 | ||
{ | ||
require_once __DIR__ . '/Movie.php'; | ||
|
||
// start-sort | ||
$movies = Movie::where('countries', 'Indonesia') | ||
->orderBy('year') | ||
->orderBy('title', 'desc') | ||
->get(); | ||
// end-sort | ||
|
||
$this->assertNotNull($movies); | ||
$this->assertCount(24, $movies); | ||
} | ||
|
||
/** | ||
* @runInSeparateProcess | ||
* @preserveGlobalState disabled | ||
*/ | ||
public function testFirst(): void | ||
{ | ||
require_once __DIR__ . '/Movie.php'; | ||
|
||
// start-first | ||
$movies = Movie::where('runtime', 30) | ||
->orderBy('_id') | ||
->first(); | ||
// end-first | ||
|
||
$this->assertNotNull($movies); | ||
$this->assertCount(1, $movies); | ||
} | ||
|
||
} |
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.
That may be a subject to be dealt with separately, but we can't freeze the version like that. How to update the links when a new Laravel version is released? Perhaps the easiest way is to link to the latest version. But you run the risk of having a broken link.
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.
We can link to the latest version, or we can store the laravel version as a source constant. Either way, the risk of linking to a broken link is there, so I'll update to just use latest for now.