| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace QB\Generic\Clause; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use PHPUnit\Framework\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use QB\Generic\Expr\Expr; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use QB\Generic\IQueryPart; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | class JoinTest extends TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     public function toStringGetParamsProvider(): array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |                 IJoin::TYPE_INNER_JOIN, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |                 'foo', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |                 new Expr('f.id = bar.foo_id AND ?', [1]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |                 'f', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |                 'INNER JOIN foo AS f ON f.id = bar.foo_id AND ?', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |                 [[1, \PDO::PARAM_INT]], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |                 IJoin::TYPE_LEFT_JOIN, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |                 'foo', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |                 'foo.id = bar.foo_id', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |                 null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |                 'LEFT JOIN foo ON foo.id = bar.foo_id', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |                 [], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * @dataProvider toStringGetParamsProvider | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * @param string            $type | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * @param string            $tableName | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * @param IQueryPart|string $on | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @param string|null       $alias | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * @param string            $expectedSql | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * @param array             $expectedParams | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 2 |  |     public function testToStringGetParamsProvider( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         string $type, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         string $tableName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         IQueryPart|string $on, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         ?string $alias, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         string $expectedSql, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         array $expectedParams | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 2 |  |         $sut = new Join($type, $tableName, $on, $alias); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 2 |  |         $actualSql    = (string)$sut; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 | 2 |  |         $actualParams = $sut->getParams(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 2 |  |         $this->assertSame($expectedSql, $actualSql); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 2 |  |         $this->assertSame($expectedParams, $actualParams); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 2 |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 62 | 1 |  |     public function testInvalidType() | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 64 | 1 |  |         $this->expectException(\InvalidArgumentException::class); | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 66 | 1 |  |         new Join('foo', 'bar', 'bar.id = foo.bar_id', 'b'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 68 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 69 |  |  |  |