From ff6d8b174f5e9c4c5823c37d5bd15e405c635449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Tue, 3 Jan 2017 00:08:45 -0300 Subject: [PATCH] [Nostromo] Improve tests --- src/Mage/Tests/Runtime/RuntimeTest.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Mage/Tests/Runtime/RuntimeTest.php b/src/Mage/Tests/Runtime/RuntimeTest.php index d468d21..aada43d 100644 --- a/src/Mage/Tests/Runtime/RuntimeTest.php +++ b/src/Mage/Tests/Runtime/RuntimeTest.php @@ -18,17 +18,26 @@ use Monolog\Handler\TestHandler; use PHPUnit_Framework_TestCase as TestCase; use Psr\Log\LogLevel; use Symfony\Component\Process\Process; +use DateTime; class RuntimeTest extends TestCase { public function testReleaseIdGeneration() { - $releaseId = date('YmdHis'); + // Given that this is a time based operation, lets conform that at least the format is right + // and the time diff is less than 2 seconds + + $now = new DateTime(); $runtime = new Runtime(); $runtime->generateReleaseId(); + $releaseId = $runtime->getReleaseId(); - $this->assertEquals($releaseId, $runtime->getReleaseId()); + $releaseDate = DateTime::createFromFormat('YmdHis', $releaseId); + $this->assertTrue($releaseDate instanceof DateTime); + + $dateDiff = $releaseDate->diff($now); + $this->assertLessThanOrEqual(2, $dateDiff->s); } public function testEmptyEnvironmentConfig() @@ -65,6 +74,8 @@ class RuntimeTest extends TestCase $this->assertNotEquals('', $tempFile); $this->assertTrue(file_exists($tempFile)); + $this->assertTrue(is_readable($tempFile)); + $this->assertTrue(is_writable($tempFile)); $this->assertEquals(0, filesize($tempFile)); }