2017-01-04 05:14:36 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								< ? php 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  This  file  is  part  of  the  Magallanes  package . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  ( c )  Andrés  Montañez  < andres @ andresmontanez . com > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  For  the  full  copyright  and  license  information ,  please  view  the  LICENSE 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  file  that  was  distributed  with  this  source  code . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								namespace  Mage\Tests ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								use  Mage\MageApplication ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								use  Mage\Runtime\Exception\RuntimeException ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 02:21:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								use  Symfony\Component\Console\Tester\ApplicationTester ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-04 05:14:36 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								use  Exception ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								use  PHPUnit_Framework_TestCase  as  TestCase ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								class  MageApplicationTest  extends  TestCase 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    public  function  testValidConfiguration () 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $application  =  new  MageApplication (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $application -> configure ( __DIR__  .  '/Resources/basic.yml' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $this -> assertTrue ( $application  instanceof  MageApplication ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    public  function  testInValidConfiguration () 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        try  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $application  =  new  MageApplication (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $application -> configure ( __DIR__  .  '/Resources/invalid.yml' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        }  catch  ( Exception  $exception )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $this -> assertTrue ( $exception  instanceof  RuntimeException ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $this -> assertEquals ( sprintf ( 'The file "%s" does not have a valid Magallanes configuration.' ,  __DIR__  .  '/Resources/invalid.yml' ),  $exception -> getMessage ()); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-07 23:08:25 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    public  function  testParserError () 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        try  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $application  =  new  MageApplication (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $application -> configure ( __DIR__  .  '/Resources/invalid-yaml.yml' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        }  catch  ( Exception  $exception )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $this -> assertTrue ( $exception  instanceof  RuntimeException ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $this -> assertEquals ( sprintf ( 'Error parsing the file "%s".' ,  __DIR__  .  '/Resources/invalid-yaml.yml' ),  $exception -> getMessage ()); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 02:21:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    public  function  testInvalidFile () 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-04 05:14:36 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        try  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $application  =  new  MageApplication (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $application -> configure ( __DIR__  .  '/Resources/this-does-not-exists.yml' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        }  catch  ( Exception  $exception )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $this -> assertTrue ( $exception  instanceof  RuntimeException ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            $this -> assertEquals ( sprintf ( 'The file "%s" does not exists or is not readable.' ,  __DIR__  .  '/Resources/this-does-not-exists.yml' ),  $exception -> getMessage ()); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 02:21:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    public  function  testAppDispatcher () 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $application  =  new  MageApplication (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $application -> setAutoExit ( false ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $application -> configure ( __DIR__  .  '/Resources/basic.yml' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $this -> assertTrue ( $application  instanceof  MageApplication ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 02:26:32 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        $application -> register ( 'foo' ) -> setCode ( function  ()  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 02:21:38 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            throw  new  \RuntimeException ( 'foo' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        }); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $tester  =  new  ApplicationTester ( $application ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $tester -> run ([ 'command'  =>  'foo' ]); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        $this -> assertContains ( 'Oops, exception thrown while running command foo' ,  $tester -> getDisplay ()); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-04 05:21:21 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								}