listCommand = new ListCommand(); $this->scandirValueObj = new FixedValueFunction(); $mockBuilder = new MockBuilder(); $this->scandirMock = $mockBuilder->setNamespace('Mage\Command\BuiltIn') ->setName("scandir") ->setCallableProvider($this->scandirValueObj) ->build(); $this->scandirMock->disable(); $this->scandirMock->enable(); } /** * Disable logging to log file and turn off colors * * @before */ public function setUpConsoleStatics() { $consoleReflection = new \ReflectionClass('Mage\Console'); $logEnableProperty = $consoleReflection->getProperty('logEnabled'); $logEnableProperty->setAccessible(true); $logEnableProperty->setValue(false); $configMock = $this->getMock('Mage\Config'); $configMock->expects($this->atLeastOnce()) ->method('getParameter') ->with('no-color') ->willReturn(true); $configProperty = $consoleReflection->getProperty('config'); $configProperty->setAccessible(true); $configProperty->setValue($configMock); } public function listEnvironmentsProvider() { 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" . "\t\n" ), 'with_missing_yml_files' => array( 'environmentFiles' => array( 'rc', 'production.yml' ), 'expectedOutput' => "\tThese are your configured environments:\n" . "\t\t* production\n" . "\t\n" ), 'with_no_yml_configs' => array( 'environmentFiles' => array( 'rc.ini', 'production.txt' ), 'expectedOutput' => "\tYou don't have any environment configured.\n\n" ), 'with_no_configs' => array( 'environmentFiles' => array(), 'expectedOutput' => "\tYou don't have any environment configured.\n\n" ) ); } /** * @covers ::run * @covers ::listEnvironments * @dataProvider listEnvironmentsProvider */ public function testListEnvironment($environmentFiles, $expectedOutput) { $this->expectOutputString($expectedOutput); $this->scandirValueObj->setValue($environmentFiles); $this->mockInputArgument('environments'); $this->listCommand->run(); } /** * @covers ::run */ public function testRunWithInvalidCommand() { $expectedOutput = "\tThe Type of Elements to List is needed.\n\n"; $this->expectOutputString($expectedOutput); $this->mockInputArgument('abc'); $this->listCommand->run(); } private function mockInputArgument($argumentValue) { $configMock = $this->getMock('Mage\Config'); $configMock->expects($this->once()) ->method('getArgument') ->with(1) ->willReturn($argumentValue); $this->listCommand->setConfig($configMock); } }