43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use ReflectionClass;
|
|
use Services\Elasticsearch;
|
|
use Services\Elasticsearch\Client;
|
|
use System\Classes\Config;
|
|
use System\Classes\MyException;
|
|
|
|
class ElasticsearchTest extends TestCase
|
|
{
|
|
protected function tearDown(): void
|
|
{
|
|
$ref = new ReflectionClass(Elasticsearch::class);
|
|
$prop = $ref->getProperty('_instances');
|
|
$prop->setAccessible(true);
|
|
$prop->setValue(null, []);
|
|
|
|
$ref = new ReflectionClass(Config::class);
|
|
$prop = $ref->getProperty('config');
|
|
$prop->setAccessible(true);
|
|
$prop->setValue(null, null);
|
|
}
|
|
|
|
public function testDefaultConnectionReturnsClient(): void
|
|
{
|
|
$this->assertInstanceOf(Client::class, Elasticsearch::instance());
|
|
}
|
|
|
|
public function testInstanceIsCachedPerConnectionName(): void
|
|
{
|
|
$this->assertSame(Elasticsearch::instance('default'), Elasticsearch::instance('default'));
|
|
}
|
|
|
|
public function testUnknownConnectionNameThrows(): void
|
|
{
|
|
$this->expectException(MyException::class);
|
|
Elasticsearch::instance('nonexistent');
|
|
}
|
|
}
|