Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,8 @@ All notable changes to `laravel-helpers` will be documented in this file
## 2.1.0 - 2021-03-11
- refactor `isProductionEnvironment()` helper to `isEnvProduction()` to match AppInfo method
- refactor `isDevelopmentEnvironment()` helper to `isEnvDevelopment()` to match AppInfo method


## 2.1.1 - 2021-03-11
- add `AppInfo::env()` method for quickly retrieving the application environment
- add `AppInfo::isEnvTesting()` method for checking if the application is in a 'testing' environment
22 changes: 21 additions & 1 deletion src/AppInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,16 @@ public static function isEnvDevelopment(): bool
return self::isEnv('development');
}

/**
* Determine if the Application is running in a 'testing' environment.
*
* @return bool
*/
public static function isEnvTesting(): bool
{
return self::isEnv('testing');
}

/**
* Determine if the application is in a particular environment.
*
Expand All @@ -185,7 +195,17 @@ public static function isEnvDevelopment(): bool
*/
public static function isEnv(string $env): bool
{
return config('app.env') == $env;
return self::env() == $env;
}

/**
* Retrieve the application's environment.
*
* @return string|null
*/
public static function env(): ?string
{
return config('app.env');
}

/**
Expand Down
25 changes: 25 additions & 0 deletions tests/AppInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,29 @@ public function isEnvDevelopment()
$this->assertTrue($output);
$this->assertFalse(AppInfo::isEnvProduction());
}

/** @test */
public function isEnvTesting()
{
$output = AppInfo::isEnvTesting();

$this->assertIsBool($output);
$this->assertTrue($output);
}

/** @test */
public function env()
{
$expected1 = 'testing';
$output1 = AppInfo::env();
$this->assertIsString($output1);
$this->assertEquals($expected1, $output1);

$expected2 = 'production';
$this->app['config']->set('app.env', $expected2);

$output2 = AppInfo::env();
$this->assertIsString($output2);
$this->assertEquals($expected2, $output2);
}
}