|
2 | 2 |
|
3 | 3 | namespace MongoDB\Laravel\Tests;
|
4 | 4 |
|
| 5 | +use Illuminate\Database\Eloquent\Collection; |
5 | 6 | use Illuminate\Support\Facades\Schema;
|
| 7 | +use MongoDB\Builder\Search; |
6 | 8 | use MongoDB\Collection as MongoDBCollection;
|
7 | 9 | use MongoDB\Driver\Exception\ServerException;
|
8 | 10 | use MongoDB\Laravel\Schema\Builder;
|
@@ -42,6 +44,7 @@ public function setUp(): void
|
42 | 44 | ]);
|
43 | 45 |
|
44 | 46 | $collection = $this->getConnection('mongodb')->getCollection('books');
|
| 47 | + |
45 | 48 | assert($collection instanceof MongoDBCollection);
|
46 | 49 | try {
|
47 | 50 | $collection->createSearchIndex([
|
@@ -135,4 +138,60 @@ public function testGetIndexes()
|
135 | 138 |
|
136 | 139 | self::assertSame($expected, $indexes);
|
137 | 140 | }
|
| 141 | + |
| 142 | + public function testEloquentBuilderSearch() |
| 143 | + { |
| 144 | + $results = Book::search(Search::text('title', 'systems')); |
| 145 | + |
| 146 | + self::assertInstanceOf(Collection::class, $results); |
| 147 | + self::assertCount(3, $results); |
| 148 | + self::assertInstanceOf(Book::class, $results->first()); |
| 149 | + self::assertSame([ |
| 150 | + 'Operating System Concepts', |
| 151 | + 'Database System Concepts', |
| 152 | + 'Modern Operating Systems', |
| 153 | + ], $results->pluck('title')->all()); |
| 154 | + } |
| 155 | + |
| 156 | + public function testDatabaseBuilderSearch() |
| 157 | + { |
| 158 | + $results = $this->getConnection('mongodb')->table('books') |
| 159 | + ->search(Search::text('title', 'systems')); |
| 160 | + |
| 161 | + self::assertInstanceOf(\Illuminate\Support\Collection::class, $results); |
| 162 | + self::assertCount(3, $results); |
| 163 | + self::assertIsArray($results->first()); |
| 164 | + self::assertSame([ |
| 165 | + 'Operating System Concepts', |
| 166 | + 'Database System Concepts', |
| 167 | + 'Modern Operating Systems', |
| 168 | + ], $results->pluck('title')->all()); |
| 169 | + } |
| 170 | + |
| 171 | + public function testEloquentBuilderAutocomplete() |
| 172 | + { |
| 173 | + $results = Book::autocomplete('title', 'system'); |
| 174 | + |
| 175 | + self::assertInstanceOf(\Illuminate\Support\Collection::class, $results); |
| 176 | + self::assertCount(3, $results); |
| 177 | + self::assertSame([ |
| 178 | + 'Operating System Concepts', |
| 179 | + 'Database System Concepts', |
| 180 | + 'Modern Operating Systems', |
| 181 | + ], $results->all()); |
| 182 | + } |
| 183 | + |
| 184 | + public function testDatabaseBuilderAutocomplete() |
| 185 | + { |
| 186 | + $results = $this->getConnection('mongodb')->table('books') |
| 187 | + ->autocomplete('title', 'system'); |
| 188 | + |
| 189 | + self::assertInstanceOf(\Illuminate\Support\Collection::class, $results); |
| 190 | + self::assertCount(3, $results); |
| 191 | + self::assertSame([ |
| 192 | + 'Operating System Concepts', |
| 193 | + 'Database System Concepts', |
| 194 | + 'Modern Operating Systems', |
| 195 | + ], $results->all()); |
| 196 | + } |
138 | 197 | }
|
0 commit comments