@@ 17-53 (lines=37) @@ | ||
14 | ||
15 | final class IndexCreateOrUpdateMappingCommandTest extends TestCase |
|
16 | { |
|
17 | public function testCreateOrUpdateMappingMustSucceed(): void |
|
18 | { |
|
19 | $this->mock(Filesystem::class, function (MockInterface $mock) { |
|
20 | $mock->shouldReceive('exists') |
|
21 | ->once() |
|
22 | ->andReturn(true); |
|
23 | ||
24 | $mock->shouldReceive('get') |
|
25 | ->once() |
|
26 | ->andReturn('{}'); |
|
27 | }); |
|
28 | ||
29 | $this->mock(Client::class, function (MockInterface $mock) { |
|
30 | $mock->shouldReceive('indices') |
|
31 | ->times(2) |
|
32 | ->andReturn( |
|
33 | $this->mock(IndicesNamespace::class, function (MockInterface $mock) { |
|
34 | $mock->shouldReceive('exists') |
|
35 | ->once() |
|
36 | ->andReturn(true); |
|
37 | ||
38 | $mock->shouldReceive('putMapping') |
|
39 | ->once() |
|
40 | ->andReturn([]); |
|
41 | }) |
|
42 | ); |
|
43 | }); |
|
44 | ||
45 | $this->artisan( |
|
46 | 'laravel-elasticsearch:utils:index-create-or-update-mapping', |
|
47 | [ |
|
48 | 'index-name' => 'valid_index_name', |
|
49 | 'mapping-file-path' => '/path/to/existing_mapping_file.json', |
|
50 | ] |
|
51 | )->assertExitCode(0) |
|
52 | ->expectsOutput('Mapping created or updated for index valid_index_name using file /path/to/existing_mapping_file.json.'); |
|
53 | } |
|
54 | ||
55 | public function testCreateOrUpdateMappingMustFailBecauseMappingFileDoesntExistsOnFilesystem(): void |
|
56 | { |
|
@@ 77-113 (lines=37) @@ | ||
74 | ->expectsOutput('Argument mapping-file-path must exists on filesystem and must be a non empty string.'); |
|
75 | } |
|
76 | ||
77 | public function testCreateOrUpdateMappingMustCreateNewIndexIfIndexDoesntExists(): void |
|
78 | { |
|
79 | $this->mock(Filesystem::class, function (MockInterface $mock) { |
|
80 | $mock->shouldReceive('exists') |
|
81 | ->once() |
|
82 | ->andReturn(true); |
|
83 | ||
84 | $mock->shouldReceive('get') |
|
85 | ->once() |
|
86 | ->andReturn('{}'); |
|
87 | }); |
|
88 | ||
89 | $this->mock(Client::class, function (MockInterface $mock) { |
|
90 | $mock->shouldReceive('indices') |
|
91 | ->times(2) |
|
92 | ->andReturn( |
|
93 | $this->mock(IndicesNamespace::class, function (MockInterface $mock) { |
|
94 | $mock->shouldReceive('exists') |
|
95 | ->once() |
|
96 | ->andReturn(false); |
|
97 | ||
98 | $mock->shouldReceive('create') |
|
99 | ->once() |
|
100 | ->andReturn(true); |
|
101 | }) |
|
102 | ); |
|
103 | }); |
|
104 | ||
105 | $this->artisan( |
|
106 | 'laravel-elasticsearch:utils:index-create-or-update-mapping', |
|
107 | [ |
|
108 | 'index-name' => 'valid_index_name', |
|
109 | 'mapping-file-path' => '/path/to/existing_mapping_file.json', |
|
110 | ] |
|
111 | )->assertExitCode(0) |
|
112 | ->expectsOutput('Index valid_index_name doesn\'t exist, a new index was created with mapping/settings using file /path/to/existing_mapping_file.json.'); |
|
113 | } |
|
114 | ||
115 | public function testCreateOrUpdateMappingMustFail(): void |
|
116 | { |
|
@@ 115-155 (lines=41) @@ | ||
112 | ->expectsOutput('Index valid_index_name doesn\'t exist, a new index was created with mapping/settings using file /path/to/existing_mapping_file.json.'); |
|
113 | } |
|
114 | ||
115 | public function testCreateOrUpdateMappingMustFail(): void |
|
116 | { |
|
117 | $this->mock(Filesystem::class, function (MockInterface $mock) { |
|
118 | $mock->shouldReceive('exists') |
|
119 | ->once() |
|
120 | ->andReturn(true); |
|
121 | ||
122 | $mock->shouldReceive('get') |
|
123 | ->once() |
|
124 | ->andReturn('{}'); |
|
125 | }); |
|
126 | ||
127 | $this->mock(Client::class, function (MockInterface $mock) { |
|
128 | $mock->shouldReceive('indices') |
|
129 | ->times(2) |
|
130 | ->andReturn( |
|
131 | $this->mock(IndicesNamespace::class, function (MockInterface $mock) { |
|
132 | $mock->shouldReceive('exists') |
|
133 | ->once() |
|
134 | ->andReturn(true); |
|
135 | ||
136 | $mock->shouldReceive('putMapping') |
|
137 | ->once() |
|
138 | ->andThrow( |
|
139 | new Exception('error creating or updating mapping test exception') |
|
140 | ); |
|
141 | }) |
|
142 | ); |
|
143 | }); |
|
144 | ||
145 | $this->artisan( |
|
146 | 'laravel-elasticsearch:utils:index-create-or-update-mapping', |
|
147 | [ |
|
148 | 'index-name' => 'valid_index_name', |
|
149 | 'mapping-file-path' => '/path/to/existing_mapping_file.json', |
|
150 | ] |
|
151 | )->assertExitCode(1) |
|
152 | ->expectsOutput( |
|
153 | 'Error creating or updating mapping for index valid_index_name, given mapping file: /path/to/existing_mapping_file.json - error message: error creating or updating mapping test exception.' |
|
154 | ); |
|
155 | } |
|
156 | ||
157 | /** |
|
158 | * @dataProvider invalidIndexNameDataProvider |