Skip to content

Commit 802f50e

Browse files
committed
Fix index creation in tests
1 parent cd6d025 commit 802f50e

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

docs/includes/fundamentals/read-operations/ReadOperationsTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace App\Http\Controllers;
66

77
use App\Models\Movie;
8+
use Illuminate\Support\Facades\DB;
89
use MongoDB\Laravel\Tests\TestCase;
910

1011
class ReadOperationsTest extends TestCase
@@ -15,7 +16,10 @@ protected function setUp(): void
1516

1617
parent::setUp();
1718

18-
Movie::truncate();
19+
$moviesCollection = DB::connection('mongodb')->getCollection('movies');
20+
$moviesCollection->drop();
21+
$moviesCollection->createIndex(['plot' => 'text']);
22+
1923
Movie::insert([
2024
['year' => 2010, 'imdb' => ['rating' => 9]],
2125
['year' => 2010, 'imdb' => ['rating' => 9.5]],
@@ -26,14 +30,10 @@ protected function setUp(): void
2630
['year' => 1999, 'countries' => ['Indonesia'], 'title' => 'Title 4'],
2731
['year' => 1999, 'countries' => ['Canada'], 'title' => 'Title 5'],
2832
['year' => 1999, 'runtime' => 30],
29-
['title' => 'movie_a', 'plot' => 'this is a love story'],
3033
['title' => 'movie_b', 'plot' => 'love is a long story'],
34+
['title' => 'movie_a', 'plot' => 'this is a love story'],
3135
['title' => 'movie_c', 'plot' => 'went on a trip'],
3236
]);
33-
34-
$collection = MongoDB::connection('mongodb')->collection('movies');
35-
$index = ['plot' => 'text'];
36-
$collection->createIndex($index);
3737
}
3838

3939
/**
@@ -109,7 +109,7 @@ public function testFirst(): void
109109
public function testText(): void
110110
{
111111
// start-text
112-
$movies = Movie::where('$text', ['$search' => '"love story"'])
112+
$movies = Movie::where('$text', ['$search' => 'love story'])
113113
->get();
114114
// end-text
115115

@@ -124,13 +124,13 @@ public function testText(): void
124124
public function testTextRelevance(): void
125125
{
126126
// start-text-relevance
127-
$movies = Movie::where('$text', ['$search' => '"love story"'])
128-
->orderBy('score', ['$meta' => 'textScore'])
127+
$movies = Movie::where('$text', ['$search' => 'love story'])
128+
->orderBy('score', ['$meta' => 'textScore'])
129129
->get();
130130
// end-text-relevance
131131

132132
$this->assertNotNull($movies);
133133
$this->assertCount(2, $movies);
134+
$this->assertEquals('this is a love story', $movies[0]->plot);
134135
}
135-
136136
}

0 commit comments

Comments
 (0)