| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Nip\Records\Tests\Traits\Unique; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Nip\Records\Tests\AbstractTest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Nip\Records\Tests\Fixtures\Records\Books\Book; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Nip\Records\Tests\Fixtures\Records\Books\Books; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * Class RecordsTraitTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @package Nip\Records\Tests\Traits\Unique | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | class RecordsTraitTest extends AbstractTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |     public function testExists() | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |         $manager = $this->getManagerWithUnique(); | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |         $manager->shouldReceive('findOneByParams') | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |             ->andReturnUsing(function ($argument) { | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |                 return $argument; | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |             }); | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |         $item = new Book(); | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |         self::assertSame( | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |             ['where' => ["`id_event` = '' AND `id_volunteer` = '' OR `hash` = ''"]], | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |             $manager->exists($item) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     public function testGenerateExistsParams() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $manager = $this->getManagerWithUnique(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $item = new Book(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $params = $manager->generateExistsParams($item); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         self::assertSame( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |                 'where' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |                     'id_event_id_volunteer-UNQ' => "`id_event` = '' AND `id_volunteer` = ''", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |                     'hash-UNQ' => "`hash` = ''" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |                 ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             $params | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     public function testGetUniqueFields() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $manager = $this->getManagerWithUnique(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $unique = $manager->getUniqueFields(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         self::assertSame( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |                 'id_event_id_volunteer' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |                     0 => 'id_event', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |                     1 => 'id_volunteer' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |                 ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |                 'hash' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |                     0 => 'hash' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |                 ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |             $unique | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * @return Books|\Mockery\MockInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     protected function getManagerWithUnique() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $manager = \Mockery::mock(Books::class)->makePartial(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         $structure = require TEST_FIXTURE_PATH | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             . DIRECTORY_SEPARATOR . 'database_structure' . DIRECTORY_SEPARATOR . 'table_with_unique.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $manager->setTableStructure($structure); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         return $manager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 81 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 82 |  |  |  |