Skip to content

Commit

Permalink
Enable the ServiceProvider to setup rollout when it boots
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaspaul committed Mar 29, 2017
1 parent 8ecced2 commit fb05726
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"opensoft/rollout": "^2.2"
},
"require-dev": {
"illuminate/container": "^5.3|^5.4",
"mockery/mockery": "^0.9.9",
"phpunit/phpunit": "^6.0",
"satooshi/php-coveralls": "^1.0",
Expand Down
6 changes: 3 additions & 3 deletions src/Drivers/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

namespace Jaspaul\LaravelRollout\Drivers;

use Illuminate\Cache\Repository;
use Illuminate\Contracts\Cache\Store;
use Illuminate\Contracts\Cache\Repository;
use Opensoft\Rollout\Storage\StorageInterface;

class Cache implements StorageInterface
{
/**
* An instance of a cache repository that we can store our keys in.
*
* @var \Illuminate\Cache\Repository;
* @var \Illuminate\Contracts\Cache\Repository
*/
protected $repository;

Expand All @@ -26,7 +26,7 @@ class Cache implements StorageInterface
* Configures our cache driver with an instance of the cache repository and
* a key prefix.
*
* @param \Illuminate\Cache\Repository $repository
* @param \Illuminate\Contracts\Cache\Repository $repository
* An instance of the cache repository.
* @param string $prefix
* A prefix for the cache keys.
Expand Down
4 changes: 4 additions & 0 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Jaspaul\LaravelRollout;

use Opensoft\Rollout\Rollout;
use Jaspaul\LaravelRollout\Drivers\Cache;
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;

Expand All @@ -14,5 +15,8 @@ class ServiceProvider extends IlluminateServiceProvider
*/
public function boot()
{
$this->app->singleton(Rollout::class, function ($app) {
return new Rollout(new Cache($app->make('cache.store')));
});
}
}
21 changes: 19 additions & 2 deletions tests/ServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace Tests;

use Mockery;
use Opensoft\Rollout\Rollout;
use Illuminate\Container\Container;
use Illuminate\Contracts\Cache\Repository;
use Jaspaul\LaravelRollout\ServiceProvider;
use Illuminate\Contracts\Container\Container;
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;

class ServiceProviderTest extends TestCase
Expand All @@ -17,7 +19,7 @@ class ServiceProviderTest extends TestCase
*/
function setup_service_provider()
{
$this->container = Mockery::mock(Container::class);
$this->container = Container::getInstance();
$this->serviceProvider = new ServiceProvider($this->container);
}

Expand All @@ -29,4 +31,19 @@ function ensure_a_service_provider_can_be_constructed()
$this->assertInstanceOf(ServiceProvider::class, $this->serviceProvider);
$this->assertInstanceOf(IlluminateServiceProvider::class, $this->serviceProvider);
}

/**
* @test
*/
function booting_registers_a_rollout_singleton_into_the_container()
{
$this->container->singleton('cache.store', function ($app) {
return Mockery::mock(Repository::class);
});

$this->serviceProvider->boot();

$result = $this->container->make(Rollout::class);
$this->assertInstanceOf(Rollout::class, $result);
}
}

0 comments on commit fb05726

Please sign in to comment.