Skip to content

Commit 0400c39

Browse files
committed
add local mode
1 parent 8abc8a6 commit 0400c39

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

src/Nuxed/Environment/Mode.hack

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
namespace Nuxed\Environment;
22

3-
enum Mode: int {
3+
enum Mode: string as string {
44
/**
55
* The application is running in dev environment.
66
*/
7-
Development = 1;
7+
Development = 'dev';
88

99
/**
1010
* The application is running in production.
1111
*/
12-
Production = 2;
12+
Production = 'prod';
1313

1414
/**
1515
* The application is running tests.
1616
*/
17-
Test = 3;
17+
Test = 'test';
18+
19+
/**
20+
* The application is running in a local environment.
21+
*/
22+
Local = 'local';
1823
}

tests/Nuxed/Environment/EnvironmentTest.hack

+29-6
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,7 @@ class EnvironmentTest extends HackTest\HackTest {
8888
}
8989

9090
<<HackTest\DataProvider('provideParseData')>>
91-
public function testParse(
92-
string $value,
93-
(string, ?string) $expected
94-
): void {
91+
public function testParse(string $value, (string, ?string) $expected): void {
9592
expect(Environment\parse($value))->toBeSame($expected);
9693
}
9794

@@ -110,13 +107,19 @@ class EnvironmentTest extends HackTest\HackTest {
110107
public function testParseInvalidSquence(): void {
111108
expect(() ==> {
112109
Environment\parse('export FOO="BAR\\#X');
113-
})->toThrow(Environment\Exception\InvalidArgumentException::class, 'an unexpected escape sequence');
110+
})->toThrow(
111+
Environment\Exception\InvalidArgumentException::class,
112+
'an unexpected escape sequence',
113+
);
114114
}
115115

116116
public function testParseUnexceptedWhiteSpace(): void {
117117
expect(() ==> {
118118
Environment\parse('export FOO=BAR "FOO"');
119-
})->toThrow(Environment\Exception\InvalidArgumentException::class, 'unexpected whitespace');
119+
})->toThrow(
120+
Environment\Exception\InvalidArgumentException::class,
121+
'unexpected whitespace',
122+
);
120123
}
121124

122125
public function testMode(): void {
@@ -136,6 +139,26 @@ class EnvironmentTest extends HackTest\HackTest {
136139
expect(Environment\mode())
137140
->toBeSame(Environment\Mode::Development);
138141

142+
Environment\put('APP_MODE', 'local');
143+
expect(Environment\mode())
144+
->toBeSame(Environment\Mode::Local);
145+
146+
Environment\put('APP_MODE', 'develop');
147+
expect(Environment\mode())
148+
->toBeSame(Environment\Mode::Development);
149+
150+
Environment\put('APP_MODE', 'Development');
151+
expect(Environment\mode())
152+
->toBeSame(Environment\Mode::Development);
153+
154+
Environment\put('APP_MODE', 'production');
155+
expect(Environment\mode())
156+
->toBeSame(Environment\Mode::Production);
157+
158+
Environment\put('APP_MODE', 'testing');
159+
expect(Environment\mode())
160+
->toBeSame(Environment\Mode::Test);
161+
139162
Environment\put('APP_MODE', 'unknown');
140163
expect(Environment\mode())
141164
->toBeSame(Environment\Mode::Production);

0 commit comments

Comments
 (0)