-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tony BOTALLA
committed
May 3, 2023
1 parent
2ec4a68
commit 886964f
Showing
4 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Novius\ArtisanCommands\Console\Database; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class GetName extends Command | ||
{ | ||
protected $signature = 'db:get-name {--connection=}'; | ||
|
||
protected $description = 'Get database name for current or given connection name.'; | ||
|
||
protected ?string $connectionName; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return int | ||
*/ | ||
public function handle() | ||
{ | ||
$this->connectionName = $this->option('connection'); | ||
$dbName = DB::getDatabaseName(); | ||
|
||
if ($this->connectionName !== null) { | ||
if (! config()->has($this->databaseConfigName())) { | ||
return Command::FAILURE; | ||
} | ||
|
||
$dbName = config($this->databaseConfigName()); | ||
} | ||
|
||
$this->line($dbName); | ||
|
||
return Command::SUCCESS; | ||
} | ||
|
||
/** | ||
* Return complete database connection config name, using $this->connectionName. | ||
*/ | ||
protected function databaseConfigName(): string | ||
{ | ||
return 'database.connections.'.$this->connectionName.'.database'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Novius\ArtisanCommands\Tests\Console\Database; | ||
|
||
use Illuminate\Support\Facades\Artisan; | ||
use Novius\ArtisanCommands\ArtisanCommandsServiceProvider; | ||
use Orchestra\Testbench\TestCase; | ||
|
||
class GetNameTest extends TestCase | ||
{ | ||
protected function getPackageProviders($app) | ||
{ | ||
return [ | ||
ArtisanCommandsServiceProvider::class, | ||
]; | ||
} | ||
|
||
/** | ||
* Does the new command db:create exist ? This doesn't check if this command actually work. | ||
*/ | ||
public function testConfigureDBCommandExists() | ||
{ | ||
$commands = Artisan::all(); | ||
|
||
$this->assertArrayHasKey('db:get-name', $commands); | ||
} | ||
} |