-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup test suite calling actual meili instance
- Loading branch information
1 parent
8403c5e
commit c2e1573
Showing
6 changed files
with
176 additions
and
69 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
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,29 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
verbose="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Spatie Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<coverage> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</coverage> | ||
<logging> | ||
<junit outputFile="build/report.junit.xml"/> | ||
</logging> | ||
<php> | ||
<env name="APP_DEBUG" value="true" /> | ||
</php> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false"> | ||
<testsuites> | ||
<testsuite name="Spatie Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<logging> | ||
<junit outputFile="build/report.junit.xml"/> | ||
</logging> | ||
<php> | ||
<env name="APP_DEBUG" value="true"/> | ||
</php> | ||
<source> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</source> | ||
</phpunit> |
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,26 +1,32 @@ | ||
<?php | ||
|
||
namespace StatamicRadPack\meilisearch\Tests; | ||
namespace StatamicRadPack\Meilisearch\Tests; | ||
|
||
use Orchestra\Testbench\TestCase as Orchestra; | ||
use StatamicRadPack\meilisearch\ServiceProvider; | ||
use Statamic\Testing\AddonTestCase; | ||
use StatamicRadPack\Meilisearch\ServiceProvider; | ||
|
||
class TestCase extends Orchestra | ||
class TestCase extends AddonTestCase | ||
{ | ||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
} | ||
protected string $addonServiceProvider = ServiceProvider::class; | ||
|
||
protected function getPackageProviders($app) | ||
{ | ||
return [ | ||
ServiceProvider::class, | ||
]; | ||
} | ||
protected $shouldFakeVersion = true; | ||
|
||
public function getEnvironmentSetUp($app) | ||
protected function resolveApplicationConfiguration($app) | ||
{ | ||
// ... | ||
parent::resolveApplicationConfiguration($app); | ||
|
||
// add driver | ||
$app['config']->set('statamic.search.drivers.meilisearch', [ | ||
'credentials' => [ | ||
'url' => 'http://localhost:7700', | ||
'secret' => 'LARAVEL-HERD', | ||
], | ||
]); | ||
|
||
// add index | ||
$app['config']->set('statamic.search.indexes.meilisearch_index', [ | ||
'driver' => 'meilisearch', | ||
'searchables' => ['collection:pages'], | ||
]); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?php | ||
|
||
namespace StatamicRadPack\Meilisearch\Tests\Unit; | ||
|
||
use Meilisearch\Client; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use Statamic\Facades; | ||
use StatamicRadPack\Meilisearch\Tests\TestCase; | ||
|
||
class IndexTest extends TestCase | ||
{ | ||
#[Test] | ||
public function it_sets_up_the_client_correctly() | ||
{ | ||
$index = Facades\Search::index('meilisearch_index'); | ||
|
||
$this->assertInstanceOf(Client::class, $index->client()); | ||
} | ||
|
||
#[Test] | ||
public function it_adds_documents_to_the_index() | ||
{ | ||
$collection = Facades\Collection::make() | ||
->handle('pages') | ||
->title('Pages') | ||
->save(); | ||
|
||
$entry1 = Facades\Entry::make() | ||
->id('test-2') | ||
->collection('pages') | ||
->data(['title' => 'Entry 1']) | ||
->save(); | ||
|
||
$entry2 = Facades\Entry::make() | ||
->id('test-1') | ||
->collection('pages') | ||
->data(['title' => 'Entry 2']) | ||
->save(); | ||
|
||
sleep(1); // give meili some time to process | ||
|
||
$index = Facades\Search::index('meilisearch_index'); | ||
|
||
$this->assertCount(2, $index->searchUsingApi('Entry')); | ||
} | ||
|
||
#[Test] | ||
public function it_updates_documents_to_the_index() | ||
{ | ||
$collection = Facades\Collection::make() | ||
->handle('pages') | ||
->title('Pages') | ||
->save(); | ||
|
||
$entry1 = Facades\Entry::make() | ||
->id('test-2') | ||
->collection('pages') | ||
->data(['title' => 'Entry 1']) | ||
->save(); | ||
|
||
$entry2 = tap(Facades\Entry::make() | ||
->id('test-1') | ||
->collection('pages') | ||
->data(['title' => 'Entry 2'])) | ||
->save(); | ||
|
||
sleep(1); // give meili some time to process | ||
|
||
$index = Facades\Search::index('meilisearch_index'); | ||
|
||
$results = collect($index->searchUsingApi('Entry'))->pluck('title'); | ||
|
||
$this->assertContains('Entry 1', $results); | ||
$this->assertContains('Entry 2', $results); | ||
|
||
$entry2->merge(['title' => 'Entry 2 Updated'])->save(); | ||
|
||
sleep(1); // give meili some time to process | ||
|
||
$results = collect($index->searchUsingApi('Entry'))->pluck('title'); | ||
|
||
$this->assertContains('Entry 2 Updated', $results); | ||
} | ||
|
||
#[Test] | ||
public function it_removes_documents_from_the_index() | ||
{ | ||
$collection = Facades\Collection::make() | ||
->handle('pages') | ||
->title('Pages') | ||
->save(); | ||
|
||
$entry1 = Facades\Entry::make() | ||
->id('test-2') | ||
->collection('pages') | ||
->data(['title' => 'Entry 1']) | ||
->save(); | ||
|
||
$entry2 = tap(Facades\Entry::make() | ||
->id('test-1') | ||
->collection('pages') | ||
->data(['title' => 'Entry 2'])) | ||
->save(); | ||
|
||
$entry2->delete(); | ||
|
||
$index = Facades\Search::index('meilisearch_index'); | ||
|
||
sleep(1); // give meili some time to process | ||
|
||
$this->assertCount(1, $index->searchUsingApi('Entry')); | ||
} | ||
} |