Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Dec 5, 2023
1 parent 66934d6 commit daa0e89
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 23 deletions.
48 changes: 39 additions & 9 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ jobs:
tests:
runs-on: ubuntu-22.04

services:
meilisearch:
image: getmeili/meilisearch:latest
ports:
- 7700:7700
env:
MEILI_MASTER_KEY: masterKey
MEILI_NO_ANALYTICS: true

strategy:
fail-fast: true
matrix:
Expand Down Expand Up @@ -57,5 +48,44 @@ jobs:
- name: Execute tests
run: vendor/bin/phpunit --verbose

tests-using-meilisearch:
runs-on: ubuntu-22.04

services:
meilisearch:
image: getmeili/meilisearch:latest
ports:
- 7700:7700
env:
MEILI_MASTER_KEY: masterKey
MEILI_NO_ANALYTICS: true

strategy:
fail-fast: true
matrix:
php: ['8.0', 8.1, 8.2, 8.3]

name: PHP ${{ matrix.php }} using Meilisearch

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip
ini-values: error_reporting=E_ALL
tools: composer:v2
coverage: none

- name: Install dependencies
run: |
composer update --prefer-dist --no-interaction --no-progress
- name: Execute tests
run: vendor/bin/phpunit --verbose --group external-network,meilisearch
env:
MEILISEARCH_HOST: "http://localhost:7700"
2 changes: 0 additions & 2 deletions testbench.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
providers:
- Laravel\Scout\ScoutServiceProvider

migrations: true
20 changes: 18 additions & 2 deletions tests/Integration/AlgoliaSearchableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Laravel\Scout\Tests\Fixtures\User;

/**
* @group algolia
* @group external-network
*/
class AlgoliaSearchableTest extends TestCase
Expand All @@ -24,16 +25,26 @@ protected function defineEnvironment($app)
$this->markTestSkipped();
}

$app['config']->set('scout.driver', 'algolia');
$this->defineScoutEnvironment($app);
}

/**
* Define database migrations.
*
* @return void
*/
protected function defineDatabaseMigrations(): void
protected function defineDatabaseMigrations()
{
$this->defineScoutDatabaseMigrations();
}

/**
* Perform any work that should take place once the database has finished refreshing.
*
* @return void
*/
protected function afterRefreshingDatabase()
{
$this->importScoutIndexFrom(User::class);
}

Expand Down Expand Up @@ -152,4 +163,9 @@ public function test_it_can_use_paginated_search_with_query_callback()
12 => 'Reta Larkin',
], $page2->pluck('name', 'id')->all());
}

protected static function scoutDriver(): string
{
return 'algolia';
}
}
7 changes: 6 additions & 1 deletion tests/Integration/CollectionSearchableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CollectionSearchableTest extends DatabaseSearchableTest
*/
protected function defineEnvironment($app)
{
$app['config']->set('scout.driver', 'collection');
$this->defineScoutEnvironment($app);
}

public function test_it_can_use_basic_search_with_query_callback_to_fetch_keys()
Expand All @@ -31,4 +31,9 @@ public function test_it_can_use_basic_search_with_query_callback_to_fetch_keys()

$this->assertSame($this->itCanUseBasicSearchToFetchKeys()->all(), $results->all());
}

protected static function scoutDriver(): string
{
return 'collection';
}
}
7 changes: 6 additions & 1 deletion tests/Integration/DatabaseSearchableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DatabaseSearchableTest extends TestCase
*/
protected function defineEnvironment($app)
{
$app['config']->set('scout.driver', 'database');
$this->defineScoutEnvironment($app);
}

/**
Expand Down Expand Up @@ -129,4 +129,9 @@ public function test_it_can_use_paginated_search_with_query_callback()
1 => 'Laravel Framework',
], $page2->pluck('name', 'id')->all());
}

protected static function scoutDriver(): string
{
return 'database';
}
}
20 changes: 18 additions & 2 deletions tests/Integration/MeilisearchSearchableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Laravel\Scout\Tests\Fixtures\User;

/**
* @group meilisearch
* @group external-network
*/
class MeilisearchSearchableTest extends TestCase
Expand All @@ -26,16 +27,26 @@ protected function defineEnvironment($app)
return;
}

$app['config']->set('scout.driver', 'meilisearch');
$this->defineScoutEnvironment($app);
}

/**
* Define database migrations.
*
* @return void
*/
protected function defineDatabaseMigrations(): void
protected function defineDatabaseMigrations()
{
$this->defineScoutDatabaseMigrations();
}

/**
* Perform any work that should take place once the database has finished refreshing.
*
* @return void
*/
protected function afterRefreshingDatabase()
{
$this->importScoutIndexFrom(User::class);
}

Expand Down Expand Up @@ -154,4 +165,9 @@ public function test_it_can_use_paginated_search_with_query_callback()
44 => 'Amos Larson Sr.',
], $page2->pluck('name', 'id')->all());
}

protected static function scoutDriver(): string
{
return 'meilisearch';
}
}
11 changes: 11 additions & 0 deletions tests/Integration/SearchableTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@

trait SearchableTests
{
/**
* Define environment setup.
*
* @param \Illuminate\Foundation\Application $app
* @return void
*/
protected function defineScoutEnvironment($app)
{
$app['config']->set('scout.driver', static::scoutDriver());
}

/**
* Define database migrations.
*/
Expand Down
31 changes: 25 additions & 6 deletions tests/Integration/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,41 @@

namespace Laravel\Scout\Tests\Integration;

use Illuminate\Support\ProcessUtil;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Orchestra\Testbench\Concerns\WithLaravelMigrations;
use Orchestra\Testbench\Concerns\WithWorkbench;

use function Orchestra\Testbench\artisan;
use function Orchestra\Testbench\remote;

class TestCase extends \Orchestra\Testbench\TestCase
abstract class TestCase extends \Orchestra\Testbench\TestCase
{
use WithWorkbench;
use RefreshDatabase, WithWorkbench;

protected function importScoutIndexFrom($model = null)
{
rescue(fn () => remote(sprintf('scout:import --model=%s', ProcessUtil::escapeArgument($model)))->mustRun());
if (class_exists($model)) {
artisan($this, 'scout:index', ['name' => $model]);
}

artisan($this, 'scout:import', ['model' => $model]);

sleep(1);
}

protected function resetScoutIndexes()
/**
* Clean up the testing environment before the next test case.
*
* @return void
*/
public static function tearDownAfterClass(): void
{
rescue(fn () => remote('scout:delete-all-indexes')->mustRun());
remote('scout:delete-all-indexes', [
'SCOUT_DRIVER' => static::scoutDriver(),
])->mustRun();

parent::tearDownAfterClass();
}

abstract protected static function scoutDriver(): string;
}

0 comments on commit daa0e89

Please sign in to comment.