|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Isswp101\Persimmon\Test; |
|
4
|
|
|
|
|
5
|
|
|
use Dotenv\Dotenv; |
|
6
|
|
|
use Dotenv\Exception\InvalidPathException; |
|
7
|
|
|
use Elasticsearch\Client; |
|
8
|
|
|
use Elasticsearch\Common\Exceptions\Missing404Exception; |
|
9
|
|
|
use Orchestra\Testbench\TestCase; |
|
10
|
|
|
use Shift31\LaravelElasticsearch\ElasticsearchServiceProvider; |
|
11
|
|
|
|
|
12
|
|
|
class BaseTestCase extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var Client |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $es; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Setup the test environment. |
|
21
|
|
|
*/ |
|
22
|
|
|
public function setUp() |
|
23
|
|
|
{ |
|
24
|
|
|
$this->loadDotenv(); |
|
25
|
|
|
|
|
26
|
|
|
parent::setUp(); |
|
27
|
|
|
|
|
28
|
|
|
$this->es = app(Client::class); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Load Dotenv. |
|
33
|
|
|
*/ |
|
34
|
|
|
protected function loadDotenv() |
|
35
|
|
|
{ |
|
36
|
|
|
$dotenv = new Dotenv(__DIR__); |
|
37
|
|
|
try { |
|
38
|
|
|
$dotenv->load(); |
|
39
|
|
|
} catch (InvalidPathException $e) { |
|
40
|
|
|
// It's workaround for Travis CI |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Define environment setup. |
|
46
|
|
|
* |
|
47
|
|
|
* @param \Illuminate\Foundation\Application $app |
|
48
|
|
|
* @return void |
|
49
|
|
|
*/ |
|
50
|
|
|
protected function getEnvironmentSetUp($app) |
|
51
|
|
|
{ |
|
52
|
|
|
$host = env('ELASTICSEARCH_AUTH_USER', '') . ':' . |
|
53
|
|
|
env('ELASTICSEARCH_AUTH_PASS', '') . '@' . |
|
54
|
|
|
env('ELASTICSEARCH_HOSTS', ''); |
|
55
|
|
|
|
|
56
|
|
|
$app['config']->set('elasticsearch.hosts', [$host]); |
|
57
|
|
|
|
|
58
|
|
|
$elasticsearchServiceProvider = new ElasticsearchServiceProvider($app); |
|
59
|
|
|
$elasticsearchServiceProvider->register(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Sleep. |
|
64
|
|
|
* |
|
65
|
|
|
* @param int $seconds |
|
66
|
|
|
*/ |
|
67
|
|
|
protected function sleep($seconds = 1) |
|
68
|
|
|
{ |
|
69
|
|
|
sleep($seconds); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Delete index. |
|
74
|
|
|
* |
|
75
|
|
|
* @param mixed $index |
|
76
|
|
|
*/ |
|
77
|
|
|
protected function deleteIndex($index) |
|
78
|
|
|
{ |
|
79
|
|
|
try { |
|
80
|
|
|
$this->es->indices()->delete(['index' => $index]); |
|
81
|
|
|
} catch (Missing404Exception $e) { |
|
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|