diff --git a/tests/MageTest/Command/BuiltIn/UnlockCommandTest.php b/tests/MageTest/Command/BuiltIn/UnlockCommandTest.php new file mode 100644 index 0000000..bd7ec91 --- /dev/null +++ b/tests/MageTest/Command/BuiltIn/UnlockCommandTest.php @@ -0,0 +1,126 @@ +unlockCommand = new UnlockCommand(); + + self::$isUnlinkCalled = false; + self::$fileExistsResult = false; + self::$isFileExists = false; + + $mockBuilder = new MockBuilder(); + $fileExistsMock = $mockBuilder + ->setName('file_exists') + ->setNamespace('Mage\Command\BuiltIn') + ->setFunction( + function ($filePath) { + UnlockCommandTest::$fileExistsResult = $filePath; + return UnlockCommandTest::$isFileExists; + } + ) + ->build(); + $unlinkMock = $mockBuilder + ->setName('unlink') + ->setNamespace('Mage\Command\BuiltIn') + ->setFunction( + function () { + UnlockCommandTest::$isUnlinkCalled = true; + } + ) + ->build(); + $getCwdMock = $mockBuilder + ->setNamespace('Mage\Command\BuiltIn') + ->setName('getcwd') + ->setFunction( + function () { + return ''; + } + ) + ->build(); + + $fileExistsMock->disable(); + $unlinkMock->disable(); + $getCwdMock->disable(); + + + $fileExistsMock->enable(); + $unlinkMock->enable(); + $getCwdMock->enable(); + + $configMock = $this->getMock('Mage\Config'); + $configMock->expects($this->atLeastOnce()) + ->method('getEnvironment') + ->willReturn('production'); + $this->unlockCommand->setConfig($configMock); + + $this->setUpConsoleStatics(); + } + + /** + * @covers ::run + */ + public function testRun() + { + $expectedOutput = "\tUnlocked deployment to production environment\n\n"; + $this->expectOutputString($expectedOutput); + $expectedLockFilePath = '/.mage/production.lock'; + + self::$isFileExists = true; + + $actualExitCode = $this->unlockCommand->run(); + $expectedExitCode = 0; + + $this->assertTrue(self::$isUnlinkCalled); + $this->assertEquals($expectedExitCode, $actualExitCode); + $this->assertEquals($expectedLockFilePath, self::$fileExistsResult); + } + + /** + * @covers ::run + */ + public function testRunIfFileNotExist() + { + $expectedOutput = "\tUnlocked deployment to production environment\n\n"; + $this->expectOutputString($expectedOutput); + $expectedLockFilePath = '/.mage/production.lock'; + + self::$isFileExists = false; + + $actualExitCode = $this->unlockCommand->run(); + $expectedExitCode = 0; + + $this->assertFalse(self::$isUnlinkCalled); + $this->assertEquals($expectedExitCode, $actualExitCode); + $this->assertEquals($expectedLockFilePath, self::$fileExistsResult); + } +}