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']); + } +}