| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Elastica\Test\Processor; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Elastica\Bulk; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Elastica\Document; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Elastica\Processor\SortProcessor; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Elastica\Test\BasePipeline as BasePipelineTest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @internal | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | class SortProcessorTest extends BasePipelineTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      * @group unit | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 17 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |     public function testSort(): void | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |         $processor = new SortProcessor('field_to_sort'); | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |         $expected = [ | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |             'sort' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |                 'field' => 'field_to_sort', | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |             ], | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |         ]; | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |         $this->assertEquals($expected, $processor->toArray()); | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * @group unit | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     public function testSortWithNonDefaultOptions(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $processor = new SortProcessor('field_to_sort'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $processor->setOrder('desc'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $expected = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             'sort' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |                 'field' => 'field_to_sort', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |                 'order' => 'desc', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $this->assertEquals($expected, $processor->toArray()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * @group functional | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     public function testSortField(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $sort = new SortProcessor('name'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $pipeline = $this->_createPipeline('my_custom_pipeline', 'pipeline for Sort'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $pipeline->addProcessor($sort)->create(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $index = $this->_createIndex(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $bulk = new Bulk($index->getClient()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $bulk->setIndex($index); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $bulk->addDocument(new Document(null, ['name' => [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $bulk->setRequestParam('pipeline', 'my_custom_pipeline'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $bulk->send(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $index->refresh(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $result = $index->search('*'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $this->assertCount(1, $result->getResults()); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $results = $result->getResults(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $this->assertSame([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ($results[0]->getHit())['_source']['name']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 76 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 77 |  |  |  | 
            
                        
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: