-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [10.x] Supports PHP 8.4 Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * Apply fixes from StyleCI * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * Apply fixes from StyleCI * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * Apply fixes from StyleCI * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * Apply fixes from StyleCI * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * Apply fixes from StyleCI * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * Apply fixes from StyleCI * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * Apply fixes from StyleCI * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * Apply fixes from StyleCI * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * Apply fixes from StyleCI * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> --------- Signed-off-by: Mior Muhammad Zaki <[email protected]> Co-authored-by: StyleCI Bot <[email protected]>
- Loading branch information
1 parent
036efa7
commit 13cb646
Showing
47 changed files
with
1,891 additions
and
1,728 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
providers: | ||
- Workbench\App\Providers\WorkbenchServiceProvider | ||
- Laravel\Scout\ScoutServiceProvider | ||
|
||
migrations: true | ||
migrations: | ||
- workbench/database/migrations | ||
|
||
workbench: | ||
install: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,23 +4,20 @@ | |
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Foundation\Testing\LazilyRefreshDatabase; | ||
use Laravel\Scout\Tests\Fixtures\SearchableModelWithUnloadedValue; | ||
use Laravel\Scout\Tests\Fixtures\SearchableUserModel; | ||
use Laravel\Scout\Tests\Fixtures\SearchableUserModelWithCustomCreatedAt; | ||
use Laravel\Scout\Tests\Fixtures\SearchableUserModelWithCustomSearchableData; | ||
use Orchestra\Testbench\Concerns\WithLaravelMigrations; | ||
use Illuminate\Support\Collection; | ||
use Orchestra\Testbench\Attributes\WithConfig; | ||
use Orchestra\Testbench\Attributes\WithMigration; | ||
use Orchestra\Testbench\Concerns\WithWorkbench; | ||
use Orchestra\Testbench\Factories\UserFactory; | ||
use Orchestra\Testbench\TestCase; | ||
use Workbench\App\Models\SearchableUser; | ||
|
||
#[WithConfig('scout.driver', 'collection')] | ||
#[WithMigration] | ||
class CollectionEngineTest extends TestCase | ||
{ | ||
use LazilyRefreshDatabase, WithLaravelMigrations, WithWorkbench; | ||
|
||
protected function defineEnvironment($app) | ||
{ | ||
$app->make('config')->set('scout.driver', 'collection'); | ||
} | ||
use LazilyRefreshDatabase; | ||
use WithWorkbench; | ||
|
||
protected function afterRefreshingDatabase() | ||
{ | ||
|
@@ -39,113 +36,113 @@ protected function afterRefreshingDatabase() | |
|
||
public function test_it_can_retrieve_results_with_empty_search() | ||
{ | ||
$models = SearchableUserModel::search()->get(); | ||
$models = SearchableUser::search()->get(); | ||
|
||
$this->assertCount(2, $models); | ||
} | ||
|
||
public function test_it_can_retrieve_results() | ||
{ | ||
$models = SearchableUserModel::search('Taylor')->where('email', '[email protected]')->get(); | ||
$models = SearchableUser::search('Taylor')->where('email', '[email protected]')->get(); | ||
$this->assertCount(1, $models); | ||
$this->assertEquals(1, $models[0]->id); | ||
|
||
$models = SearchableUserModel::search('Taylor')->query(function ($query) { | ||
$models = SearchableUser::search('Taylor')->query(function ($query) { | ||
$query->where('email', 'like', '[email protected]'); | ||
})->get(); | ||
|
||
$this->assertCount(1, $models); | ||
$this->assertEquals(1, $models[0]->id); | ||
|
||
$models = SearchableUserModel::search('Abigail')->where('email', '[email protected]')->get(); | ||
$models = SearchableUser::search('Abigail')->where('email', '[email protected]')->get(); | ||
$this->assertCount(1, $models); | ||
$this->assertEquals(2, $models[0]->id); | ||
|
||
$models = SearchableUserModel::search('Taylor')->where('email', '[email protected]')->get(); | ||
$models = SearchableUser::search('Taylor')->where('email', '[email protected]')->get(); | ||
$this->assertCount(0, $models); | ||
|
||
$models = SearchableUserModel::search('Taylor')->where('email', '[email protected]')->get(); | ||
$models = SearchableUser::search('Taylor')->where('email', '[email protected]')->get(); | ||
$this->assertCount(1, $models); | ||
|
||
$models = SearchableUserModel::search('otwell')->get(); | ||
$models = SearchableUser::search('otwell')->get(); | ||
$this->assertCount(2, $models); | ||
|
||
$models = SearchableUserModel::search('laravel')->get(); | ||
$models = SearchableUser::search('laravel')->get(); | ||
$this->assertCount(2, $models); | ||
|
||
$models = SearchableUserModel::search('foo')->get(); | ||
$models = SearchableUser::search('foo')->get(); | ||
$this->assertCount(0, $models); | ||
|
||
$models = SearchableUserModel::search('Abigail')->where('email', '[email protected]')->get(); | ||
$models = SearchableUser::search('Abigail')->where('email', '[email protected]')->get(); | ||
$this->assertCount(0, $models); | ||
} | ||
|
||
public function test_it_can_retrieve_results_matching_to_custom_searchable_data() | ||
{ | ||
$models = SearchableUserModelWithCustomSearchableData::search('rolyaT')->get(); | ||
$models = SearchableUserWithCustomSearchableData::search('rolyaT')->get(); | ||
$this->assertCount(1, $models); | ||
} | ||
|
||
public function test_it_can_paginate_results() | ||
{ | ||
$models = SearchableUserModel::search('Taylor')->where('email', '[email protected]')->paginate(); | ||
$models = SearchableUser::search('Taylor')->where('email', '[email protected]')->paginate(); | ||
$this->assertCount(1, $models); | ||
|
||
$models = SearchableUserModel::search('Taylor')->where('email', '[email protected]')->paginate(); | ||
$models = SearchableUser::search('Taylor')->where('email', '[email protected]')->paginate(); | ||
$this->assertCount(0, $models); | ||
|
||
$models = SearchableUserModel::search('Taylor')->where('email', '[email protected]')->paginate(); | ||
$models = SearchableUser::search('Taylor')->where('email', '[email protected]')->paginate(); | ||
$this->assertCount(1, $models); | ||
|
||
$models = SearchableUserModel::search('laravel')->paginate(); | ||
$models = SearchableUser::search('laravel')->paginate(); | ||
$this->assertCount(2, $models); | ||
|
||
$dummyQuery = function ($query) { | ||
$query->where('name', '!=', 'Dummy'); | ||
}; | ||
$models = SearchableUserModel::search('laravel')->query($dummyQuery)->orderBy('name')->paginate(1, 'page', 1); | ||
$models = SearchableUser::search('laravel')->query($dummyQuery)->orderBy('name')->paginate(1, 'page', 1); | ||
$this->assertCount(1, $models); | ||
$this->assertEquals('Abigail Otwell', $models[0]->name); | ||
|
||
$models = SearchableUserModel::search('laravel')->query($dummyQuery)->orderBy('name')->paginate(1, 'page', 2); | ||
$models = SearchableUser::search('laravel')->query($dummyQuery)->orderBy('name')->paginate(1, 'page', 2); | ||
$this->assertCount(1, $models); | ||
$this->assertEquals('Taylor Otwell', $models[0]->name); | ||
} | ||
|
||
public function test_limit_is_applied() | ||
{ | ||
$models = SearchableUserModel::search('laravel')->get(); | ||
$models = SearchableUser::search('laravel')->get(); | ||
$this->assertCount(2, $models); | ||
|
||
$models = SearchableUserModel::search('laravel')->take(1)->get(); | ||
$models = SearchableUser::search('laravel')->take(1)->get(); | ||
$this->assertCount(1, $models); | ||
} | ||
|
||
public function test_it_can_order_results() | ||
{ | ||
$models = SearchableUserModel::search('laravel')->orderBy('name', 'asc')->paginate(1, 'page', 1); | ||
$models = SearchableUser::search('laravel')->orderBy('name', 'asc')->paginate(1, 'page', 1); | ||
$this->assertCount(1, $models); | ||
$this->assertEquals('Abigail Otwell', $models[0]->name); | ||
|
||
$models = SearchableUserModel::search('laravel')->orderBy('name', 'desc')->paginate(1, 'page', 1); | ||
$models = SearchableUser::search('laravel')->orderBy('name', 'desc')->paginate(1, 'page', 1); | ||
$this->assertCount(1, $models); | ||
$this->assertEquals('Taylor Otwell', $models[0]->name); | ||
} | ||
|
||
public function test_it_can_order_by_latest_and_oldest() | ||
{ | ||
$models = SearchableUserModel::search('laravel')->latest()->paginate(1, 'page', 1); | ||
$models = SearchableUser::search('laravel')->latest()->paginate(1, 'page', 1); | ||
$this->assertCount(1, $models); | ||
$this->assertEquals('Abigail Otwell', $models[0]->name); | ||
|
||
$models = SearchableUserModel::search('laravel')->oldest()->paginate(1, 'page', 1); | ||
$models = SearchableUser::search('laravel')->oldest()->paginate(1, 'page', 1); | ||
$this->assertCount(1, $models); | ||
$this->assertEquals('Taylor Otwell', $models[0]->name); | ||
} | ||
|
||
public function test_it_can_order_by_custom_model_created_at_timestamp() | ||
{ | ||
$query = SearchableUserModelWithCustomCreatedAt::search()->latest(); | ||
$query = SearchableUserWithCustomCreatedAt::search()->latest(); | ||
|
||
$this->assertCount(1, $query->orders); | ||
$this->assertEquals('created', $query->orders[0]['column']); | ||
|
@@ -155,8 +152,43 @@ public function test_it_calls_make_searchable_using_before_searching() | |
{ | ||
Model::preventAccessingMissingAttributes(true); | ||
|
||
$models = SearchableModelWithUnloadedValue::search('loaded')->get(); | ||
$models = SearchableUserWithUnloadedValue::search('loaded')->get(); | ||
|
||
$this->assertCount(2, $models); | ||
} | ||
} | ||
|
||
class SearchableUserWithCustomCreatedAt extends SearchableUser | ||
{ | ||
public const CREATED_AT = 'created'; | ||
} | ||
|
||
class SearchableUserWithCustomSearchableData extends SearchableUser | ||
{ | ||
/** {@inheritDoc} */ | ||
public function toSearchableArray(): array | ||
{ | ||
return [ | ||
'reversed_name' => strrev($this->name), | ||
]; | ||
} | ||
} | ||
|
||
class SearchableUserWithUnloadedValue extends SearchableUser | ||
{ | ||
/** {@inheritDoc} */ | ||
public function toSearchableArray() | ||
{ | ||
return [ | ||
'value' => $this->unloadedValue, | ||
]; | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
public function makeSearchableUsing(Collection $models) | ||
{ | ||
return $models->each( | ||
fn ($model) => $model->unloadedValue = 'loaded', | ||
); | ||
} | ||
} |
Oops, something went wrong.