Skip to content

Commit

Permalink
🚨 patch StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptiste authored and lenybernard committed Jan 24, 2017
1 parent 27615c6 commit fd2a32e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
12 changes: 6 additions & 6 deletions Monolog/Processor/GitProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,18 @@ private function getRevision()

try {
//Get revision number from .git
$gitRev = shell_exec("git rev-parse HEAD");
if(preg_match("/^[0-9a-f]{40}|[0-9a-f]{6,8}$/", $gitRev)){
$gitRev = shell_exec('git rev-parse HEAD');
if (preg_match('/^[0-9a-f]{40}|[0-9a-f]{6,8}$/', $gitRev)) {
return self::$cache = trim($gitRev);
}
} catch (\Exception $e) {
error_log('GitProcessor, git rev-parse failed "'.$e->getMessage().'"');
}


try {
$gitRev = file_get_contents($this->appRootDir.'/REVISION');
//Get revision number from REVISION file
if(preg_match("/^[0-9a-f]{40}|[0-9a-f]{6,8}$/", $gitRev)){
if (preg_match('/^[0-9a-f]{40}|[0-9a-f]{6,8}$/', $gitRev)) {
return self::$cache = $gitRev;
}
} catch (\Exception $e) {
Expand All @@ -55,9 +54,10 @@ private function getRevision()
}

/**
* Clear Cache
* Clear Cache.
*/
static function clearCache() {
public static function clearCache()
{
self::$cache = false;
}
}
16 changes: 9 additions & 7 deletions Tests/GitRevision/GitRevsionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

class GitRevsionTest extends \PHPUnit_Framework_TestCase
{
static $defaultPath = '/tmp';
public static $defaultPath = '/tmp';

/**
* @before
*/
public function before(){
public function before()
{
chdir(self::$defaultPath);
if (file_exists('REVISION')) {
unlink('REVISION');
Expand All @@ -21,7 +22,8 @@ public function before(){
/**
* @after
*/
public function after() {
public function after()
{
GitProcessor::clearCache();
}

Expand All @@ -45,15 +47,15 @@ public function testGitRevisionWithGit()
$gitProcessor = new GitProcessor($rootPath);
$record = $gitProcessor([]);

$this->assertRegExp("/^[0-9a-f]{40}|[0-9a-f]{6,8}$/", $record['extra']['@git']);
$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');
fwrite($revisionFile, 'This is not a git commit sha');
fclose($revisionFile);

$gitProcessor = new GitProcessor($rootPath);
Expand All @@ -67,12 +69,12 @@ public function testGitRevisionWithGoodRevisionFile()
$rootPath = self::$defaultPath;

$revisionFile = fopen('REVISION', 'w');
fputs($revisionFile, sha1(time()));
fwrite($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']);
$this->assertRegExp('/^[0-9a-f]{40}|[0-9a-f]{6,8}$/', $record['extra']['@git']);
}
}

0 comments on commit fd2a32e

Please sign in to comment.