Skip to content

Commit e8dc94b

Browse files
committed
Overrideable environment
1 parent e60a5c3 commit e8dc94b

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

CHANGELOG.md

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

33
## Unreleased
44

5+
## 0.4.1 - 2021-05-23
6+
7+
### Added
8+
- Ability to override the environment.
9+
510
## 0.4.0 - 2021-05-23
611

712
### Added

src/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ protected function potentiallyThrowRequestException($response)
111111

112112
protected function throwUnlessProduction($exception)
113113
{
114-
throw_unless(app()->environment('production'), $exception);
114+
throw_unless(Torchlight::environment() === 'production', $exception);
115115
}
116116

117117
public function cachePrefix()

src/Manager.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ class Manager
3131
*/
3232
protected $app;
3333

34+
/**
35+
* @var null|string
36+
*/
37+
protected $environment;
38+
3439
/**
3540
* @param Container $app
3641
*/
@@ -56,6 +61,22 @@ public function client()
5661
return $this->app->make(Client::class);
5762
}
5863

64+
/**
65+
* @return string
66+
*/
67+
public function environment()
68+
{
69+
return $this->environment ?? app()->environment();
70+
}
71+
72+
/**
73+
* @param string $environment
74+
*/
75+
public function overrideEnvironment($environment = null)
76+
{
77+
$this->environment = $environment;
78+
}
79+
5980
/**
6081
* Get an item out of the config using dot notation.
6182
*

tests/CustomizationTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,18 @@ public function cache_implementation_can_be_set()
6060
$this->assertFalse($newStore->has('original_key'));
6161
$this->assertTrue($newStore->has('new_key'));
6262
}
63+
64+
/** @test */
65+
public function environment_can_be_set()
66+
{
67+
$this->assertEquals('testing', Torchlight::environment());
68+
69+
Torchlight::overrideEnvironment('production');
70+
71+
$this->assertEquals('production', Torchlight::environment());
72+
73+
Torchlight::overrideEnvironment(null);
74+
75+
$this->assertEquals('testing', Torchlight::environment());
76+
}
6377
}

0 commit comments

Comments
 (0)