-
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
DOCSP-35962: sorts #2879
Changes from 5 commits
0c44e6c
8cb7389
8ca26d0
12e6d55
0787f2b
9b63d29
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 |
---|---|---|
@@ -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']; | ||
} |
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); | ||
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 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 commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for fixing the tests! |
||
} | ||
|
||
/** | ||
* @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 |
||
} | ||
} |
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.