Skip to content

Commit 818c97f

Browse files
authored
Merge pull request #33 from candasm/default_configuration_namespace_bug_fix
Update default config namespace name.
2 parents a7ee6c7 + 79d368b commit 818c97f

File tree

5 files changed

+31
-31
lines changed

5 files changed

+31
-31
lines changed

README.md

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,11 @@ Laravel artisan command
5050
```
5151
$ php artisan config:publish shift31/laravel-elasticsearch
5252
```
53-
54-
Manually: Create [app/config/elasticsearch.php](src/config/elasticsearch.php), modifying the following contents
55-
accordingly:
53+
You can always read config parameters with:
5654
```php
57-
<?php
58-
59-
return array(
60-
'hosts' => array(
61-
'your.elasticsearch.server:9200'
62-
),
63-
'logPath' => 'path/to/your/elasticsearch/log',
64-
);
55+
\Config::get('shift31::elasticsearch');
6556
```
66-
Note: The keys of this array should be named according the parameters supported by Elasticsearch\Client.
57+
Note: The keys of this array should be named according the parameters supported by [Elasticsearch\Client](https://github.com/elastic/elasticsearch-php/blob/0.4/src/Elasticsearch/Client.php).
6758

6859
3. In the `'providers'` array in app/config/app.php, add `'Shift31\LaravelElasticsearch\ElasticsearchServiceProvider'`.
6960

@@ -77,11 +68,7 @@ $result = Es::search($searchParams);
7768

7869
Default Configuration
7970
---------------------
80-
If you return an empty array in the config file:
81-
82-
`'hosts'` defaults to localhost:9200
83-
84-
`'logPath'` defaults to `storage_path() . '/logs/elasticsearch.log'`
71+
If you return an empty array in the config file, Service provider [merges default config with custom config variables](https://github.com/shift31/laravel-elasticsearch/blob/master/src/Shift31/LaravelElasticsearch/ElasticsearchServiceProvider.php#L27).
8572

8673
[Default config file](src/config/elasticsearch.php) which is publishing by artisan command.
8774

phpunit.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
<testsuite name="unit">
1414
<directory suffix=".php">./tests/Unit</directory>
1515
</testsuite>
16+
<testsuite name="integration">
17+
<directory suffix=".php">./tests/Integration</directory>
18+
</testsuite>
1619
</testsuites>
1720
<filter>
1821
<blacklist>

src/Shift31/LaravelElasticsearch/ElasticsearchServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ElasticsearchServiceProvider extends ServiceProvider
1212
*/
1313
public function boot()
1414
{
15-
$this->package('shift31/laravel-elasticsearch');
15+
$this->package('shift31/laravel-elasticsearch', 'shift31');
1616
}
1717

1818
/**
@@ -21,7 +21,7 @@ public function boot()
2121
public function register()
2222
{
2323
$this->app->singleton('elasticsearch', function () {
24-
$customConfig = $this->app->config->get('elasticsearch');
24+
$customConfig = $this->app->config->get('shift31::elasticsearch');
2525
$defaultConfig = $this->loadDefaultConfig();
2626

2727
return new Client(array_merge($defaultConfig, $customConfig));

tests/Integration/ElasticsearchServiceProviderIntegrationTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace Shift31\LaravelElasticsearch\Tests\Integration;
33

44
use Orchestra\Testbench\TestCase;
5+
use Illuminate\Support\Facades\Config;
56
use Shift31\LaravelElasticsearch\Facades\Es;
67

78
class ElasticsearchServiceProviderIntegrationTest extends TestCase
@@ -14,6 +15,14 @@ public function test_elasticsearch_simple_create_request()
1415
$this->assertTrue($result['acknowledged']);
1516
}
1617

18+
public function test_get_elasticsearch_config()
19+
{
20+
$config = Config::get('shift31::elasticsearch');
21+
$this->assertArrayHasKey('hosts', $config);
22+
$this->assertArrayHasKey('logPath', $config);
23+
$this->assertArrayHasKey('logLevel', $config);
24+
}
25+
1726
protected function getPackageProviders()
1827
{
1928
return ['Shift31\LaravelElasticsearch\ElasticsearchServiceProvider'];

tests/Unit/ElasticsearchServiceProviderUnitTest.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function test_boot_method_to_set_config_file()
2424
});
2525
$configMock = Mockery::mock('Illuminate\Config\Repository', function (MockInterface $m) use ($configPath) {
2626
$m->shouldReceive('package')
27-
->with('shift31/laravel-elasticsearch', $configPath, 'laravel-elasticsearch')
27+
->with('shift31/laravel-elasticsearch', $configPath, 'shift31')
2828
->once()
2929
->andReturnSelf();
3030
});
@@ -42,24 +42,25 @@ public function test_register_method_to_set_singleton_elastic_search_client()
4242
{
4343
$configPath = $this->getSourcePath('config/elasticsearch.php');
4444
$configMock = Mockery::mock('Illuminate\Config\Repository', function (MockInterface $m) {
45-
$m->shouldReceive('get')->with('elasticsearch')->andReturn([]);
45+
$m->shouldReceive('get')->with('shift31::elasticsearch')->andReturn([]);
4646
});
4747
$filesMock = Mockery::mock('Illuminate\Filesystem\Filesystem', function (MockInterface $m) use ($configPath) {
4848
$m->shouldReceive('getRequire')
4949
->with($configPath)
5050
->once()->andReturn([]);
5151
});
52-
$application = Mockery::mock('Illuminate\Foundation\Application', function (MockInterface $m) use ($configMock, $filesMock) {
53-
$m->shouldReceive('booting')->once()->andReturnSelf();
54-
$m->shouldReceive('offsetGet')->with('config')->andReturn($configMock);
55-
$m->shouldReceive('offsetGet')->with('files')->andReturn($filesMock);
56-
$m->shouldReceive('singleton')->with('elasticsearch',
57-
Mockery::on(function ($closure) {
58-
$this->assertInstanceOf('Elasticsearch\Client', $closure());
52+
$application = Mockery::mock('Illuminate\Foundation\Application',
53+
function (MockInterface $m) use ($configMock, $filesMock) {
54+
$m->shouldReceive('booting')->once()->andReturnSelf();
55+
$m->shouldReceive('offsetGet')->with('config')->andReturn($configMock);
56+
$m->shouldReceive('offsetGet')->with('files')->andReturn($filesMock);
57+
$m->shouldReceive('singleton')->with('elasticsearch',
58+
Mockery::on(function ($closure) {
59+
$this->assertInstanceOf('Elasticsearch\Client', $closure());
5960

60-
return true;
61-
}))->once()->andReturnSelf();
62-
});
61+
return true;
62+
}))->once()->andReturnSelf();
63+
});
6364
$provider = new ElasticsearchServiceProvider($application);
6465
$this->assertNull($provider->register());
6566
}

0 commit comments

Comments
 (0)