Skip to content

Commit

Permalink
Merge pull request #18 from fr3nch13/dev
Browse files Browse the repository at this point in the history
Passing a valid git config value.
  • Loading branch information
fr3nch13 authored Aug 19, 2024
2 parents ecffaa5 + 8179e39 commit 4314bbe
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ jobs:
composer update
- name: Run PHPUnit
run: composer run-script test
run: |
sudo apt-get install git -y
composer run-script test
coverage-php:
runs-on: ubuntu-22.04
Expand Down
4 changes: 2 additions & 2 deletions src/View/Helper/VersionsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function __construct(View $View, array $config = [])
}
// use an environment vairable if set like in config/.env
// otherwise use the constant ROOT from the source application
$this->rootDir = getenv('LOCK_DIR') ?: (getenv('ROOT') ?: ROOT);
$this->rootDir = getenv('LOCK_DIR') ? getenv('LOCK_DIR') : (getenv('ROOT') ? getenv('ROOT') : __DIR__);
if (isset($config['rootDir'])) {
$this->rootDir = $config['rootDir'];
}
Expand Down Expand Up @@ -300,7 +300,7 @@ public function runGit(array $args = [], bool $addSafe = false): array
$cmd .= ' 2>&1';
$output = [];
// removed the try/catch since I added the 'cd [root]' above,
// which will never make the $cmd emprty, so the exec() will never throw a ValueError.
// which will never make the $cmd empty, so the exec() will never throw a ValueError.
$last_line = $this->exec($cmd, $output, $result_code);

if ($result_code) {
Expand Down
20 changes: 20 additions & 0 deletions tests/TestCase/View/Helper/VersionsHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,26 @@ public function testRunGitWithAddSafe(): void
}
}

public function testRunGitGood(): void
{
$versions = new VersionsHelper($this->View, [
'git' => '/bin/git',
]);
$results = $versions->runGit(['branch']);
if (count($results) == 1) {
$this->assertMatchesRegularExpression('/^\*\s+([\(\)\w\s\/]+)$/i', $results[0]);
} else {
$result = '';
foreach ($results as $i => $line) {
if (substr($results[$i], 0, 1) == '*') {
$result = $results[$i];
break;
}
}
$this-> assertStringContainsString('*', $result);
}
}

public function testRunGitBad(): void
{
$this->expectException(UtilitiesException::class);
Expand Down

0 comments on commit 4314bbe

Please sign in to comment.