|
3 | 3 | namespace DirectoryTree\OpenSearchAdapter\Tests\Unit\Exceptions; |
4 | 4 |
|
5 | 5 | use DirectoryTree\OpenSearchAdapter\Exceptions\BulkRequestException; |
6 | | -use PHPUnit\Framework\TestCase; |
7 | | - |
8 | | -class BulkRequestExceptionTest extends TestCase |
9 | | -{ |
10 | | - public function test_response_can_be_retrieved(): void |
11 | | - { |
12 | | - $response = [ |
13 | | - 'took' => 486, |
14 | | - 'errors' => true, |
15 | | - 'items' => [ |
16 | | - [ |
17 | | - 'update' => [ |
18 | | - '_index' => 'index1', |
19 | | - '_type' => '_doc', |
20 | | - '_id' => '5', |
21 | | - 'status' => 404, |
22 | | - 'error' => [ |
23 | | - 'type' => 'document_missing_exception', |
24 | | - 'reason' => '[_doc][5]: document missing', |
25 | | - 'index_uuid' => 'aAsFqTI0Tc2W0LCWgPNrOA', |
26 | | - 'shard' => '0', |
27 | | - 'index' => 'index1', |
28 | | - ], |
| 6 | + |
| 7 | +test('response can be retrieved', function () { |
| 8 | + $response = [ |
| 9 | + 'took' => 486, |
| 10 | + 'errors' => true, |
| 11 | + 'items' => [ |
| 12 | + [ |
| 13 | + 'update' => [ |
| 14 | + '_index' => 'index1', |
| 15 | + '_type' => '_doc', |
| 16 | + '_id' => '5', |
| 17 | + 'status' => 404, |
| 18 | + 'error' => [ |
| 19 | + 'type' => 'document_missing_exception', |
| 20 | + 'reason' => '[_doc][5]: document missing', |
| 21 | + 'index_uuid' => 'aAsFqTI0Tc2W0LCWgPNrOA', |
| 22 | + 'shard' => '0', |
| 23 | + 'index' => 'index1', |
29 | 24 | ], |
30 | 25 | ], |
31 | 26 | ], |
32 | | - ]; |
33 | | - |
34 | | - $exception = new BulkRequestException($response); |
35 | | - |
36 | | - $this->assertSame($response, $exception->getResponse()); |
37 | | - } |
38 | | - |
39 | | - public function test_first_error_message_from_response_is_given_in_exception_message(): void |
40 | | - { |
41 | | - $response = [ |
42 | | - 'took' => 486, |
43 | | - 'errors' => true, |
44 | | - 'items' => [ |
45 | | - [ |
46 | | - 'update' => [ |
47 | | - '_index' => 'index1', |
48 | | - '_type' => '_doc', |
49 | | - '_id' => '5', |
50 | | - 'status' => 404, |
51 | | - 'error' => [ |
52 | | - 'type' => 'document_missing_exception', |
53 | | - 'reason' => '[_doc][5]: document missing', |
54 | | - 'index_uuid' => 'aAsFqTI0Tc2W0LCWgPNrOA', |
55 | | - 'shard' => '0', |
56 | | - 'index' => 'index1', |
57 | | - ], |
| 27 | + ], |
| 28 | + ]; |
| 29 | + |
| 30 | + $exception = new BulkRequestException($response); |
| 31 | + |
| 32 | + $this->assertSame($response, $exception->getResponse()); |
| 33 | +}); |
| 34 | + |
| 35 | +test('first error message from response is given in exception message', function () { |
| 36 | + $response = [ |
| 37 | + 'took' => 486, |
| 38 | + 'errors' => true, |
| 39 | + 'items' => [ |
| 40 | + [ |
| 41 | + 'update' => [ |
| 42 | + '_index' => 'index1', |
| 43 | + '_type' => '_doc', |
| 44 | + '_id' => '5', |
| 45 | + 'status' => 404, |
| 46 | + 'error' => [ |
| 47 | + 'type' => 'document_missing_exception', |
| 48 | + 'reason' => '[_doc][5]: document missing', |
| 49 | + 'index_uuid' => 'aAsFqTI0Tc2W0LCWgPNrOA', |
| 50 | + 'shard' => '0', |
| 51 | + 'index' => 'index1', |
58 | 52 | ], |
59 | 53 | ], |
60 | 54 | ], |
61 | | - ]; |
62 | | - |
63 | | - $exception = new BulkRequestException($response); |
64 | | - |
65 | | - $this->assertEquals( |
66 | | - '1 bulk operation(s) did not complete successfully. Error: document_missing_exception. Reason: [_doc][5]: document missing. Catch the exception and use the DirectoryTree\OpenSearchAdapter\Exceptions\BulkRequestException::getResponse() method to get more details.', |
67 | | - $exception->getMessage() |
68 | | - ); |
69 | | - } |
70 | | - |
71 | | - public function test_exception_can_be_throw_with_many_errors_in_response(): void |
72 | | - { |
73 | | - $response = [ |
74 | | - 'took' => 486, |
75 | | - 'errors' => true, |
76 | | - 'items' => [ |
77 | | - [ |
78 | | - 'update' => [ |
79 | | - '_index' => 'index1', |
80 | | - '_type' => '_doc', |
81 | | - '_id' => '5', |
82 | | - 'status' => 404, |
83 | | - 'error' => [ |
84 | | - 'type' => 'document_missing_exception', |
85 | | - 'reason' => '[_doc][5]: document missing', |
86 | | - 'index_uuid' => 'aAsFqTI0Tc2W0LCWgPNrOA', |
87 | | - 'shard' => '0', |
88 | | - 'index' => 'index1', |
89 | | - ], |
| 55 | + ], |
| 56 | + ]; |
| 57 | + |
| 58 | + $exception = new BulkRequestException($response); |
| 59 | + |
| 60 | + $this->assertEquals( |
| 61 | + '1 bulk operation(s) did not complete successfully. Error: document_missing_exception. Reason: [_doc][5]: document missing. Catch the exception and use the DirectoryTree\OpenSearchAdapter\Exceptions\BulkRequestException::getResponse() method to get more details.', |
| 62 | + $exception->getMessage() |
| 63 | + ); |
| 64 | +}); |
| 65 | + |
| 66 | +test('exception can be thrown with many errors in response', function () { |
| 67 | + $response = [ |
| 68 | + 'took' => 486, |
| 69 | + 'errors' => true, |
| 70 | + 'items' => [ |
| 71 | + [ |
| 72 | + 'update' => [ |
| 73 | + '_index' => 'index1', |
| 74 | + '_type' => '_doc', |
| 75 | + '_id' => '5', |
| 76 | + 'status' => 404, |
| 77 | + 'error' => [ |
| 78 | + 'type' => 'document_missing_exception', |
| 79 | + 'reason' => '[_doc][5]: document missing', |
| 80 | + 'index_uuid' => 'aAsFqTI0Tc2W0LCWgPNrOA', |
| 81 | + 'shard' => '0', |
| 82 | + 'index' => 'index1', |
90 | 83 | ], |
91 | 84 | ], |
92 | | - [ |
93 | | - 'index' => [ |
94 | | - '_index' => 'index1', |
95 | | - '_type' => '_doc', |
96 | | - '_id' => '5', |
97 | | - 'status' => 404, |
98 | | - 'error' => [ |
99 | | - 'type' => 'mapper_parsing_exception', |
100 | | - 'reason' => 'failed to parse field', |
101 | | - 'index_uuid' => 'aAsFqTI0Tc2W0LCWgPNrOA', |
102 | | - 'shard' => '0', |
103 | | - 'index' => 'index1', |
104 | | - ], |
| 85 | + ], |
| 86 | + [ |
| 87 | + 'index' => [ |
| 88 | + '_index' => 'index1', |
| 89 | + '_type' => '_doc', |
| 90 | + '_id' => '5', |
| 91 | + 'status' => 404, |
| 92 | + 'error' => [ |
| 93 | + 'type' => 'mapper_parsing_exception', |
| 94 | + 'reason' => 'failed to parse field', |
| 95 | + 'index_uuid' => 'aAsFqTI0Tc2W0LCWgPNrOA', |
| 96 | + 'shard' => '0', |
| 97 | + 'index' => 'index1', |
105 | 98 | ], |
106 | 99 | ], |
107 | 100 | ], |
108 | | - ]; |
109 | | - |
110 | | - $exception = new BulkRequestException($response); |
111 | | - |
112 | | - $this->assertEquals( |
113 | | - '2 bulk operation(s) did not complete successfully. First error: document_missing_exception. Reason: [_doc][5]: document missing. Catch the exception and use the DirectoryTree\OpenSearchAdapter\Exceptions\BulkRequestException::getResponse() method to get more details.', |
114 | | - $exception->getMessage() |
115 | | - ); |
116 | | - } |
117 | | - |
118 | | - public function test_exception_can_be_throw_with_missing_error_in_response(): void |
119 | | - { |
120 | | - $response = [ |
121 | | - 'took' => 486, |
122 | | - 'errors' => true, |
123 | | - 'items' => [ |
124 | | - [ |
125 | | - 'update' => [ |
126 | | - '_index' => 'index1', |
127 | | - '_type' => '_doc', |
128 | | - '_id' => '5', |
129 | | - 'status' => 404, |
130 | | - ], |
| 101 | + ], |
| 102 | + ]; |
| 103 | + |
| 104 | + $exception = new BulkRequestException($response); |
| 105 | + |
| 106 | + $this->assertEquals( |
| 107 | + '2 bulk operation(s) did not complete successfully. First error: document_missing_exception. Reason: [_doc][5]: document missing. Catch the exception and use the DirectoryTree\OpenSearchAdapter\Exceptions\BulkRequestException::getResponse() method to get more details.', |
| 108 | + $exception->getMessage() |
| 109 | + ); |
| 110 | +}); |
| 111 | + |
| 112 | +test('exception can be thrown with missing error in response', function () { |
| 113 | + $response = [ |
| 114 | + 'took' => 486, |
| 115 | + 'errors' => true, |
| 116 | + 'items' => [ |
| 117 | + [ |
| 118 | + 'update' => [ |
| 119 | + '_index' => 'index1', |
| 120 | + '_type' => '_doc', |
| 121 | + '_id' => '5', |
| 122 | + 'status' => 404, |
131 | 123 | ], |
132 | 124 | ], |
133 | | - ]; |
134 | | - |
135 | | - $exception = new BulkRequestException($response); |
136 | | - |
137 | | - $this->assertEquals( |
138 | | - '1 bulk operation(s) did not complete successfully. Catch the exception and use the DirectoryTree\OpenSearchAdapter\Exceptions\BulkRequestException::getResponse() method to get more details.', |
139 | | - $exception->getMessage() |
140 | | - ); |
141 | | - } |
142 | | - |
143 | | - public function test_exception_can_be_throw_with_missing_items_in_response(): void |
144 | | - { |
145 | | - $response = [ |
146 | | - 'took' => 486, |
147 | | - 'errors' => true, |
148 | | - 'items' => [], |
149 | | - ]; |
150 | | - |
151 | | - $exception = new BulkRequestException($response); |
152 | | - |
153 | | - $this->assertEquals( |
154 | | - 'One or more did not complete successfully. Catch the exception and use the DirectoryTree\OpenSearchAdapter\Exceptions\BulkRequestException::getResponse() method to get more details.', |
155 | | - $exception->getMessage() |
156 | | - ); |
157 | | - } |
158 | | -} |
| 125 | + ], |
| 126 | + ]; |
| 127 | + |
| 128 | + $exception = new BulkRequestException($response); |
| 129 | + |
| 130 | + $this->assertEquals( |
| 131 | + '1 bulk operation(s) did not complete successfully. Catch the exception and use the DirectoryTree\OpenSearchAdapter\Exceptions\BulkRequestException::getResponse() method to get more details.', |
| 132 | + $exception->getMessage() |
| 133 | + ); |
| 134 | +}); |
| 135 | + |
| 136 | +test('exception can be thrown with missing items in response', function () { |
| 137 | + $response = [ |
| 138 | + 'took' => 486, |
| 139 | + 'errors' => true, |
| 140 | + 'items' => [], |
| 141 | + ]; |
| 142 | + |
| 143 | + $exception = new BulkRequestException($response); |
| 144 | + |
| 145 | + $this->assertEquals( |
| 146 | + 'One or more did not complete successfully. Catch the exception and use the DirectoryTree\OpenSearchAdapter\Exceptions\BulkRequestException::getResponse() method to get more details.', |
| 147 | + $exception->getMessage() |
| 148 | + ); |
| 149 | +}); |
0 commit comments