88use Illuminate \Support \Collection as IlluminateCollection ;
99use Laravel \Scout \Builder ;
1010use Laravel \Scout \Jobs \RemoveFromSearch ;
11- use LogicException ;
1211use Mockery as m ;
1312use MongoDB \BSON \Document ;
1413use MongoDB \BSON \UTCDateTime ;
1514use MongoDB \Collection ;
1615use MongoDB \Database ;
1716use MongoDB \Driver \CursorInterface ;
1817use MongoDB \Laravel \Scout \ScoutEngine ;
19- use MongoDB \Laravel \Tests \Models \SearchableInSameNamespace ;
20- use MongoDB \Laravel \Tests \Models \SearchableModel ;
18+ use MongoDB \Laravel \Tests \Scout \Models \SearchableModel ;
2119use MongoDB \Laravel \Tests \TestCase ;
2220use MongoDB \Model \BSONDocument ;
2321use PHPUnit \Framework \Attributes \DataProvider ;
2422
2523use function array_replace_recursive ;
26- use function env ;
2724use function serialize ;
28- use function sprintf ;
2925use function unserialize ;
3026
3127/** Unit tests that do not require an Atlas Search cluster */
3228class ScoutEngineTest extends TestCase
3329{
34- private const EXPECTED_SEARCH_OPTIONS = ['typeMap ' => ['root ' => 'object ' , 'document ' => 'array ' , 'array ' => 'array ' ]];
30+ private const EXPECTED_SEARCH_OPTIONS = ['typeMap ' => ['root ' => 'array ' , 'document ' => 'array ' , 'array ' => 'array ' ]];
3531
3632 /** @param callable(): Builder $builder */
3733 #[DataProvider('provideSearchPipelines ' )]
@@ -41,7 +37,7 @@ public function testSearch(Closure $builder, array $expectedPipeline): void
4137 $ database = m::mock (Database::class);
4238 $ collection = m::mock (Collection::class);
4339 $ database ->shouldReceive ('selectCollection ' )
44- ->with ('table_searchable ' )
40+ ->with ('collection_searchable ' )
4541 ->andReturn ($ collection );
4642 $ cursor = m::mock (CursorInterface::class);
4743 $ cursor ->shouldReceive ('toArray ' )->once ()->with ()->andReturn ($ data );
@@ -337,7 +333,7 @@ public function testPaginate()
337333 $ collection = m::mock (Collection::class);
338334 $ cursor = m::mock (CursorInterface::class);
339335 $ database ->shouldReceive ('selectCollection ' )
340- ->with ('table_searchable ' )
336+ ->with ('collection_searchable ' )
341337 ->andReturn ($ collection );
342338 $ collection ->shouldReceive ('aggregate ' )
343339 ->once ()
@@ -451,7 +447,7 @@ public function testUpdate(): void
451447 $ database = m::mock (Database::class);
452448 $ collection = m::mock (Collection::class);
453449 $ database ->shouldReceive ('selectCollection ' )
454- ->with ('table_indexable ' )
450+ ->with ('collection_indexable ' )
455451 ->andReturn ($ collection );
456452 $ collection ->shouldReceive ('bulkWrite ' )
457453 ->once ()
@@ -490,7 +486,7 @@ public function testUpdateWithSoftDelete(): void
490486 $ database = m::mock (Database::class);
491487 $ collection = m::mock (Collection::class);
492488 $ database ->shouldReceive ('selectCollection ' )
493- ->with ('table_indexable ' )
489+ ->with ('collection_indexable ' )
494490 ->andReturn ($ collection );
495491 $ collection ->shouldReceive ('bulkWrite ' )
496492 ->once ()
@@ -516,7 +512,7 @@ public function testDelete(): void
516512 $ database = m::mock (Database::class);
517513 $ collection = m::mock (Collection::class);
518514 $ database ->shouldReceive ('selectCollection ' )
519- ->with ('table_indexable ' )
515+ ->with ('collection_indexable ' )
520516 ->andReturn ($ collection );
521517 $ collection ->shouldReceive ('deleteMany ' )
522518 ->once ()
@@ -540,7 +536,7 @@ public function testDeleteWithRemoveableScoutCollection(): void
540536 $ database = m::mock (Database::class);
541537 $ collection = m::mock (Collection::class);
542538 $ database ->shouldReceive ('selectCollection ' )
543- ->with ('table_indexable ' )
539+ ->with ('collection_indexable ' )
544540 ->andReturn ($ collection );
545541 $ collection ->shouldReceive ('deleteMany ' )
546542 ->once ()
@@ -549,16 +545,4 @@ public function testDeleteWithRemoveableScoutCollection(): void
549545 $ engine = new ScoutEngine ($ database , softDelete: false , prefix: 'ignored_prefix_ ' );
550546 $ engine ->delete ($ job ->models );
551547 }
552- 553- public function testItCannotIndexInTheSameNamespace ()
554- {
555- self ::expectException (LogicException::class);
556- self ::expectExceptionMessage (sprintf (
557- 'The MongoDB Scout collection "%s.searchable_in_same_namespaces" must use a different collection from the collection name of the model "%s". Set the "scout.prefix" configuration or use a distinct MongoDB database ' ,
558- env ('MONGODB_DATABASE ' , 'unittest ' ),
559- SearchableInSameNamespace::class,
560- ),);
561- 562- SearchableInSameNamespace::create (['name ' => 'test ' ]);
563- }
564548}
0 commit comments