mirror of https://github.com/hauke68/Magallanes
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
2.9 KiB
86 lines
2.9 KiB
8 years ago
|
<?php
|
||
8 years ago
|
/*
|
||
|
* 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.
|
||
|
*/
|
||
|
|
||
8 years ago
|
namespace Mage\Tests;
|
||
|
|
||
|
use Mage\Utils;
|
||
|
use Mage\Runtime\Runtime;
|
||
|
use DateTime;
|
||
|
use PHPUnit_Framework_TestCase as TestCase;
|
||
|
|
||
|
class UtilsTest extends TestCase
|
||
|
{
|
||
|
public function testStageNames()
|
||
|
{
|
||
8 years ago
|
$utils = new Utils();
|
||
|
$this->assertEquals('Pre Deploy', $utils->getStageName(Runtime::PRE_DEPLOY));
|
||
|
$this->assertEquals('On Deploy', $utils->getStageName(Runtime::ON_DEPLOY));
|
||
|
$this->assertEquals('Post Deploy', $utils->getStageName(Runtime::POST_DEPLOY));
|
||
|
$this->assertEquals('On Release', $utils->getStageName(Runtime::ON_RELEASE));
|
||
|
$this->assertEquals('Post Release', $utils->getStageName(Runtime::POST_RELEASE));
|
||
|
$this->assertEquals('invalid-stage', $utils->getStageName('invalid-stage'));
|
||
8 years ago
|
}
|
||
|
|
||
|
public function testReleaseDate()
|
||
|
{
|
||
8 years ago
|
$utils = new Utils();
|
||
8 years ago
|
$releaseId = '20170102031530';
|
||
8 years ago
|
$dateTime = $utils->getReleaseDate($releaseId);
|
||
8 years ago
|
|
||
|
$this->assertTrue($dateTime instanceof DateTime);
|
||
|
|
||
8 years ago
|
$this->assertEquals('2017-01-02 03:15:30', $dateTime->format('Y-m-d H:i:s'));
|
||
8 years ago
|
}
|
||
|
|
||
|
public function testTimeDiffs()
|
||
|
{
|
||
8 years ago
|
$utils = new Utils();
|
||
8 years ago
|
$dateTime = new DateTime();
|
||
|
$dateTime->modify('-1 second');
|
||
8 years ago
|
$this->assertEquals('just now', $utils->getTimeDiff($dateTime));
|
||
8 years ago
|
|
||
|
$dateTime = new DateTime();
|
||
|
$dateTime->modify('-45 seconds');
|
||
8 years ago
|
$this->assertEquals('45 seconds ago', $utils->getTimeDiff($dateTime));
|
||
8 years ago
|
|
||
|
$dateTime = new DateTime();
|
||
|
$dateTime->modify('-90 seconds');
|
||
8 years ago
|
$this->assertEquals('one minute ago', $utils->getTimeDiff($dateTime));
|
||
8 years ago
|
|
||
|
$dateTime = new DateTime();
|
||
|
$dateTime->modify('-30 minutes');
|
||
8 years ago
|
$this->assertEquals('30 minutes ago', $utils->getTimeDiff($dateTime));
|
||
8 years ago
|
|
||
|
$dateTime = new DateTime();
|
||
|
$dateTime->modify('-1 hour');
|
||
8 years ago
|
$this->assertEquals('one hour ago', $utils->getTimeDiff($dateTime));
|
||
8 years ago
|
|
||
|
$dateTime = new DateTime();
|
||
|
$dateTime->modify('-10 hours');
|
||
8 years ago
|
$this->assertEquals('10 hours ago', $utils->getTimeDiff($dateTime));
|
||
8 years ago
|
|
||
|
$dateTime = new DateTime();
|
||
|
$dateTime->modify('-1 day');
|
||
8 years ago
|
$this->assertEquals('one day ago', $utils->getTimeDiff($dateTime));
|
||
8 years ago
|
|
||
|
$dateTime = new DateTime();
|
||
|
$dateTime->modify('-3 days');
|
||
8 years ago
|
$this->assertEquals('3 days ago', $utils->getTimeDiff($dateTime));
|
||
8 years ago
|
|
||
|
$dateTime = new DateTime();
|
||
|
$dateTime->modify('-7 days');
|
||
8 years ago
|
$this->assertEquals('a week ago', $utils->getTimeDiff($dateTime));
|
||
8 years ago
|
|
||
|
$dateTime = new DateTime();
|
||
|
$dateTime->modify('-10 days');
|
||
8 years ago
|
$this->assertEquals('', $utils->getTimeDiff($dateTime));
|
||
8 years ago
|
}
|
||
|
}
|