-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command to resync mail configuration from environment variables/c…
…onfiguration. Closes #9 Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
- Loading branch information
Showing
4 changed files
with
106 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Orchestra\Installation\Console; | ||
|
||
use Illuminate\Console\Command; | ||
use Orchestra\Contracts\Foundation\Foundation; | ||
use Orchestra\Installation\MailConfigurationUpdater; | ||
|
||
class ConfigureMailCommand extends Command | ||
{ | ||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'orchestra:configure-email'; | ||
|
||
/** | ||
* Handle the command. | ||
* | ||
* @param \Orchestra\Contracts\Foundation\Foundation $foundation | ||
* @return int | ||
*/ | ||
public function handle(Foundation $foundation) | ||
{ | ||
if (! $foundation->installed()) { | ||
$this->error('This command can only be executed when the application has been installed!'); | ||
|
||
return 1; | ||
} | ||
|
||
$memory = $foundation->memory(); | ||
|
||
$name = $this->ask('What is the application name?', $memory->get('email.from.name')); | ||
$email = $this->ask('What is the e-mail address?', $memory->get('email.from.address')); | ||
|
||
\with(new MailConfigurationUpdater($memory), static function ($updater) use ($name, $email) { | ||
$updater($name, $email); | ||
}); | ||
|
||
return 0; | ||
} | ||
} |
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
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,44 @@ | ||
<?php | ||
|
||
namespace Orchestra\Installation\Tests\Feature; | ||
|
||
use Mockery as m; | ||
use Orchestra\Contracts\Foundation\Foundation; | ||
use Orchestra\Contracts\Memory\Provider as MemoryProvider; | ||
use Orchestra\Installation\Tests\Feature\TestCase; | ||
|
||
class ConfigureMailCommandTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_cant_sync_configuration_when_orchestra_is_not_installed() | ||
{ | ||
$this->app->instance('orchestra.app', $foundation = m::mock(Foundation::class)); | ||
|
||
$foundation->shouldReceive('installed')->andReturn(false) | ||
->shouldReceive('memory')->andReturn(m::mock(MemoryProvider::class)); | ||
|
||
$this->artisan('orchestra:configure-email') | ||
->expectsOutput('This command can only be executed when the application has been installed!') | ||
->assertExitCode(1); | ||
} | ||
|
||
|
||
/** @test */ | ||
public function it_cant_sync_configuration_when_orchestra_is_installed() | ||
{ | ||
$this->app->instance('orchestra.app', $foundation = m::mock(Foundation::class)); | ||
|
||
$foundation->shouldReceive('installed')->andReturn(true) | ||
->shouldReceive('memory')->andReturn($memory = m::mock(MemoryProvider::class)); | ||
|
||
$memory->shouldReceive('get')->once()->with('email.from.name')->andReturn('Orchestra Platform') | ||
->shouldReceive('get')->once()->with('email.from.address')->andReturn('hello@orchestraplatform.com') | ||
->shouldReceive('put')->once()->with('email', ['driver' => 'smtp', 'host' => 'smtp.mailgun.org', 'port' => 587, 'encryption' => 'tls', 'sendmail' => '/usr/sbin/sendmail -bs'])->andReturnNull() | ||
->shouldReceive('put')->once()->with('email.from', ['name' => 'The Application', 'address' => 'crynobone@gmail.com'])->andReturnNull(); | ||
|
||
$this->artisan('orchestra:configure-email') | ||
->expectsQuestion('What is the application name?', 'The Application') | ||
->expectsQuestion('What is the e-mail address?', 'crynobone@gmail.com') | ||
->assertExitCode(0); | ||
} | ||
} |