Skip to content

Commit d086582

Browse files
committed
Adds the ability to have a configuration file for rollout
1 parent dd0075d commit d086582

File tree

3 files changed

+83
-2
lines changed

3 files changed

+83
-2
lines changed

config/rollout.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Default Rollout Driver
8+
|--------------------------------------------------------------------------
9+
|
10+
| This option controls the default location where we'll store the data
11+
| used by rollout.
12+
|
13+
| Supported: "database", "null"
14+
|
15+
*/
16+
'driver' => env('ROLLOUT_DRIVER', 'database')
17+
18+
];

src/ServiceProvider.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,17 @@
66

77
class ServiceProvider extends IlluminateServiceProvider
88
{
9-
9+
/**
10+
* Register the service provider.
11+
*
12+
* @return void
13+
*/
14+
public function register()
15+
{
16+
if ($this->app->runningInConsole()) {
17+
$this->publishes([
18+
__DIR__ . '/../config/rollout.php' => $this->app->make('path.config') . DIRECTORY_SEPARATOR . 'rollout.php'
19+
]);
20+
}
21+
}
1022
}

tests/ServiceProviderTest.php

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,65 @@ class ServiceProviderTest extends TestCase
1818
function setup_service_provider()
1919
{
2020
$this->container = Mockery::mock(Container::class);
21-
$this->serviceProvider = new ServiceProvider($this->container);
21+
$this->serviceProvider = new ResettableServiceProvider($this->container);
22+
}
23+
24+
/**
25+
* @after
26+
*/
27+
function reset_publish_list()
28+
{
29+
ResettableServiceProvider::$publishes = [];
2230
}
2331

2432
/**
2533
* @test
2634
*/
2735
function ensure_a_service_provider_can_be_constructed()
2836
{
37+
$this->assertInstanceOf(ServiceProvider::class, $this->serviceProvider);
2938
$this->assertInstanceOf(IlluminateServiceProvider::class, $this->serviceProvider);
3039
}
40+
41+
/**
42+
* @test
43+
*/
44+
function when_running_in_the_console_it_adds_its_configuration_to_the_paths_to_publish()
45+
{
46+
$this->container->shouldReceive('runningInConsole')
47+
->andReturn(true);
48+
$this->container->shouldReceive('make')
49+
->with('path.config')
50+
->andReturn('/this/is/a/path');
51+
$this->serviceProvider->register();
52+
53+
$paths = ResettableServiceProvider::pathsToPublish();
54+
55+
$this->assertNotEmpty($paths);
56+
$this->assertEquals(1, count($paths));
57+
}
58+
59+
/**
60+
* @test
61+
*/
62+
function when_running_outside_of_the_console_its_configuration_is_not_added_to_the_paths_to_publish()
63+
{
64+
$this->container->shouldReceive('runningInConsole')
65+
->andReturn(false);
66+
$this->serviceProvider->register();
67+
68+
$paths = ResettableServiceProvider::pathsToPublish();
69+
70+
$this->assertEmpty($paths);
71+
}
72+
}
73+
74+
class ResettableServiceProvider extends ServiceProvider
75+
{
76+
/**
77+
* The paths that should be published.
78+
*
79+
* @var array
80+
*/
81+
public static $publishes = [];
3182
}

0 commit comments

Comments
 (0)