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); } /** * @covers ::run * @covers ::listEnvironments */ public function testListEnvironment() { $expectedOutput = <<expectOutputString($expectedOutput); $environmentsFiles = [ 'rc.yml', 'production.yml', 'local.yml' ]; $this->scandirValueObj->setValue($environmentsFiles); $configMock = $this->getMock('Mage\Config'); $configMock->expects($this->once()) ->method('getArgument') ->with(1) ->willReturn('environments'); $this->listCommand->setConfig($configMock); $this->listCommand->run(); } /** * @covers ::run * @covers ::listEnvironments */ public function testListEnvironmentWithNoEnvironments() { $expectedOutput = "\tYou don't have any environment configured.\n\n"; $this->expectOutputString($expectedOutput); $this->scandirValueObj->setValue([]); $configMock = $this->getMock('Mage\Config'); $configMock->expects($this->once()) ->method('getArgument') ->with(1) ->willReturn('environments'); $this->listCommand->setConfig($configMock); $this->listCommand->run(); } /** * @covers ::run */ public function testRunWithInvalidCommand() { $expectedOutput = "\tThe Type of Elements to List is needed.\n\n"; $this->expectOutputString($expectedOutput); $configMock = $this->getMock('Mage\Config'); $configMock->expects($this->once()) ->method('getArgument') ->with(1) ->willReturn('abc'); $this->listCommand->setConfig($configMock); $this->listCommand->run(); } }