magallanes/tests/Deploy/StrategyTest.php

118 lines
4.6 KiB
PHP
Raw Normal View History

2017-01-11 01:41:06 +01:00
<?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mage\Tests\Deploy;
2017-01-12 02:22:21 +01:00
use Mage\Deploy\Strategy\ReleasesStrategy;
use Mage\Deploy\Strategy\RsyncStrategy;
2017-01-11 01:41:06 +01:00
use Mage\Runtime\Exception\RuntimeException;
use Mage\Runtime\Runtime;
use Exception;
use PHPUnit\Framework\TestCase;
2017-01-11 01:41:06 +01:00
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);
2021-02-11 17:57:40 +01:00
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::ON_DEPLOY, Runtime::PRE_DEPLOY), $exception->getMessage());
2017-01-11 01:41:06 +01:00
}
try {
$runtime->setStage(Runtime::PRE_DEPLOY);
$rsync->getOnDeployTasks();
} catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException);
2021-02-11 17:57:40 +01:00
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::PRE_DEPLOY, Runtime::ON_DEPLOY), $exception->getMessage());
2017-01-11 01:41:06 +01:00
}
try {
$runtime->setStage(Runtime::PRE_DEPLOY);
$rsync->getOnReleaseTasks();
} catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException);
2021-02-11 17:57:40 +01:00
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::PRE_DEPLOY, Runtime::ON_RELEASE), $exception->getMessage());
2017-01-11 01:41:06 +01:00
}
try {
$runtime->setStage(Runtime::PRE_DEPLOY);
$rsync->getPostReleaseTasks();
} catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException);
2021-02-11 17:57:40 +01:00
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::PRE_DEPLOY, Runtime::POST_RELEASE), $exception->getMessage());
2017-01-11 01:41:06 +01:00
}
try {
$runtime->setStage(Runtime::PRE_DEPLOY);
$rsync->getPostDeployTasks();
} catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException);
2021-02-11 17:57:40 +01:00
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::PRE_DEPLOY, Runtime::POST_DEPLOY), $exception->getMessage());
2017-01-11 01:41:06 +01:00
}
}
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);
2021-02-11 17:57:40 +01:00
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::ON_DEPLOY, Runtime::PRE_DEPLOY), $exception->getMessage());
2017-01-11 01:41:06 +01:00
}
try {
$runtime->setStage(Runtime::PRE_DEPLOY);
$releases->getOnDeployTasks();
} catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException);
2021-02-11 17:57:40 +01:00
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::PRE_DEPLOY, Runtime::ON_DEPLOY), $exception->getMessage());
2017-01-11 01:41:06 +01:00
}
try {
$runtime->setStage(Runtime::PRE_DEPLOY);
$releases->getOnReleaseTasks();
} catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException);
2021-02-11 17:57:40 +01:00
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::PRE_DEPLOY, Runtime::ON_RELEASE), $exception->getMessage());
2017-01-11 01:41:06 +01:00
}
try {
$runtime->setStage(Runtime::PRE_DEPLOY);
$releases->getPostReleaseTasks();
} catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException);
2021-02-11 17:57:40 +01:00
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::PRE_DEPLOY, Runtime::POST_RELEASE), $exception->getMessage());
2017-01-11 01:41:06 +01:00
}
try {
$runtime->setStage(Runtime::PRE_DEPLOY);
$releases->getPostDeployTasks();
} catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException);
2021-02-11 17:57:40 +01:00
$this->assertEquals(sprintf('Invalid stage, got "%s" but expected "%s"', Runtime::PRE_DEPLOY, Runtime::POST_DEPLOY), $exception->getMessage());
2017-01-11 01:41:06 +01:00
}
}
}