|
| 1 | +<?php |
| 2 | + |
| 3 | +use GuzzleHttp\Psr7\Response; |
| 4 | + |
| 5 | +beforeEach(function () { |
| 6 | + setTestConfigFile(); |
| 7 | + |
| 8 | + $this->clientMock->shouldReceive('request')->with('POST', 'sites/1/wp-cli', [ |
| 9 | + 'form_params' => [ |
| 10 | + 'commands' => ['core version'], |
| 11 | + ], |
| 12 | + ])->andReturn( |
| 13 | + new Response(200, [], json_encode(['event_id' => 100])) |
| 14 | + ); |
| 15 | +}); |
| 16 | + |
| 17 | +afterEach(function () { |
| 18 | + deleteTestConfigFile(); |
| 19 | +}); |
| 20 | + |
| 21 | +test('wp-cli command with site ID and command supplied', function () { |
| 22 | + $this->clientMock->shouldReceive('request')->with('GET', 'events/100', [])->andReturn( |
| 23 | + new Response(200, [], json_encode([ |
| 24 | + 'data' => [ |
| 25 | + 'id' => 100, |
| 26 | + 'status' => 'deployed', |
| 27 | + 'output' => "$ core version\n6.4.2", |
| 28 | + ], |
| 29 | + ])) |
| 30 | + ); |
| 31 | + |
| 32 | + $this->artisan('sites:wp-cli', ['site_id' => '1', '--command' => ['core version']]) |
| 33 | + ->expectsOutput('==> WP-CLI commands queued for execution.') |
| 34 | + ->assertExitCode(0); |
| 35 | +}); |
| 36 | + |
| 37 | +test('wp-cli command with interactive site selection', function () { |
| 38 | + $this->clientMock->shouldReceive('request')->once()->with('GET', 'sites?page=1&limit=100', [])->andReturn( |
| 39 | + new Response(200, [], json_encode([ |
| 40 | + 'data' => [ |
| 41 | + [ |
| 42 | + 'id' => 1, |
| 43 | + 'domain' => 'hellfishmedia.com', |
| 44 | + ], |
| 45 | + ], |
| 46 | + 'pagination' => [ |
| 47 | + 'previous' => null, |
| 48 | + 'next' => null, |
| 49 | + 'count' => 1, |
| 50 | + ], |
| 51 | + ])) |
| 52 | + ); |
| 53 | + |
| 54 | + $this->clientMock->shouldReceive('request')->with('GET', 'events/100', [])->andReturn( |
| 55 | + new Response(200, [], json_encode([ |
| 56 | + 'data' => [ |
| 57 | + 'id' => 100, |
| 58 | + 'status' => 'deployed', |
| 59 | + 'output' => "$ core version\n6.4.2", |
| 60 | + ], |
| 61 | + ])) |
| 62 | + ); |
| 63 | + |
| 64 | + $this->artisan('sites:wp-cli', ['--command' => ['core version']]) |
| 65 | + ->expectsQuestion('Which site would you like to run WP-CLI commands on', '1') |
| 66 | + ->expectsOutput('==> WP-CLI commands queued for execution.') |
| 67 | + ->assertExitCode(0); |
| 68 | +}); |
| 69 | + |
| 70 | +test('wp-cli command with multiple commands', function () { |
| 71 | + $this->clientMock->shouldReceive('request')->with('POST', 'sites/1/wp-cli', [ |
| 72 | + 'form_params' => [ |
| 73 | + 'commands' => ['core version', 'plugin list --status=active'], |
| 74 | + ], |
| 75 | + ])->andReturn( |
| 76 | + new Response(200, [], json_encode(['event_id' => 101])) |
| 77 | + ); |
| 78 | + |
| 79 | + $this->clientMock->shouldReceive('request')->with('GET', 'events/101', [])->andReturn( |
| 80 | + new Response(200, [], json_encode([ |
| 81 | + 'data' => [ |
| 82 | + 'id' => 101, |
| 83 | + 'status' => 'deployed', |
| 84 | + 'output' => "$ core version\n6.4.2\n\n$ plugin list --status=active\nName\tStatus\tVersion", |
| 85 | + ], |
| 86 | + ])) |
| 87 | + ); |
| 88 | + |
| 89 | + $this->artisan('sites:wp-cli', ['site_id' => '1', '--command' => ['core version', 'plugin list --status=active']]) |
| 90 | + ->expectsOutput('==> WP-CLI commands queued for execution.') |
| 91 | + ->assertExitCode(0); |
| 92 | +}); |
0 commit comments