Skip to content

Commit

Permalink
Enable optional customization of route prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
Krisell committed Nov 23, 2019
1 parent 1aaf3c3 commit a718970
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor
**/**.cache
build
.phpunit*
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
</testsuites>
<php>
<env name="VERSION" value="TESTING_VALUE"/>
<env name="VERSION_ROUTE_PREFIX" value="dev-custom"/>
</php>
</phpunit>
5 changes: 3 additions & 2 deletions src/DeployedVersionServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ class DeployedVersionServiceProvider extends ServiceProvider
{
public function boot()
{
Route::get('/version', VersionController::class);
Route::get(config('deployed-version.route-prefix') . '/version', VersionController::class);
}

public function register()
{
$this->mergeConfigFrom(
__DIR__.'/config/deployed-version.php', 'deployed-version'
__DIR__.'/config/deployed-version.php',
'deployed-version'
);
}
}
3 changes: 2 additions & 1 deletion src/config/deployed-version.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

return [
'version' => env('VERSION', 'NONE'),
];
'route-prefix' => env('VERSION_ROUTE_PREFIX', '')
];
10 changes: 5 additions & 5 deletions tests/DeployedVersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ protected function getPackageProviders($app)
}

/** @test */
public function the_version_route_is_added()
public function the_version_route_is_added_and_uses_prefix_set_in_env()
{
$this->get('/version')->assertStatus(200);
$this->get('dev-custom/version')->assertStatus(200);
}

/** @test */
public function the_default_version_is_TESTING_VALUE()
{
$this->get('/version')->assertJson(['version' => 'TESTING_VALUE']);
$this->get('dev-custom/version')->assertJson(['version' => 'TESTING_VALUE']);
}

/** @test */
public function the_version_can_be_set_in_the_environment()
{
config(['deployed-version.version' => 'NEW_TESTING_VALUE']);
$this->get('/version')->assertJson(['version' => 'NEW_TESTING_VALUE']);
$this->get('dev-custom/version')->assertJson(['version' => 'NEW_TESTING_VALUE']);
}
}
}

0 comments on commit a718970

Please sign in to comment.