Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests (in progress)
  • Loading branch information
Arayik authored and Arayik committed Feb 20, 2023
commit 0748b8145f67c1359de92515eb8f460645715d89
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
run: composer install --prefer-dist --no-progress --no-suggest --ignore-platform-req=ext-imagick

- name: Run Tests
run: ./vendor/bin/pest
run: ./vendor/bin/phpunit tests
13 changes: 10 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
"Typesense\\LaravelTypesense\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Typesense\\LaravelTypesense\\Tests\\": "tests/"
}
},
"extra": {
"laravel": {
"providers": [
Expand All @@ -47,14 +52,16 @@
"illuminate/pagination": "^7.0|^8.0|^9.0",
"illuminate/queue": "^7.0|^8.0|^9.0",
"illuminate/support": "^7.0|^8.0|^9.0",
"typesense/typesense-php": "^4.0"
"typesense/typesense-php": "^4.0",
"symfony/http-client": "^5.4"
},
"config": {
"platform": {
"php": "8.0"
},
"allow-plugins": {
"pestphp/pest-plugin": true
"pestphp/pest-plugin": true,
"php-http/discovery": true
}
},
"suggest": {
Expand All @@ -63,6 +70,6 @@
"require-dev": {
"phpunit/phpunit": "^8.0|^9.0",
"mockery/mockery": "^1.3",
"pestphp/pest": "^1.22"
"orchestra/testbench": "^6.17|^7.0|^8.0"
}
}
5 changes: 5 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@
<directory suffix=".php">./src</directory>
</include>
</coverage>
<php>
<env name="APP_ENV" value="testing"/>
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/>
<env name="DB_CONNECTION" value="testing"/>
</php>
</phpunit>
5 changes: 0 additions & 5 deletions tests/ExampleTest.php

This file was deleted.

16 changes: 16 additions & 0 deletions tests/Feature/ExampleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Typesense\LaravelTypesense\Tests\Feature;

use Typesense\LaravelTypesense\Tests\Fixtures\UserModel;
use Typesense\LaravelTypesense\Tests\TestCase;

class ExampleTest extends TestCase
{
public function test_search()
{
$models = UserModel::search('[email protected]')->get();

$this->assertCount(1, $models);
}
}
67 changes: 67 additions & 0 deletions tests/Fixtures/UserModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Typesense\LaravelTypesense\Tests\Fixtures;

use Illuminate\Foundation\Auth\User as Model;
use Laravel\Scout\Searchable;
use Typesense\LaravelTypesense\Interfaces\TypesenseDocument;

class UserModel extends Model implements TypesenseDocument
{
use Searchable;

protected $fillable = ['email', 'name', 'password'];

public $timestamps = false;

protected $table = 'users';

public function toSearchableArray(): array
{
return array_merge(
$this->toArray(),
[
'id' => (string)$this->id,
'created_at' => $this->created_at->timestamp,
]
);
}

public function getCollectionSchema(): array
{
return [
'name' => $this->searchableAs(),
'fields' => [
[
'name' => 'id',
'type' => 'string',
'facet' => true,
],
[
'name' => 'name',
'type' => 'string',
'facet' => true,
],
[
'name' => 'email',
'type' => 'string',
'facet' => true,
],
[
'name' => 'created_at',
'type' => 'int64',
'facet' => true,
],
],
'default_sorting_field' => 'created_at',
];
}

public function typesenseQueryBy(): array
{
return [
'name',
'email',
];
}
}
45 changes: 0 additions & 45 deletions tests/Pest.php

This file was deleted.

64 changes: 64 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace Typesense\LaravelTypesense\Tests;

use Illuminate\Foundation\Testing\WithFaker;
use Orchestra\Testbench\TestCase as Orchestra;
use Typesense\LaravelTypesense\Tests\Fixtures\UserModel;
use Typesense\LaravelTypesense\TypesenseServiceProvider;

abstract class TestCase extends Orchestra
{
use WithFaker;

protected function getPackageProviders($app)
{
return [TypesenseServiceProvider::class];
}

protected function defineEnvironment($app)
{
$app->make('config')->set('scout.driver', 'typesense');
$app->make('config')->set('scout.typesense',
[
'api_key' => 'xyz',
'nodes' => [
[
'host' => 'localhost',
'port' => '8108',
'path' => '',
'protocol' => 'http',
],
],
'nearest_node' => [
'host' => 'localhost',
'port' => '8108',
'path' => '',
'protocol' => 'http',
],
'connection_timeout_seconds' => 2,
'healthcheck_interval_seconds' => 30,
'num_retries' => 3,
'retry_interval_seconds' => 1,
]
);
}

protected function defineDatabaseMigrations()
{
$this->setUpFaker();
$this->loadLaravelMigrations();

UserModel::create([
'name' => 'Taylor Otwell',
'email' => '[email protected]',
'password' => 'asd'
]);

UserModel::create([
'name' => 'Abigail Otwell',
'email' => '[email protected]',
'password' => 'asd'
]);
}
}