-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
193 additions
and
13 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory suffix="Test.php">./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<coverage> | ||
<include> | ||
<directory suffix=".php">./app</directory> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</coverage> | ||
</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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
use ByteXR\LaravelScoutOpenSearch\Engines\OpenSearchEngine; | ||
use ByteXR\LaravelScoutOpenSearch\Services\OpenSearchClient; | ||
|
||
beforeEach(function () { | ||
$this->index = "opensearch_engine_test"; | ||
|
||
$this->openSearch = new OpenSearchClient( | ||
(new \OpenSearch\ClientBuilder()) | ||
->setHosts(["https://127.0.0.1:9200"]) | ||
->setSSLVerification(false) | ||
->setBasicAuthentication("admin", "admin") | ||
->build() | ||
); | ||
$this->engine = new OpenSearchEngine($this->openSearch); | ||
|
||
$data = collect(json_decode(file_get_contents("tests/data/documents.json"), true)); | ||
|
||
$this->openSearch->bulkUpdate($this->index, $data); | ||
}); | ||
|
||
it('can search full keyword', function () { | ||
$count = $this->engine->getTotalCount($this->openSearch->search($this->index, "Greenwood paper Factory")); | ||
|
||
expect($count)->toBe(1); | ||
}); | ||
|
||
it('can search partial (prefix) keyword', function () { | ||
$count = $this->engine->getTotalCount($this->openSearch->search($this->index, "greenwood")); | ||
|
||
expect($count)->toBe(1); | ||
}); | ||
|
||
it('can search partial (middle) keyword', function () { | ||
$count = $this->engine->getTotalCount($this->openSearch->search($this->index, "paper")); | ||
|
||
expect($count)->toBe(2); | ||
}); | ||
|
||
it('can search email keyword', function () { | ||
$count = $this->engine->getTotalCount($this->openSearch->search($this->index, "[email protected]")); | ||
|
||
expect($count)->toBe(1); | ||
}); | ||
|
||
it('can search partial email (prefix) keyword', function () { | ||
$count = $this->engine->getTotalCount($this->openSearch->search($this->index, "greenwood+email")); | ||
|
||
expect($count)->toBe(1); | ||
}); | ||
|
||
it('can search partial email (suffix) keyword', function () { | ||
$count = $this->engine->getTotalCount($this->openSearch->search($this->index, "@example.com")); | ||
|
||
expect($count)->toBe(2); | ||
}); | ||
|
||
it('can search postcode keyword', function () { | ||
$count = $this->engine->getTotalCount($this->openSearch->search($this->index, "AX1 BT2")); | ||
|
||
expect($count)->toBe(1); | ||
}); | ||
|
||
it('can search partial postcode (prefix) keyword', function () { | ||
$count = $this->engine->getTotalCount($this->openSearch->search($this->index, "AX1")); | ||
|
||
expect($count)->toBe(1); | ||
}); | ||
|
||
it('can search partial postcode (suffix) keyword', function () { | ||
$count = $this->engine->getTotalCount($this->openSearch->search($this->index, "XC3")); | ||
|
||
expect($count)->toBe(1); | ||
}); | ||
|
||
it('can search keyword with "of" without pulling all results with "of"', function (){ | ||
$count = $this->engine->getTotalCount($this->openSearch->search($this->index, "Isle of Green")); | ||
|
||
expect($count)->toBe(2); | ||
}); | ||
|
||
it('can search keyword with "of" without pulling all results with "of" partial (prefix)', function (){ | ||
$count = $this->engine->getTotalCount($this->openSearch->search($this->index, "Isle of")); | ||
|
||
expect($count)->toBe(3); | ||
}); | ||
|
||
it('can search by house number', function () { | ||
$count = $this->engine->getTotalCount($this->openSearch->search($this->index, "456")); | ||
|
||
expect($count)->toBe(1); | ||
}); |
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,45 @@ | ||
<?php | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Test Case | ||
|-------------------------------------------------------------------------- | ||
| | ||
| The closure you provide to your test functions is always bound to a specific PHPUnit test | ||
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may | ||
| need to change it using the "uses()" function to bind a different classes or traits. | ||
| | ||
*/ | ||
|
||
// uses(Tests\TestCase::class)->in('Feature'); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Expectations | ||
|-------------------------------------------------------------------------- | ||
| | ||
| When you're writing tests, you often need to check that values meet certain conditions. The | ||
| "expect()" function gives you access to a set of "expectations" methods that you can use | ||
| to assert different things. Of course, you may extend the Expectation API at any time. | ||
| | ||
*/ | ||
|
||
expect()->extend('toBeOne', function () { | ||
return $this->toBe(1); | ||
}); | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Functions | ||
|-------------------------------------------------------------------------- | ||
| | ||
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your | ||
| project that you don't want to repeat in every file. Here you can also expose helpers as | ||
| global functions to help you to reduce the number of lines of code in your test files. | ||
| | ||
*/ | ||
|
||
function something() | ||
{ | ||
// .. | ||
} |
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,13 @@ | ||
<?php | ||
|
||
namespace Tests; | ||
|
||
use PHPUnit\Framework\TestCase as BaseTestCase; | ||
|
||
abstract class TestCase extends BaseTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
} | ||
} |
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,5 @@ | ||
<?php | ||
|
||
test('example', function () { | ||
expect(true)->toBeTrue(); | ||
}); |
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,7 @@ | ||
[ | ||
{ "objectID": 1, "name": "Greenwood Paper Factory", "address_line_1": "123 Shore road", "address_postcode": "AX1 BT2", "email": "[email protected]" }, | ||
{ "objectID": 2, "name": "Blackwood Paper Factory", "address_line_1": "456 London street", "address_postcode": "TY8 XC3", "email": "[email protected]" }, | ||
{ "objectID": 3, "name": "Isle of Green Company", "address_line_1": "756 Brussels avenue", "address_postcode": "HY7 TJ8", "email": "[email protected]" }, | ||
{ "objectID": 4, "name": "Isle of Purple Company", "address_line_1": "7 Purple avenue", "address_postcode": "XV1 KI9", "email": "[email protected]" }, | ||
{ "objectID": 5, "name": "True storage solutions", "address_line_1": "Isle of green", "address_postcode": "UI8 GH5", "email": "[email protected]" } | ||
] |