Skip to content

Commit

Permalink
Add a facade
Browse files Browse the repository at this point in the history
Resolves #3
  • Loading branch information
markwalet committed Aug 5, 2019
1 parent 259d70f commit 61326c9
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
## [Unreleased](https://github.com/markwalet/laravel-git-state/compare/v1.0.2...master)

### Added
- Added DocBlock for git manager
- Added DocBlock for git manager.
- Added a facade.

## [1.0.2](https://github.com/markwalet/laravel-git-state/compare/v1.0.1...v1.0.2)

Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
"laravel": {
"providers": [
"MarkWalet\\GitState\\GitServiceProvider"
]
],
"aliases": {
"GitState": "MarkWalet\\GitState\\Facades\\GitState"
}
}
}
}
25 changes: 25 additions & 0 deletions src/Facades/GitState.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace MarkWalet\GitState\Facades;

use Illuminate\Support\Facades\Facade;
use MarkWalet\GitState\Drivers\GitDriver;

/**
* Class GitState
*
* @method static string currentBranch()
* @see GitDriver
*/
class GitState extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return GitDriver::class;
}
}
8 changes: 2 additions & 6 deletions src/GitManager.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php /** @noinspection PhpHierarchyChecksInspection */

namespace MarkWalet\GitState;

Expand All @@ -7,11 +7,7 @@
use MarkWalet\GitState\Exceptions\MissingConfigurationException;

/**
* Class GitManager
*
* @package MarkWalet\GitState
* @method string currentBranch
* @see GitDriver
* @mixin GitDriver
*/
class GitManager
{
Expand Down
2 changes: 1 addition & 1 deletion src/GitServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private function registerGitServices(): void
});

// Bind default driver to application.
$this->app->bind(GitDriver::class, function (Application $app) {
$this->app->singleton(GitDriver::class, function (Application $app) {
/** @var GitManager $manager */
$manager = $app->make(GitManager::class);

Expand Down
11 changes: 11 additions & 0 deletions tests/GitServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use MarkWalet\GitState\Exceptions\MissingDriverException;
use MarkWalet\GitState\Exceptions\NoGitRepositoryException;
use MarkWalet\GitState\Exceptions\RuntimeException;
use MarkWalet\GitState\Facades\GitState;
use MarkWalet\GitState\GitDriverFactory;
use MarkWalet\GitState\GitManager;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -42,4 +43,14 @@ public function it_codec_resolves_to_default_codec()

$this->assertInstanceOf(FakeGitDriver::class, $driver);
}

/** @test */
public function it_registers_a_facade()
{
$this->app['config']['git-state.default'] = 'test';
$this->app['config']['git-state.drivers.test'] = ['driver' => 'fake'];
$branch = GitState::currentBranch();

$this->assertEquals('master', $branch);
}
}

0 comments on commit 61326c9

Please sign in to comment.