Skip to content
Prev Previous commit
Next Next commit
Mock sync classes instead
  • Loading branch information
bakerkretzmar committed Jun 11, 2021
commit aa2fdf42097742518461ea9f5153e8506b358cd3
18 changes: 4 additions & 14 deletions app/Commands/PushConfigCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use App\Sync\WebhookSync;
use App\Sync\WorkerSync;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Support\Arr;
use Laravel\Forge\Forge;
use Laravel\Forge\Resources\Server;
use Laravel\Forge\Resources\Site;
Expand All @@ -25,7 +24,7 @@ class PushConfigCommand extends ForgeCommand
WorkerSync::class,
];

protected $signature = 'config:push {environment=production} {--sync=all} {--force}';
protected $signature = 'config:push {environment=production} {--force}';

protected $description = 'Push the configuration from your forge.yml file to Laravel Forge';

Expand All @@ -41,23 +40,14 @@ public function handle(Forge $forge, Configuration $configuration)
$server = $forge->server($configuration->get($environment, 'server'));
$site = $forge->site($server->id, $configuration->get($environment, 'id'));

$syncClasses = $this->option('sync') === 'all'
? static::SYNC_CLASSES
: array_values(Arr::only([
'webhooks' => WebhookSync::class,
'deployment' => DeploymentScriptSync::class,
'daemons' => DaemonSync::class,
'workers' => WorkerSync::class,
], explode(',', $this->option('sync'))));

$this->synchronize($environment, $server, $site, $syncClasses);
$this->synchronize($environment, $server, $site);

$this->info('Done');
}

protected function synchronize(string $environment, Server $server, Site $site, array $syncClasses)
protected function synchronize(string $environment, Server $server, Site $site)
{
foreach ($syncClasses as $syncClass) {
foreach (static::SYNC_CLASSES as $syncClass) {
$this->info('Synchronizing ' . $syncClass);

$output = fn (string $contents, string $level = 'info') => $this->{$level}($contents);
Expand Down
13 changes: 10 additions & 3 deletions tests/SyncWorkersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
namespace Tests;

use App\Support\Defaults;
use App\Sync\DaemonSync;
use App\Sync\DeploymentScriptSync;
use App\Sync\WebhookSync;
use Tests\TestCase;

class SyncWorkersTest extends TestCase
Expand All @@ -12,6 +15,10 @@ protected function setUp(): void
parent::setUp();

$this->mockForge();

$this->mock(WebhookSync::class)->shouldReceive('sync');
$this->mock(DeploymentScriptSync::class)->shouldReceive('sync');
$this->mock(DaemonSync::class)->shouldReceive('sync');
}

/** @test */
Expand All @@ -35,7 +42,7 @@ public function can_diff_workers_found_in_local_config_and_on_forge()
// No additional Forge expectations because the local and Forge workers
// are the same - the command should determine this and do nothing

$this->inFixtureDir()->artisan('config:push --sync=workers')
$this->inFixtureDir()->artisan('config:push')
->expectsOutput('Done')
->assertExitCode(0);
}
Expand Down Expand Up @@ -482,7 +489,7 @@ public function can_sync_forge_workers_up(string $config, array $forge, array $c
$this->shouldDeleteForgeWorker($attributes['id']);
}

$command = $this->inFixtureDir()->artisan('config:push --sync=workers --force');
$command = $this->inFixtureDir()->artisan('config:push --force');

foreach ($create as $attributes) {
$command->expectsOutput("Creating {$attributes['queue']} queue worker on {$attributes['connection']} connection...");
Expand Down Expand Up @@ -510,7 +517,7 @@ public function can_skip_deleting_forge_workers_unless_force_option_passed()
->withForgePhpVersion(['used_on_cli' => true])
->withForgeWorker();

$command = $this->inFixtureDir()->artisan('config:push --sync=workers');
$command = $this->inFixtureDir()->artisan('config:push');

$command->expectsOutput('Found 1 queue workers present on Forge but not listed locally.');
$command->expectsOutput('Run the command again with the `--force` option to delete them.');
Expand Down