Skip to content

Commit fb05726

Browse files
committed
Enable the ServiceProvider to setup rollout when it boots
1 parent 8ecced2 commit fb05726

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"opensoft/rollout": "^2.2"
1818
},
1919
"require-dev": {
20+
"illuminate/container": "^5.3|^5.4",
2021
"mockery/mockery": "^0.9.9",
2122
"phpunit/phpunit": "^6.0",
2223
"satooshi/php-coveralls": "^1.0",

src/Drivers/Cache.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
namespace Jaspaul\LaravelRollout\Drivers;
44

5-
use Illuminate\Cache\Repository;
65
use Illuminate\Contracts\Cache\Store;
6+
use Illuminate\Contracts\Cache\Repository;
77
use Opensoft\Rollout\Storage\StorageInterface;
88

99
class Cache implements StorageInterface
1010
{
1111
/**
1212
* An instance of a cache repository that we can store our keys in.
1313
*
14-
* @var \Illuminate\Cache\Repository;
14+
* @var \Illuminate\Contracts\Cache\Repository
1515
*/
1616
protected $repository;
1717

@@ -26,7 +26,7 @@ class Cache implements StorageInterface
2626
* Configures our cache driver with an instance of the cache repository and
2727
* a key prefix.
2828
*
29-
* @param \Illuminate\Cache\Repository $repository
29+
* @param \Illuminate\Contracts\Cache\Repository $repository
3030
* An instance of the cache repository.
3131
* @param string $prefix
3232
* A prefix for the cache keys.

src/ServiceProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Jaspaul\LaravelRollout;
44

5+
use Opensoft\Rollout\Rollout;
56
use Jaspaul\LaravelRollout\Drivers\Cache;
67
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
78

@@ -14,5 +15,8 @@ class ServiceProvider extends IlluminateServiceProvider
1415
*/
1516
public function boot()
1617
{
18+
$this->app->singleton(Rollout::class, function ($app) {
19+
return new Rollout(new Cache($app->make('cache.store')));
20+
});
1721
}
1822
}

tests/ServiceProviderTest.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
namespace Tests;
44

55
use Mockery;
6+
use Opensoft\Rollout\Rollout;
7+
use Illuminate\Container\Container;
8+
use Illuminate\Contracts\Cache\Repository;
69
use Jaspaul\LaravelRollout\ServiceProvider;
7-
use Illuminate\Contracts\Container\Container;
810
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
911

1012
class ServiceProviderTest extends TestCase
@@ -17,7 +19,7 @@ class ServiceProviderTest extends TestCase
1719
*/
1820
function setup_service_provider()
1921
{
20-
$this->container = Mockery::mock(Container::class);
22+
$this->container = Container::getInstance();
2123
$this->serviceProvider = new ServiceProvider($this->container);
2224
}
2325

@@ -29,4 +31,19 @@ function ensure_a_service_provider_can_be_constructed()
2931
$this->assertInstanceOf(ServiceProvider::class, $this->serviceProvider);
3032
$this->assertInstanceOf(IlluminateServiceProvider::class, $this->serviceProvider);
3133
}
34+
35+
/**
36+
* @test
37+
*/
38+
function booting_registers_a_rollout_singleton_into_the_container()
39+
{
40+
$this->container->singleton('cache.store', function ($app) {
41+
return Mockery::mock(Repository::class);
42+
});
43+
44+
$this->serviceProvider->boot();
45+
46+
$result = $this->container->make(Rollout::class);
47+
$this->assertInstanceOf(Rollout::class, $result);
48+
}
3249
}

0 commit comments

Comments
 (0)