| 
									
										
										
										
											2015-02-21 14:38:53 +01:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace MageTest\Command\BuiltIn; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use Mage\Command\BuiltIn\ListCommand; | 
					
						
							|  |  |  | use MageTest\TestHelper\BaseTest; | 
					
						
							|  |  |  | use malkusch\phpmock\FixedValueFunction; | 
					
						
							|  |  |  | use malkusch\phpmock\Mock; | 
					
						
							|  |  |  | use malkusch\phpmock\MockBuilder; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Class ListCommandTest | 
					
						
							|  |  |  |  * @package MageTest\Command\BuiltIn | 
					
						
							|  |  |  |  * @coversDefaultClass Mage\Command\BuiltIn\ListCommand | 
					
						
							|  |  |  |  * @uses malkusch\phpmock\Mock | 
					
						
							|  |  |  |  * @uses malkusch\phpmock\MockBuilder | 
					
						
							|  |  |  |  * @uses malkusch\phpmock\FixedValueFunction | 
					
						
							|  |  |  |  * @uses Mage\Console\Colors | 
					
						
							|  |  |  |  * @uses Mage\Console | 
					
						
							|  |  |  |  * @uses Mage\Command\AbstractCommand | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | class ListCommandTest extends BaseTest | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @var ListCommand | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     private $listCommand; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @var FixedValueFunction | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     private $scandirValueObj; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @before | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function before() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->listCommand = new ListCommand(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->scandirValueObj = new FixedValueFunction(); | 
					
						
							|  |  |  |         $mockBuilder = new MockBuilder(); | 
					
						
							| 
									
										
										
										
											2015-02-22 18:14:53 +01:00
										 |  |  |         $scandirMock = $mockBuilder->setNamespace('Mage\Command\BuiltIn') | 
					
						
							| 
									
										
										
										
											2015-02-21 14:38:53 +01:00
										 |  |  |             ->setName("scandir") | 
					
						
							|  |  |  |             ->setCallableProvider($this->scandirValueObj) | 
					
						
							|  |  |  |             ->build(); | 
					
						
							| 
									
										
										
										
											2015-02-22 18:14:53 +01:00
										 |  |  |         $scandirMock->disable(); | 
					
						
							|  |  |  |         $scandirMock->enable(); | 
					
						
							| 
									
										
										
										
											2015-02-21 14:38:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-21 16:45:26 +01:00
										 |  |  |         $this->setUpConsoleStatics(); | 
					
						
							| 
									
										
										
										
											2015-02-21 14:38:53 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-21 14:57:03 +01:00
										 |  |  |     public function listEnvironmentsProvider() | 
					
						
							| 
									
										
										
										
											2015-02-21 14:38:53 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-02-21 14:57:03 +01:00
										 |  |  |         return array( | 
					
						
							|  |  |  |             'normal' => array( | 
					
						
							|  |  |  |                 'environmentFiles' => array( | 
					
						
							|  |  |  |                     'rc.yml', | 
					
						
							|  |  |  |                     'production.yml', | 
					
						
							|  |  |  |                     'local.yml' | 
					
						
							|  |  |  |                 ), | 
					
						
							|  |  |  |                 'expectedOutput' => "\tThese are your configured environments:\n" | 
					
						
							|  |  |  |                     . "\t\t* local\n" | 
					
						
							|  |  |  |                     . "\t\t* production\n" | 
					
						
							|  |  |  |                     . "\t\t* rc\n" | 
					
						
							| 
									
										
										
										
											2015-02-21 15:42:18 +01:00
										 |  |  |                     . "\t\n", | 
					
						
							|  |  |  |                 'expectedExitCode' => 0 | 
					
						
							| 
									
										
										
										
											2015-02-21 14:57:03 +01:00
										 |  |  |             ), | 
					
						
							|  |  |  |             'with_missing_yml_files' => array( | 
					
						
							|  |  |  |                 'environmentFiles' => array( | 
					
						
							|  |  |  |                     'rc', | 
					
						
							|  |  |  |                     'production.yml' | 
					
						
							|  |  |  |                 ), | 
					
						
							|  |  |  |                 'expectedOutput' => "\tThese are your configured environments:\n" | 
					
						
							|  |  |  |                     . "\t\t* production\n" | 
					
						
							| 
									
										
										
										
											2015-02-21 15:42:18 +01:00
										 |  |  |                     . "\t\n", | 
					
						
							|  |  |  |                 'expectedExitCode' => 0 | 
					
						
							| 
									
										
										
										
											2015-02-21 14:57:03 +01:00
										 |  |  |             ), | 
					
						
							|  |  |  |             'with_no_yml_configs' => array( | 
					
						
							|  |  |  |                 'environmentFiles' => array( | 
					
						
							|  |  |  |                     'rc.ini', | 
					
						
							|  |  |  |                     'production.txt' | 
					
						
							|  |  |  |                 ), | 
					
						
							| 
									
										
										
										
											2015-02-21 15:42:18 +01:00
										 |  |  |                 'expectedOutput' => "\tYou don't have any environment configured.\n\n", | 
					
						
							|  |  |  |                 'expectedExitCode' => 220 | 
					
						
							| 
									
										
										
										
											2015-02-21 14:57:03 +01:00
										 |  |  |             ), | 
					
						
							|  |  |  |             'with_no_configs' => array( | 
					
						
							|  |  |  |                 'environmentFiles' => array(), | 
					
						
							| 
									
										
										
										
											2015-02-21 15:42:18 +01:00
										 |  |  |                 'expectedOutput' => "\tYou don't have any environment configured.\n\n", | 
					
						
							|  |  |  |                 'expectedExitCode' => 220 | 
					
						
							| 
									
										
										
										
											2015-02-21 14:57:03 +01:00
										 |  |  |             ) | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2015-02-21 14:38:53 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2015-05-16 22:20:20 +02:00
										 |  |  |      * @covers ::__construct | 
					
						
							| 
									
										
										
										
											2015-02-21 14:38:53 +01:00
										 |  |  |      * @covers ::run | 
					
						
							|  |  |  |      * @covers ::listEnvironments | 
					
						
							| 
									
										
										
										
											2015-02-21 14:57:03 +01:00
										 |  |  |      * @dataProvider listEnvironmentsProvider | 
					
						
							| 
									
										
										
										
											2015-02-21 14:38:53 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-02-21 15:42:18 +01:00
										 |  |  |     public function testListEnvironment($environmentFiles, $expectedOutput, $expectedExitCode) | 
					
						
							| 
									
										
										
										
											2015-02-21 14:38:53 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         $this->expectOutputString($expectedOutput); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-21 14:57:03 +01:00
										 |  |  |         $this->scandirValueObj->setValue($environmentFiles); | 
					
						
							|  |  |  |         $this->mockInputArgument('environments'); | 
					
						
							| 
									
										
										
										
											2015-02-21 14:38:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-21 15:42:18 +01:00
										 |  |  |         $actualExitCode = $this->listCommand->run(); | 
					
						
							|  |  |  |         $this->assertEquals($expectedExitCode, $actualExitCode); | 
					
						
							| 
									
										
										
										
											2015-02-21 14:38:53 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2015-05-16 22:20:20 +02:00
										 |  |  |      * @covers ::__construct | 
					
						
							| 
									
										
										
										
											2015-02-21 14:38:53 +01:00
										 |  |  |      * @covers ::run | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function testRunWithInvalidCommand() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $expectedOutput = "\tThe Type of Elements to List is needed.\n\n"; | 
					
						
							|  |  |  |         $this->expectOutputString($expectedOutput); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-21 14:57:03 +01:00
										 |  |  |         $this->mockInputArgument('abc'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-21 15:42:18 +01:00
										 |  |  |         $expectedExitCode = 221; | 
					
						
							|  |  |  |         $actualExitCode = $this->listCommand->run(); | 
					
						
							|  |  |  |         $this->assertEquals($expectedExitCode, $actualExitCode); | 
					
						
							| 
									
										
										
										
											2015-02-21 14:57:03 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-22 18:14:53 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Stub Config::getArgument to return desired value | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param String $argumentValue Input argument | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-02-21 14:57:03 +01:00
										 |  |  |     private function mockInputArgument($argumentValue) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-02-21 14:38:53 +01:00
										 |  |  |         $configMock = $this->getMock('Mage\Config'); | 
					
						
							|  |  |  |         $configMock->expects($this->once()) | 
					
						
							|  |  |  |             ->method('getArgument') | 
					
						
							|  |  |  |             ->with(1) | 
					
						
							| 
									
										
										
										
											2015-02-21 14:57:03 +01:00
										 |  |  |             ->willReturn($argumentValue); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-21 14:38:53 +01:00
										 |  |  |         $this->listCommand->setConfig($configMock); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |