Skip to content

Commit 461bef2

Browse files
committed
Fix index creation in tests
1 parent cd6d025 commit 461bef2

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

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

Lines changed: 6 additions & 7 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]],
@@ -30,10 +34,6 @@ protected function setUp(): void
3034
['title' => 'movie_b', 'plot' => 'love is a long 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
/**
@@ -125,12 +125,11 @@ public function testTextRelevance(): void
125125
{
126126
// start-text-relevance
127127
$movies = Movie::where('$text', ['$search' => '"love story"'])
128-
->orderBy('score', ['$meta' => 'textScore'])
128+
->orderBy('score', ['$meta' => 'textScore'])
129129
->get();
130130
// end-text-relevance
131131

132132
$this->assertNotNull($movies);
133133
$this->assertCount(2, $movies);
134134
}
135-
136135
}

0 commit comments

Comments
 (0)