From 27615c60ea317ca9a43f463950ca6d1139f57a20 Mon Sep 17 00:00:00 2001 From: Baptiste Date: Tue, 24 Jan 2017 01:09:00 +0100 Subject: [PATCH] :rotating_light: getRevision test --- Tests/GitRevision/GitRevsionTest.php | 78 ++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 Tests/GitRevision/GitRevsionTest.php diff --git a/Tests/GitRevision/GitRevsionTest.php b/Tests/GitRevision/GitRevsionTest.php new file mode 100644 index 0000000..82c62a9 --- /dev/null +++ b/Tests/GitRevision/GitRevsionTest.php @@ -0,0 +1,78 @@ +assertArrayHasKey('extra', $record); + $this->assertArrayHasKey('@git', $record['extra']); + + $this->assertEquals(null, $record['extra']['@git']); + } + + public function testGitRevisionWithGit() + { + $rootPath = __DIR__; + chdir($rootPath); + $gitProcessor = new GitProcessor($rootPath); + $record = $gitProcessor([]); + + $this->assertRegExp("/^[0-9a-f]{40}|[0-9a-f]{6,8}$/", $record['extra']['@git']); + } + + public function testGitRevisionWithBadRevisionFile() + { + $rootPath = self::$defaultPath; + + $revisionFile = fopen('REVISION', 'w'); + fputs($revisionFile, 'This is not a git commit sha'); + fclose($revisionFile); + + $gitProcessor = new GitProcessor($rootPath); + $record = $gitProcessor([]); + + $this->assertEquals(null, $record['extra']['@git']); + } + + public function testGitRevisionWithGoodRevisionFile() + { + $rootPath = self::$defaultPath; + + $revisionFile = fopen('REVISION', 'w'); + fputs($revisionFile, sha1(time())); + fclose($revisionFile); + + $gitProcessor = new GitProcessor($rootPath); + $record = $gitProcessor([]); + + $this->assertRegExp("/^[0-9a-f]{40}|[0-9a-f]{6,8}$/", $record['extra']['@git']); + } +}