You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: configuration.md
+33-21
Original file line number
Diff line number
Diff line change
@@ -97,7 +97,9 @@ APP_NAME="My Application"
97
97
98
98
All of the variables listed in the `.env` file will be loaded into the `$_ENV` PHP super-global when your application receives a request. However, you may use the `env` function to retrieve values from these variables in your configuration files. In fact, if you review the Laravel configuration files, you will notice many of the options are already using this function:
99
99
100
-
'debug' => env('APP_DEBUG', false),
100
+
```php
101
+
'debug' => env('APP_DEBUG', false),
102
+
```
101
103
102
104
The second value passed to the `env` function is the "default value". This value will be returned if no environment variable exists for the given key.
103
105
@@ -106,19 +108,23 @@ The second value passed to the `env` function is the "default value". This value
106
108
107
109
The current application environment is determined via the `APP_ENV` variable from your `.env` file. You may access this value via the `environment` method on the `App`[facade](/docs/{{version}}/facades):
108
110
109
-
use Illuminate\Support\Facades\App;
111
+
```php
112
+
use Illuminate\Support\Facades\App;
110
113
111
-
$environment = App::environment();
114
+
$environment = App::environment();
115
+
```
112
116
113
117
You may also pass arguments to the `environment` method to determine if the environment matches a given value. The method will return `true` if the environment matches any of the given values:
114
118
115
-
if (App::environment('local')) {
116
-
// The environment is local
117
-
}
119
+
```php
120
+
if (App::environment('local')) {
121
+
// The environment is local
122
+
}
118
123
119
-
if (App::environment(['local', 'staging'])) {
120
-
// The environment is either local OR staging...
121
-
}
124
+
if (App::environment(['local', 'staging'])) {
125
+
// The environment is either local OR staging...
126
+
}
127
+
```
122
128
123
129
> [!NOTE]
124
130
> The current application environment detection can be overridden by defining a server-level `APP_ENV` environment variable.
You may easily access your configuration values using the `Config` facade or global `config` function from anywhere in your application. The configuration values may be accessed using "dot" syntax, which includes the name of the file and option you wish to access. A default value may also be specified and will be returned if the configuration option does not exist:
194
200
195
-
use Illuminate\Support\Facades\Config;
201
+
```php
202
+
use Illuminate\Support\Facades\Config;
196
203
197
-
$value = Config::get('app.timezone');
204
+
$value = Config::get('app.timezone');
198
205
199
-
$value = config('app.timezone');
206
+
$value = config('app.timezone');
200
207
201
-
// Retrieve a default value if the configuration value does not exist...
202
-
$value = config('app.timezone', 'Asia/Seoul');
208
+
// Retrieve a default value if the configuration value does not exist...
209
+
$value = config('app.timezone', 'Asia/Seoul');
210
+
```
203
211
204
212
To set configuration values at runtime, you may invoke the `Config` facade's `set` method or pass an array to the `config` function:
205
213
206
-
Config::set('app.timezone', 'America/Chicago');
214
+
```php
215
+
Config::set('app.timezone', 'America/Chicago');
207
216
208
-
config(['app.timezone' => 'America/Chicago']);
217
+
config(['app.timezone' => 'America/Chicago']);
218
+
```
209
219
210
220
To assist with static analysis, the `Config` facade also provides typed configuration retrieval methods. If the retrieved configuration value does not match the expected type, an exception will be thrown:
Copy file name to clipboardexpand all lines: console-tests.md
+33-23
Original file line number
Diff line number
Diff line change
@@ -33,30 +33,36 @@ public function test_console_command(): void
33
33
34
34
You may use the `assertNotExitCode` method to assert that the command did not exit with a given exit code:
35
35
36
-
$this->artisan('inspire')->assertNotExitCode(1);
36
+
```php
37
+
$this->artisan('inspire')->assertNotExitCode(1);
38
+
```
37
39
38
40
Of course, all terminal commands typically exit with a status code of `0` when they are successful and a non-zero exit code when they are not successful. Therefore, for convenience, you may utilize the `assertSuccessful` and `assertFailed` assertions to assert that a given command exited with a successful exit code or not:
39
41
40
-
$this->artisan('inspire')->assertSuccessful();
42
+
```php
43
+
$this->artisan('inspire')->assertSuccessful();
41
44
42
-
$this->artisan('inspire')->assertFailed();
45
+
$this->artisan('inspire')->assertFailed();
46
+
```
43
47
44
48
<aname="input-output-expectations"></a>
45
49
## Input / Output Expectations
46
50
47
51
Laravel allows you to easily "mock" user input for your console commands using the `expectsQuestion` method. In addition, you may specify the exit code and text that you expect to be output by the console command using the `assertExitCode` and `expectsOutput` methods. For example, consider the following console command:
48
52
49
-
Artisan::command('question', function () {
50
-
$name = $this->ask('What is your name?');
53
+
```php
54
+
Artisan::command('question', function () {
55
+
$name = $this->ask('What is your name?');
51
56
52
-
$language = $this->choice('Which language do you prefer?', [
53
-
'PHP',
54
-
'Ruby',
55
-
'Python',
56
-
]);
57
+
$language = $this->choice('Which language do you prefer?', [
58
+
'PHP',
59
+
'Ruby',
60
+
'Python',
61
+
]);
57
62
58
-
$this->line('Your name is '.$name.' and you prefer '.$language.'.');
59
-
});
63
+
$this->line('Your name is '.$name.' and you prefer '.$language.'.');
64
+
});
65
+
```
60
66
61
67
You may test this command with the following test:
62
68
@@ -165,23 +171,27 @@ public function test_console_command(): void
165
171
166
172
When writing a command which expects confirmation in the form of a "yes" or "no" answer, you may utilize the `expectsConfirmation` method:
167
173
168
-
$this->artisan('module:import')
169
-
->expectsConfirmation('Do you really wish to run this command?', 'no')
170
-
->assertExitCode(1);
174
+
```php
175
+
$this->artisan('module:import')
176
+
->expectsConfirmation('Do you really wish to run this command?', 'no')
177
+
->assertExitCode(1);
178
+
```
171
179
172
180
<aname="table-expectations"></a>
173
181
#### Table Expectations
174
182
175
183
If your command displays a table of information using Artisan's `table` method, it can be cumbersome to write output expectations for the entire table. Instead, you may use the `expectsTable` method. This method accepts the table's headers as its first argument and the table's data as its second argument:
0 commit comments