You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.3 KiB
51 lines
1.3 KiB
11 years ago
|
<?php
|
||
|
|
||
11 years ago
|
namespace yiiunit\extensions\elasticsearch;
|
||
11 years ago
|
|
||
11 years ago
|
use Yii;
|
||
11 years ago
|
use yii\elasticsearch\Connection;
|
||
|
use yiiunit\TestCase;
|
||
|
|
||
11 years ago
|
Yii::setAlias('@yii/elasticsearch', __DIR__ . '/../../../../extensions/elasticsearch');
|
||
|
|
||
11 years ago
|
/**
|
||
11 years ago
|
* ElasticSearchTestCase is the base class for all elasticsearch related test cases
|
||
11 years ago
|
*/
|
||
|
class ElasticSearchTestCase extends TestCase
|
||
|
{
|
||
|
protected function setUp()
|
||
|
{
|
||
|
$this->mockApplication();
|
||
|
|
||
|
$databases = $this->getParam('databases');
|
||
|
$params = isset($databases['elasticsearch']) ? $databases['elasticsearch'] : null;
|
||
|
if ($params === null || !isset($params['dsn'])) {
|
||
|
$this->markTestSkipped('No elasticsearch server connection configured.');
|
||
|
}
|
||
|
$dsn = explode('/', $params['dsn']);
|
||
|
$host = $dsn[2];
|
||
|
if (strpos($host, ':')===false) {
|
||
|
$host .= ':9200';
|
||
|
}
|
||
|
if(!@stream_socket_client($host, $errorNumber, $errorDescription, 0.5)) {
|
||
|
$this->markTestSkipped('No elasticsearch server running at ' . $params['dsn'] . ' : ' . $errorNumber . ' - ' . $errorDescription);
|
||
|
}
|
||
|
|
||
|
parent::setUp();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @param bool $reset whether to clean up the test database
|
||
|
* @return Connection
|
||
|
*/
|
||
|
public function getConnection($reset = true)
|
||
|
{
|
||
|
$databases = $this->getParam('databases');
|
||
|
$params = isset($databases['elasticsearch']) ? $databases['elasticsearch'] : array();
|
||
|
$db = new Connection;
|
||
|
if ($reset) {
|
||
|
$db->open();
|
||
|
}
|
||
|
return $db;
|
||
|
}
|
||
|
}
|