Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Jan 14, 2025
1 parent 1ae5af1 commit b22192b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
13 changes: 6 additions & 7 deletions src/Scout/ScoutEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use MongoDB\BSON\UTCDateTime;
use MongoDB\Collection as MongoDBCollection;
use MongoDB\Database;
use MongoDB\Driver\Cursor;
use MongoDB\Driver\CursorInterface;
use MongoDB\Exception\RuntimeException as MongoDBRuntimeException;
use MongoDB\Laravel\Connection;
Expand Down Expand Up @@ -311,9 +310,9 @@ public function mapIds($results): Collection
*
* @see Engine::map()
*
* @param Builder $builder
* @param array|Cursor $results
* @param Model $model
* @param Builder $builder
* @param array $results
* @param Model $model
*
* @return Collection
*/
Expand All @@ -328,9 +327,9 @@ public function map(Builder $builder, $results, $model): Collection
*
* @see Engine::lazyMap()
*
* @param Builder $builder
* @param array|Cursor $results
* @param Model $model
* @param Builder $builder
* @param array $results
* @param Model $model
*
* @return LazyCollection
*/
Expand Down
26 changes: 15 additions & 11 deletions tests/Scout/ScoutEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ function () {
'$search' => [
'compound' => [
'filter' => [
['equals' => ['path' => '__soft_deleted', 'value' => 0]],
['equals' => ['path' => '__soft_deleted', 'value' => false]],
],
],
],
Expand All @@ -286,7 +286,7 @@ function () {
'$search' => [
'compound' => [
'filter' => [
['equals' => ['path' => '__soft_deleted', 'value' => 1]],
['equals' => ['path' => '__soft_deleted', 'value' => true]],
],
],
],
Expand Down Expand Up @@ -493,20 +493,24 @@ public function testUpdateWithSoftDelete(): void
->andReturn($collection);
$collection->shouldReceive('bulkWrite')
->once()
->with([
[
'updateOne' => [
['_id' => 'key_1'],
['$setOnInsert' => ['_id' => 'key_1'], '$set' => ['id' => 1]],
['upsert' => true],
->withArgs(function ($pipeline) {
$this->assertSame([
[
'updateOne' => [
['_id' => 'key_1'],
['$setOnInsert' => ['_id' => 'key_1'], '$set' => ['id' => 1, '__soft_deleted' => false]],
['upsert' => true],
],
],
],
]);
], $pipeline);

return true;
});

$model = new SearchableModel(['id' => 1]);
$model->delete();

$engine = new ScoutEngine($database, softDelete: false);
$engine = new ScoutEngine($database, softDelete: true);
$engine->update(EloquentCollection::make([$model]));
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Scout/ScoutIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public function setUp(): void
{
parent::setUp();

$this->skipIfSearchIndexManagementIsNotSupported();

// Init the SQL database with some objects that will be indexed
// Test data copied from Laravel Scout tests
// https://github.com/laravel/scout/blob/10.x/tests/Integration/SearchableTests.php
Expand Down Expand Up @@ -88,8 +90,6 @@ public function setUp(): void
/** This test create the search index for tests performing search */
public function testItCanCreateTheCollection()
{
$this->skipIfSearchIndexManagementIsNotSupported();

$collection = DB::connection('mongodb')->getCollection('prefix_scout_users');
$collection->drop();

Expand All @@ -111,7 +111,7 @@ public function testItCanCreateTheCollection()
['$search' => ['index' => 'scout', 'exists' => ['path' => 'name']]],
])->toArray();

if (count($indexedDocuments) > 0) {
if (count($indexedDocuments) >= 44) {
break;
}

Expand Down

0 comments on commit b22192b

Please sign in to comment.