2
2
namespace Shift31 \LaravelElasticsearch \Tests \Unit ;
3
3
4
4
use Mockery ;
5
- use Elasticsearch \Client ;
6
5
use Mockery \MockInterface ;
7
- use Illuminate \Config \Repository ;
8
- use Illuminate \Filesystem \Filesystem ;
9
6
use Illuminate \Foundation \AliasLoader ;
10
- use Illuminate \Foundation \Application ;
11
7
use Shift31 \LaravelElasticsearch \Tests \TestCase ;
12
8
use Shift31 \LaravelElasticsearch \ElasticsearchServiceProvider ;
13
9
14
10
class ElasticsearchServiceProviderUnitTest extends TestCase
15
11
{
16
12
public function test_it_should_provide_elasticsearch ()
17
13
{
18
- $ provider = new ElasticsearchServiceProvider (Mockery::mock (Application::class ));
14
+ $ provider = new ElasticsearchServiceProvider (Mockery::mock (' Illuminate\Foundation\ Application' ));
19
15
$ this ->assertEquals (['elasticsearch ' ], $ provider ->provides ());
20
16
}
21
17
22
18
public function test_boot_method_to_set_config_file ()
23
19
{
24
20
$ configPath = realpath ($ this ->getSourcePath ('config ' ));
25
- $ filesMock = Mockery::mock (Filesystem::class , function (MockInterface $ m ) use ($ configPath ) {
21
+ $ filesMock = Mockery::mock (' Illuminate\ Filesystem\Filesystem ' , function (MockInterface $ m ) use ($ configPath ) {
26
22
$ m ->shouldReceive ('isDirectory ' )->with ($ configPath )->once ()->andReturn (true );
27
23
$ m ->shouldReceive ('isDirectory ' )->withAnyArgs ()->times (3 )->andReturn (false );
28
24
});
29
- $ configMock = Mockery::mock (Repository::class , function (MockInterface $ m ) use ($ configPath ) {
25
+ $ configMock = Mockery::mock (' Illuminate\Config\ Repository' , function (MockInterface $ m ) use ($ configPath ) {
30
26
$ m ->shouldReceive ('package ' )
31
27
->with ('shift31/laravel-elasticsearch ' , $ configPath , 'laravel-elasticsearch ' )
32
28
->once ()
33
29
->andReturnSelf ();
34
30
});
35
- $ application = Mockery::mock (Application::class, function (MockInterface $ m ) use ($ configMock , $ filesMock ) {
36
- $ m ->shouldReceive ('offsetGet ' )->with ('config ' )->once ()->andReturn ($ configMock );
37
- $ m ->shouldReceive ('offsetGet ' )->with ('files ' )->times (4 )->andReturn ($ filesMock );
38
- $ m ->shouldReceive ('offsetGet ' )->with ('path ' )->once ()->andReturn ($ this ->getSourcePath ());
39
- });
31
+ $ application = Mockery::mock ('Illuminate\Foundation\Application ' ,
32
+ function (MockInterface $ m ) use ($ configMock , $ filesMock ) {
33
+ $ m ->shouldReceive ('offsetGet ' )->with ('config ' )->once ()->andReturn ($ configMock );
34
+ $ m ->shouldReceive ('offsetGet ' )->with ('files ' )->times (4 )->andReturn ($ filesMock );
35
+ $ m ->shouldReceive ('offsetGet ' )->with ('path ' )->once ()->andReturn ($ this ->getSourcePath ());
36
+ });
40
37
$ provider = new ElasticsearchServiceProvider ($ application );
41
38
$ this ->assertNull ($ provider ->boot ());
42
39
}
43
40
44
41
public function test_register_method_to_set_singleton_elastic_search_client ()
45
42
{
46
43
$ configPath = $ this ->getSourcePath ('config/elasticsearch.php ' );
47
- $ configMock = Mockery::mock (Repository::class , function (MockInterface $ m ) {
44
+ $ configMock = Mockery::mock (' Illuminate\Config\ Repository' , function (MockInterface $ m ) {
48
45
$ m ->shouldReceive ('get ' )->with ('elasticsearch ' )->andReturn ([]);
49
46
});
50
- $ filesMock = Mockery::mock (Filesystem::class , function (MockInterface $ m ) use ($ configPath ) {
47
+ $ filesMock = Mockery::mock (' Illuminate\ Filesystem\Filesystem ' , function (MockInterface $ m ) use ($ configPath ) {
51
48
$ m ->shouldReceive ('getRequire ' )
52
49
->with ($ configPath )
53
50
->once ()->andReturn ([]);
54
51
});
55
- $ application = Mockery::mock (Application::class , function (MockInterface $ m ) use ($ configMock , $ filesMock ) {
52
+ $ application = Mockery::mock (' Illuminate\Foundation\ Application' , function (MockInterface $ m ) use ($ configMock , $ filesMock ) {
56
53
$ m ->shouldReceive ('booting ' )->once ()->andReturnSelf ();
57
54
$ m ->shouldReceive ('offsetGet ' )->with ('config ' )->andReturn ($ configMock );
58
55
$ m ->shouldReceive ('offsetGet ' )->with ('files ' )->andReturn ($ filesMock );
59
56
$ m ->shouldReceive ('singleton ' )->with ('elasticsearch ' ,
60
57
Mockery::on (function ($ closure ) {
61
- $ this ->assertInstanceOf (Client::class , $ closure ());
58
+ $ this ->assertInstanceOf (' Elasticsearch\ Client' , $ closure ());
62
59
63
60
return true ;
64
61
}))->once ()->andReturnSelf ();
@@ -69,7 +66,7 @@ public function test_register_method_to_set_singleton_elastic_search_client()
69
66
70
67
public function test_register_method_to_set_elastic_search_facade ()
71
68
{
72
- $ application = Mockery::mock (Application::class , function (MockInterface $ m ) {
69
+ $ application = Mockery::mock (' Illuminate\Foundation\ Application' , function (MockInterface $ m ) {
73
70
$ m ->shouldReceive ('singleton ' )->once ()->andReturnSelf ();
74
71
$ m ->shouldReceive ('booting ' )->with (Mockery::on (function ($ closure ) {
75
72
$ closure ();
0 commit comments