-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07e5162
commit 27615c6
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
namespace Troopers\MetricsBundle\Tests\GitRevsion; | ||
|
||
use Troopers\MetricsBundle\Monolog\Processor\GitProcessor; | ||
|
||
class GitRevsionTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
static $defaultPath = '/tmp'; | ||
|
||
/** | ||
* @before | ||
*/ | ||
public function before(){ | ||
chdir(self::$defaultPath); | ||
if (file_exists('REVISION')) { | ||
unlink('REVISION'); | ||
} | ||
} | ||
|
||
/** | ||
* @after | ||
*/ | ||
public function after() { | ||
GitProcessor::clearCache(); | ||
} | ||
|
||
public function testGitFieldIsAdded() | ||
{ | ||
$rootPath = self::$defaultPath; | ||
|
||
$gitProcessor = new GitProcessor($rootPath); | ||
$record = $gitProcessor([]); | ||
|
||
$this->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']); | ||
} | ||
} |