| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace Tests\FOA\CronBundle\Validator\Constraints; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use FOA\CronBundle\Manager\Cron; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use FOA\CronBundle\Validator\Constraints\CliCommandPath; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use FOA\CronBundle\Validator\Constraints\CliCommandPathValidator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use InvalidArgumentException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use PHPUnit\Framework\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | class CliCommandPathValidatorTest extends AbstractConstraintValidatorTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     protected function createValidator() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |         return new CliCommandPathValidator('/home/akeneo/pim/app'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     public function testValidCommand() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         $constraint = new CliCommandPath(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         $this->validator->validate('php /home/akeneo/pim/app/console debug:container', $constraint); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         $this->assertNoViolation(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * @dataProvider getInvalidValues | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 27 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |     public function testInvalidValues($value) | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |         $constraint = new CliCommandPath(); | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |         $this->validator->validate($value, $constraint); | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |         $this->buildViolation($constraint->message) | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |             ->setParameter('%string%', $value) | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |             ->assertRaised(); | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     public function getInvalidValues() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             ['php /home/akeneo/pim/app/hack.php'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             ['php /usr/bin/console'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             ['/home/akeneo/pim/app/console'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             ['php /home/akeneo/pim/app/console_hacked'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             ['app/console'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 49 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 50 |  |  |  |