From 3a1a1b1ac2765485cde0defff825dd4d994aa8a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Tue, 10 Jan 2017 21:41:06 -0300 Subject: [PATCH] [Nostromo] Improve tests --- tests/Deploy/StrategyTest.php | 118 ++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 tests/Deploy/StrategyTest.php diff --git a/tests/Deploy/StrategyTest.php b/tests/Deploy/StrategyTest.php new file mode 100644 index 0000000..fd3997d --- /dev/null +++ b/tests/Deploy/StrategyTest.php @@ -0,0 +1,118 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Mage\Tests\Deploy; + +use Mage\Deploy\Strategy\ReleasesStrategy; +use Mage\Deploy\Strategy\RsyncStrategy; +use Mage\Runtime\Exception\RuntimeException; +use Mage\Runtime\Runtime; +use Exception; +use PHPUnit_Framework_TestCase as TestCase; + +class StrategyTest extends TestCase +{ + public function testCheckStateRsync() + { + $runtime = new Runtime(); + + $rsync = new RsyncStrategy(); + $rsync->setRuntime($runtime); + + try { + $runtime->setStage(Runtime::ON_DEPLOY); + $rsync->getPreDeployTasks(); + } catch (Exception $exception) { + $this->assertTrue($exception instanceof RuntimeException); + $this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::ON_DEPLOY, Runtime::PRE_DEPLOY), $exception->getMessage()); + } + + try { + $runtime->setStage(Runtime::PRE_DEPLOY); + $rsync->getOnDeployTasks(); + } catch (Exception $exception) { + $this->assertTrue($exception instanceof RuntimeException); + $this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::PRE_DEPLOY, Runtime::ON_DEPLOY), $exception->getMessage()); + } + + try { + $runtime->setStage(Runtime::PRE_DEPLOY); + $rsync->getOnReleaseTasks(); + } catch (Exception $exception) { + $this->assertTrue($exception instanceof RuntimeException); + $this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::PRE_DEPLOY, Runtime::ON_RELEASE), $exception->getMessage()); + } + + try { + $runtime->setStage(Runtime::PRE_DEPLOY); + $rsync->getPostReleaseTasks(); + } catch (Exception $exception) { + $this->assertTrue($exception instanceof RuntimeException); + $this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::PRE_DEPLOY, Runtime::POST_RELEASE), $exception->getMessage()); + } + + try { + $runtime->setStage(Runtime::PRE_DEPLOY); + $rsync->getPostDeployTasks(); + } catch (Exception $exception) { + $this->assertTrue($exception instanceof RuntimeException); + $this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::PRE_DEPLOY, Runtime::POST_DEPLOY), $exception->getMessage()); + } + } + + public function testCheckStateReleases() + { + $runtime = new Runtime(); + + $releases = new ReleasesStrategy(); + $releases->setRuntime($runtime); + + try { + $runtime->setStage(Runtime::ON_DEPLOY); + $releases->getPreDeployTasks(); + } catch (Exception $exception) { + $this->assertTrue($exception instanceof RuntimeException); + $this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::ON_DEPLOY, Runtime::PRE_DEPLOY), $exception->getMessage()); + } + + try { + $runtime->setStage(Runtime::PRE_DEPLOY); + $releases->getOnDeployTasks(); + } catch (Exception $exception) { + $this->assertTrue($exception instanceof RuntimeException); + $this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::PRE_DEPLOY, Runtime::ON_DEPLOY), $exception->getMessage()); + } + + try { + $runtime->setStage(Runtime::PRE_DEPLOY); + $releases->getOnReleaseTasks(); + } catch (Exception $exception) { + $this->assertTrue($exception instanceof RuntimeException); + $this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::PRE_DEPLOY, Runtime::ON_RELEASE), $exception->getMessage()); + } + + try { + $runtime->setStage(Runtime::PRE_DEPLOY); + $releases->getPostReleaseTasks(); + } catch (Exception $exception) { + $this->assertTrue($exception instanceof RuntimeException); + $this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::PRE_DEPLOY, Runtime::POST_RELEASE), $exception->getMessage()); + } + + try { + $runtime->setStage(Runtime::PRE_DEPLOY); + $releases->getPostDeployTasks(); + } catch (Exception $exception) { + $this->assertTrue($exception instanceof RuntimeException); + $this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%"', Runtime::PRE_DEPLOY, Runtime::POST_DEPLOY), $exception->getMessage()); + } + } + +}