8
8
use Illuminate \Support \Collection as IlluminateCollection ;
9
9
use Laravel \Scout \Builder ;
10
10
use Laravel \Scout \Jobs \RemoveFromSearch ;
11
- use LogicException ;
12
11
use Mockery as m ;
13
12
use MongoDB \BSON \Document ;
14
13
use MongoDB \BSON \UTCDateTime ;
15
14
use MongoDB \Collection ;
16
15
use MongoDB \Database ;
17
16
use MongoDB \Driver \CursorInterface ;
18
17
use 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 ;
21
19
use MongoDB \Laravel \Tests \TestCase ;
22
20
use MongoDB \Model \BSONDocument ;
23
21
use PHPUnit \Framework \Attributes \DataProvider ;
24
22
25
23
use function array_replace_recursive ;
26
- use function env ;
27
24
use function serialize ;
28
- use function sprintf ;
29
25
use function unserialize ;
30
26
31
27
/** Unit tests that do not require an Atlas Search cluster */
32
28
class ScoutEngineTest extends TestCase
33
29
{
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 ' ]];
35
31
36
32
/** @param callable(): Builder $builder */
37
33
#[DataProvider('provideSearchPipelines ' )]
@@ -41,7 +37,7 @@ public function testSearch(Closure $builder, array $expectedPipeline): void
41
37
$ database = m::mock (Database::class);
42
38
$ collection = m::mock (Collection::class);
43
39
$ database ->shouldReceive ('selectCollection ' )
44
- ->with ('table_searchable ' )
40
+ ->with ('collection_searchable ' )
45
41
->andReturn ($ collection );
46
42
$ cursor = m::mock (CursorInterface::class);
47
43
$ cursor ->shouldReceive ('toArray ' )->once ()->with ()->andReturn ($ data );
@@ -337,7 +333,7 @@ public function testPaginate()
337
333
$ collection = m::mock (Collection::class);
338
334
$ cursor = m::mock (CursorInterface::class);
339
335
$ database ->shouldReceive ('selectCollection ' )
340
- ->with ('table_searchable ' )
336
+ ->with ('collection_searchable ' )
341
337
->andReturn ($ collection );
342
338
$ collection ->shouldReceive ('aggregate ' )
343
339
->once ()
@@ -451,7 +447,7 @@ public function testUpdate(): void
451
447
$ database = m::mock (Database::class);
452
448
$ collection = m::mock (Collection::class);
453
449
$ database ->shouldReceive ('selectCollection ' )
454
- ->with ('table_indexable ' )
450
+ ->with ('collection_indexable ' )
455
451
->andReturn ($ collection );
456
452
$ collection ->shouldReceive ('bulkWrite ' )
457
453
->once ()
@@ -490,7 +486,7 @@ public function testUpdateWithSoftDelete(): void
490
486
$ database = m::mock (Database::class);
491
487
$ collection = m::mock (Collection::class);
492
488
$ database ->shouldReceive ('selectCollection ' )
493
- ->with ('table_indexable ' )
489
+ ->with ('collection_indexable ' )
494
490
->andReturn ($ collection );
495
491
$ collection ->shouldReceive ('bulkWrite ' )
496
492
->once ()
@@ -516,7 +512,7 @@ public function testDelete(): void
516
512
$ database = m::mock (Database::class);
517
513
$ collection = m::mock (Collection::class);
518
514
$ database ->shouldReceive ('selectCollection ' )
519
- ->with ('table_indexable ' )
515
+ ->with ('collection_indexable ' )
520
516
->andReturn ($ collection );
521
517
$ collection ->shouldReceive ('deleteMany ' )
522
518
->once ()
@@ -540,7 +536,7 @@ public function testDeleteWithRemoveableScoutCollection(): void
540
536
$ database = m::mock (Database::class);
541
537
$ collection = m::mock (Collection::class);
542
538
$ database ->shouldReceive ('selectCollection ' )
543
- ->with ('table_indexable ' )
539
+ ->with ('collection_indexable ' )
544
540
->andReturn ($ collection );
545
541
$ collection ->shouldReceive ('deleteMany ' )
546
542
->once ()
@@ -549,16 +545,4 @@ public function testDeleteWithRemoveableScoutCollection(): void
549
545
$ engine = new ScoutEngine ($ database , softDelete: false , prefix: 'ignored_prefix_ ' );
550
546
$ engine ->delete ($ job ->models );
551
547
}
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
- }
564
548
}
0 commit comments