-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from zingimmick/generate-env-tests
Environment tests improvement
- Loading branch information
Showing
3 changed files
with
196 additions
and
14 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,97 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Zing\LaravelSms\Tests\Laravel; | ||
|
||
use Zing\LaravelSms\Commands\SmsSwitchConnectionCommand; | ||
|
||
class CommandTest extends LaravelTestCase | ||
{ | ||
public function testCommand(): void | ||
{ | ||
$this->artisan( | ||
SmsSwitchConnectionCommand::class, | ||
[ | ||
'connection' => 'default', | ||
] | ||
)->assertExitCode(0); | ||
$this->artisan( | ||
SmsSwitchConnectionCommand::class, | ||
[ | ||
'connection' => 'default', | ||
'--show' => 1, | ||
] | ||
)->assertExitCode(0); | ||
file_put_contents($this->envPath(), ''); | ||
$this->artisan( | ||
SmsSwitchConnectionCommand::class, | ||
[ | ||
'connection' => 'default', | ||
] | ||
)->assertExitCode(0); | ||
$this->artisan( | ||
SmsSwitchConnectionCommand::class, | ||
[ | ||
'connection' => 'default-2', | ||
] | ||
) | ||
->expectsQuestion('This maybe invalidate existing sms feature. Are you sure you want to override the sms default connection?', false) | ||
->assertExitCode(0); | ||
self::assertSame(config('sms.default'), 'default'); | ||
$this->artisan( | ||
SmsSwitchConnectionCommand::class, | ||
[ | ||
'connection' => 'default-2', | ||
] | ||
)->expectsQuestion('This maybe invalidate existing sms feature. Are you sure you want to override the sms default connection?', true) | ||
->assertExitCode(0); | ||
self::assertSame(config('sms.default'), 'default-2'); | ||
} | ||
|
||
public function testAlwaysNo(): void | ||
{ | ||
file_put_contents($this->envPath(), ''); | ||
$this->artisan( | ||
SmsSwitchConnectionCommand::class, | ||
[ | ||
'connection' => 'default', | ||
] | ||
)->assertExitCode(0); | ||
$this->artisan( | ||
SmsSwitchConnectionCommand::class, | ||
[ | ||
'connection' => 'default-2', | ||
'--always-no' => 1, | ||
] | ||
)->expectsOutput('Sms default connection already exists. Skipping...'); | ||
self::assertSame(config('sms.default'), 'default'); | ||
} | ||
|
||
protected function envPath() | ||
{ | ||
if (method_exists($this->app, 'environmentFilePath')) { | ||
return $this->app->environmentFilePath(); | ||
} | ||
|
||
return $this->app->basePath('.env'); | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->connection = \config('sms.default'); | ||
} | ||
|
||
protected $connection; | ||
|
||
protected function tearDown(): void | ||
{ | ||
if (file_exists($this->envPath())) { | ||
unlink($this->envPath()); | ||
} | ||
|
||
\config(['sms.default' => $this->connection]); | ||
parent::tearDown(); | ||
} | ||
} |
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,99 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Zing\LaravelSms\Tests\Lumen; | ||
|
||
use Illuminate\Foundation\Testing\Concerns\InteractsWithConsole; | ||
use Zing\LaravelSms\Commands\SmsSwitchConnectionCommand; | ||
|
||
class CommandTest extends LumenTestCase | ||
{ | ||
use InteractsWithConsole; | ||
|
||
public function testCommand(): void | ||
{ | ||
$this->artisan( | ||
SmsSwitchConnectionCommand::class, | ||
[ | ||
'connection' => 'default', | ||
] | ||
)->assertExitCode(0); | ||
$this->artisan( | ||
SmsSwitchConnectionCommand::class, | ||
[ | ||
'connection' => 'default', | ||
'--show' => 1, | ||
] | ||
)->assertExitCode(0); | ||
file_put_contents($this->envPath(), ''); | ||
$this->artisan( | ||
SmsSwitchConnectionCommand::class, | ||
[ | ||
'connection' => 'default', | ||
] | ||
)->assertExitCode(0); | ||
$this->artisan( | ||
SmsSwitchConnectionCommand::class, | ||
[ | ||
'connection' => 'default-2', | ||
] | ||
)->expectsQuestion('This maybe invalidate existing sms feature. Are you sure you want to override the sms default connection?', false) | ||
->assertExitCode(0); | ||
self::assertSame(config('sms.default'), 'default'); | ||
$this->artisan( | ||
SmsSwitchConnectionCommand::class, | ||
[ | ||
'connection' => 'default-2', | ||
] | ||
)->expectsQuestion('This maybe invalidate existing sms feature. Are you sure you want to override the sms default connection?', true) | ||
->assertExitCode(0); | ||
self::assertSame(config('sms.default'), 'default-2'); | ||
} | ||
|
||
public function testAlwaysNo(): void | ||
{ | ||
file_put_contents($this->envPath(), ''); | ||
$this->artisan( | ||
SmsSwitchConnectionCommand::class, | ||
[ | ||
'connection' => 'default', | ||
] | ||
)->assertExitCode(0); | ||
$this->artisan( | ||
SmsSwitchConnectionCommand::class, | ||
[ | ||
'connection' => 'default-2', | ||
'--always-no' => 1, | ||
] | ||
)->expectsOutput('Sms default connection already exists. Skipping...'); | ||
self::assertSame(config('sms.default'), 'default'); | ||
} | ||
|
||
protected function envPath() | ||
{ | ||
if (method_exists($this->app, 'environmentFilePath')) { | ||
return $this->app->environmentFilePath(); | ||
} | ||
|
||
return $this->app->basePath('.env'); | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->connection = \config('sms.default'); | ||
} | ||
|
||
protected $connection; | ||
|
||
protected function tearDown(): void | ||
{ | ||
if (file_exists($this->envPath())) { | ||
unlink($this->envPath()); | ||
} | ||
|
||
\config(['sms.default' => $this->connection]); | ||
parent::tearDown(); | ||
} | ||
} |