|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace ScoutEngines\Postgres\Test; |
| 4 | + |
| 5 | + |
| 6 | +use Mockery; |
| 7 | +use Laravel\Scout\Builder; |
| 8 | +use Laravel\Scout\EngineManager; |
| 9 | +use Illuminate\Database\Eloquent\Model; |
| 10 | +use Illuminate\Contracts\Config\Repository; |
| 11 | +use ScoutEngines\Postgres\TsQuery\ToTsQuery; |
| 12 | +use Illuminate\Contracts\Foundation\Application; |
| 13 | +use ScoutEngines\Postgres\TsQuery\PlainToTsQuery; |
| 14 | +use ScoutEngines\Postgres\TsQuery\PhraseToTsQuery; |
| 15 | +use Illuminate\Database\ConnectionResolverInterface; |
| 16 | +use ScoutEngines\Postgres\TsQuery\WebSearchToTsQuery; |
| 17 | +use ScoutEngines\Postgres\PostgresEngineServiceProvider; |
| 18 | + |
| 19 | +class PostgresEngineServiceProviderTest extends TestCase |
| 20 | +{ |
| 21 | + public function test_it_boots() |
| 22 | + { |
| 23 | + list($provider) = $this->newProvider(); |
| 24 | + $provider->boot(); |
| 25 | + } |
| 26 | + |
| 27 | + public function test_it_creates_macros() |
| 28 | + { |
| 29 | + list($provider) = $this->newProvider(); |
| 30 | + $provider->boot(); |
| 31 | + |
| 32 | + $builder = new Builder(Mockery::mock(Model::class), ''); |
| 33 | + |
| 34 | + foreach ([ |
| 35 | + 'usingPhraseQuery' => PhraseToTsQuery::class, |
| 36 | + 'usingPlainQuery' => PlainToTsQuery::class, |
| 37 | + 'usingTsQuery' => ToTsQuery::class, |
| 38 | + 'usingWebSearchQuery' => WebSearchToTsQuery::class, |
| 39 | + ] as $macro => $class) { |
| 40 | + $this->assertTrue(Builder::hasMacro($macro)); |
| 41 | + |
| 42 | + $callback = $builder->{$macro}()->callback; |
| 43 | + $tsFunction = $callback($builder, []); |
| 44 | + $this->assertInstanceOf($class, $tsFunction); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + protected function newProvider() |
| 49 | + { |
| 50 | + $app = Mockery::mock(Application::class); |
| 51 | + $resolver = Mockery::mock(ConnectionResolverInterface::class); |
| 52 | + $app->shouldReceive('get') |
| 53 | + ->with('db') |
| 54 | + ->andReturn($resolver); |
| 55 | + $config = Mockery::mock(Repository::class) |
| 56 | + ->shouldReceive('get') |
| 57 | + ->with('scout.pgsql', []) |
| 58 | + ->andReturn([]); |
| 59 | + $app->shouldReceive('get') |
| 60 | + ->with('config') |
| 61 | + ->andReturn($config); |
| 62 | + $manager = new EngineManager($app); |
| 63 | + $app->shouldReceive('make') |
| 64 | + ->with(EngineManager::class) |
| 65 | + ->once() |
| 66 | + ->andReturn($manager); |
| 67 | + |
| 68 | + $provider = new PostgresEngineServiceProvider($app); |
| 69 | + |
| 70 | + return [$provider, $app]; |
| 71 | + } |
| 72 | +} |
0 commit comments