From ad6c8b24ac751c1ff649f223b502bd7d3f2e5e0c Mon Sep 17 00:00:00 2001 From: Jakub Turek Date: Sat, 21 Feb 2015 14:38:53 +0100 Subject: [PATCH] Add ListCommand tests --- .../Command/BuiltIn/ListCommandTest.php | 148 ++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 tests/MageTest/Command/BuiltIn/ListCommandTest.php diff --git a/tests/MageTest/Command/BuiltIn/ListCommandTest.php b/tests/MageTest/Command/BuiltIn/ListCommandTest.php new file mode 100644 index 0000000..53e598a --- /dev/null +++ b/tests/MageTest/Command/BuiltIn/ListCommandTest.php @@ -0,0 +1,148 @@ +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(); + } +}