Skip to content

Commit

Permalink
Improve code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
markwalet authored Dec 15, 2021
1 parent cb260da commit e95fbf6
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 24 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

## [Unreleased](https://github.com/markwalet/laravel-git-state/compare/v1.4.0...master)

## [v1.5.0 (2021-12-15)](https://github.com/markwalet/laravel-git-state/compare/v1.4.1...v1.5.0)

### Added
- Added PHP 8.1 support ([#18](https://github.com/markwalet/laravel-git-state/issues/18))

### Changed
- Used [`webmozart/assert`](https://github.com/webmozarts/assert) instead of custom logic to reduce complexity.
- Simplified exception code style.

## [v1.4.1 (2020-10-19)](https://github.com/markwalet/laravel-git-state/compare/v1.4.0...v1.4.1)

### Added
Expand Down
4 changes: 2 additions & 2 deletions src/Drivers/FileGitDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class FileGitDriver implements GitDriver
{
/** @var string */
private $folder;
private string $folder;

/**
* GitDriverInterface constructor.
Expand Down Expand Up @@ -51,7 +51,7 @@ public function latestCommitHash(bool $short = false): string
$path = $this->path('refs'.DIRECTORY_SEPARATOR.'heads'.DIRECTORY_SEPARATOR.$this->currentBranch());

if (file_exists($path) === false) {
throw new RuntimeException($path);
throw new RuntimeException("File `$path` is not found.");
}

$hash = file_get_contents($path);
Expand Down
20 changes: 0 additions & 20 deletions src/Exceptions/FileNotFoundException.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Exceptions/RuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class RuntimeException extends BaseRuntimeException
{
/**
* NoGitRepositoryException constructor.
* RuntimeException constructor.
*
* @param $message
*/
Expand Down
10 changes: 10 additions & 0 deletions tests/Drivers/DriverTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,14 @@ public function it_can_get_the_latest_long_commit_hash_of_a_git_repository()

$this->assertEquals('202131f0ba24d03d75667ce586be1c1ce3983ce8', $commit);
}

/** @test */
public function it_throws_an_exception_when_the_head_file_is_not_found_for_the_latest_commit()
{
$this->expectException(RuntimeException::class);

$git = $this->driver('broken-head');

$git->latestCommitHash();
}
}
2 changes: 1 addition & 1 deletion tests/LaravelTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class LaravelTestCase extends TestCase
*
* @return array
*/
protected function getPackageProviders($app)
protected function getPackageProviders($app): array
{
return [
GitStateServiceProvider::class,
Expand Down
1 change: 1 addition & 0 deletions tests/test-data/broken-head/HEAD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ref: refs/heads/master
2 changes: 2 additions & 0 deletions tests/test-data/broken-head/objects/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore

0 comments on commit e95fbf6

Please sign in to comment.