| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace CouchDB\Tests\Util; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use CouchDB\Tests\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use CouchDB\Util\BatchUpdater; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use GuzzleHttp\Psr7\Response; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @author Markus Bachmann <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | class BatchUpdaterTest extends TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     protected function setUp() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |         parent::setUp(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |         $this->database = $this->getMockBuilder('CouchDB\Database') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |             ->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |             ->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         $this->database->expects($this->any()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |             ->method('getName') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |             ->willReturn('test'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $this->updater = new BatchUpdater($this->client, $this->database); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 29 |  | View Code Duplication |     public function testUpdate() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         $this->updater->update(['_id' => 'bar1']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $this->updater->update(['_id' => 'bar2']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $this->mock->append(new Response(200, [], '{}')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $this->updater->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $request = $this->mock->getLastRequest(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $this->assertEquals('POST', $request->getMethod()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $this->assertEquals('/test/_bulk_docs', $request->getUri()->getPath()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $this->assertEquals('{"docs":[{"_id":"bar1"},{"_id":"bar2"}]}', (string) $request->getBody()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                        
            
                                                                    
                                                                                                        
            
            
                | 45 |  | View Code Duplication |     public function testDelete() | 
            
                                                        
            
                                    
            
            
                | 46 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 47 |  |  |         $this->updater->delete('bar1', 'rev'); | 
            
                                                        
            
                                    
            
            
                | 48 |  |  |         $this->updater->delete('bar2', 'rev'); | 
            
                                                        
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 50 |  |  |         $this->mock->append(new Response(200, [], '{}')); | 
            
                                                        
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 52 |  |  |         $this->updater->execute(); | 
            
                                                        
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 54 |  |  |         $request = $this->mock->getLastRequest(); | 
            
                                                        
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 56 |  |  |         $this->assertEquals('POST', $request->getMethod()); | 
            
                                                        
            
                                    
            
            
                | 57 |  |  |         $this->assertEquals('/test/_bulk_docs', $request->getUri()->getPath()); | 
            
                                                        
            
                                    
            
            
                | 58 |  |  |         $this->assertEquals('{"docs":[{"_id":"bar1","_rev":"rev","_deleted":true},{"_id":"bar2","_rev":"rev","_deleted":true}]}', (string) $request->getBody()); | 
            
                                                        
            
                                    
            
            
                | 59 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 60 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 61 |  |  |  |