Skip to content

Commit 14580ef

Browse files
committed
add task registration tests
1 parent a6ecb36 commit 14580ef

10 files changed

Lines changed: 331 additions & 0 deletions
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Gaambo\DeployerWordpress\Tests\Integration\Tasks;
4+
5+
class DatabaseTasksRegistrationTest extends TaskRegistrationTestCase
6+
{
7+
protected static function loadTasks(): void
8+
{
9+
// Require on each run, so they are registered again on the new Deployer instance.
10+
require __DIR__ . '/../../../tasks/database.php';
11+
}
12+
13+
public function testTasksAreRegistered(): void
14+
{
15+
// Verify database tasks are registered
16+
$this->assertTaskExists('db:remote:backup');
17+
$this->assertTaskExists('db:local:backup');
18+
$this->assertTaskExists('db:remote:import');
19+
$this->assertTaskExists('db:local:import');
20+
$this->assertTaskExists('db:push');
21+
$this->assertTaskExists('db:pull');
22+
}
23+
24+
public function testTaskDependencies(): void
25+
{
26+
// Verify task dependencies
27+
$this->assertTaskDependencies('db:push', ['db:local:backup', 'db:remote:import']);
28+
$this->assertTaskDependencies('db:pull', ['db:remote:backup', 'db:local:import']);
29+
}
30+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Gaambo\DeployerWordpress\Tests\Integration\Tasks;
4+
5+
class FilesTasksRegistrationTest extends TaskRegistrationTestCase
6+
{
7+
protected static function loadTasks(): void
8+
{
9+
// Require on each run, so they are registered again on the new Deployer instance.
10+
require __DIR__ . '/../../../tasks/files.php';
11+
}
12+
13+
public function testTasksAreRegistered(): void
14+
{
15+
// Verify files tasks are registered
16+
$this->assertTaskExists('files:push');
17+
$this->assertTaskExists('files:pull');
18+
$this->assertTaskExists('files:sync');
19+
$this->assertTaskExists('files:backup:remote');
20+
$this->assertTaskExists('files:backup:local');
21+
}
22+
23+
public function testTaskDependencies(): void
24+
{
25+
// Verify task dependencies
26+
$this->assertTaskDependencies('files:push', [
27+
'wp:push',
28+
'uploads:push',
29+
'plugins:push',
30+
'mu-plugins:push',
31+
'themes:push',
32+
'packages:push'
33+
]);
34+
$this->assertTaskDependencies('files:pull', [
35+
'wp:pull',
36+
'uploads:pull',
37+
'plugins:pull',
38+
'mu-plugins:pull',
39+
'themes:pull',
40+
'packages:pull'
41+
]);
42+
$this->assertTaskDependencies('files:sync', ['files:push', 'files:pull']);
43+
}
44+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Gaambo\DeployerWordpress\Tests\Integration\Tasks;
4+
5+
class LanguagesTasksRegistrationTest extends TaskRegistrationTestCase
6+
{
7+
protected static function loadTasks(): void
8+
{
9+
// Require on each run, so they are registered again on the new Deployer instance.
10+
require __DIR__ . '/../../../tasks/languages.php';
11+
}
12+
13+
public function testTasksAreRegistered(): void
14+
{
15+
// Verify languages tasks are registered
16+
$this->assertTaskExists('languages:push');
17+
$this->assertTaskExists('languages:pull');
18+
$this->assertTaskExists('languages:sync');
19+
$this->assertTaskExists('languages:backup:remote');
20+
$this->assertTaskExists('languages:backup:local');
21+
}
22+
23+
public function testTaskDependencies(): void
24+
{
25+
// Verify task dependencies
26+
$this->assertTaskDependencies('languages:sync', ['languages:push', 'languages:pull']);
27+
}
28+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Gaambo\DeployerWordpress\Tests\Integration\Tasks;
4+
5+
class MuPluginsTasksRegistrationTest extends TaskRegistrationTestCase
6+
{
7+
protected static function loadTasks(): void
8+
{
9+
// Require on each run, so they are registered again on the new Deployer instance.
10+
require __DIR__ . '/../../../tasks/mu-plugins.php';
11+
}
12+
13+
public function testTasksAreRegistered(): void
14+
{
15+
// Verify mu-plugin tasks are registered
16+
$this->assertTaskExists('mu-plugin:vendors');
17+
$this->assertTaskExists('mu-plugin');
18+
$this->assertTaskExists('mu-plugins:push');
19+
$this->assertTaskExists('mu-plugins:pull');
20+
$this->assertTaskExists('mu-plugins:sync');
21+
$this->assertTaskExists('mu-plugins:backup:remote');
22+
$this->assertTaskExists('mu-plugins:backup:local');
23+
}
24+
25+
public function testTaskDependencies(): void
26+
{
27+
// Verify task dependencies
28+
$this->assertTaskDependencies('mu-plugin', ['mu-plugin:vendors']);
29+
$this->assertTaskDependencies('mu-plugins:sync', ['mu-plugins:push', 'mu-plugins:pull']);
30+
}
31+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Gaambo\DeployerWordpress\Tests\Integration\Tasks;
4+
5+
class PackagesTasksRegistrationTest extends TaskRegistrationTestCase
6+
{
7+
protected static function loadTasks(): void
8+
{
9+
// Require on each run, so they are registered again on the new Deployer instance.
10+
require __DIR__ . '/../../../tasks/packages.php';
11+
}
12+
13+
public function testTasksAreRegistered(): void
14+
{
15+
// Verify package tasks are registered
16+
$this->assertTaskExists('packages:assets:vendors');
17+
$this->assertTaskExists('packages:assets:build');
18+
$this->assertTaskExists('packages:assets');
19+
$this->assertTaskExists('packages:vendors');
20+
$this->assertTaskExists('packages');
21+
$this->assertTaskExists('packages:push');
22+
$this->assertTaskExists('packages:pull');
23+
$this->assertTaskExists('packages:sync');
24+
$this->assertTaskExists('packages:backup:remote');
25+
$this->assertTaskExists('packages:backup:local');
26+
}
27+
28+
public function testTaskDependencies(): void
29+
{
30+
// Verify task dependencies
31+
$this->assertTaskDependencies('packages:assets', ['packages:assets:vendors', 'packages:assets:build']);
32+
$this->assertTaskDependencies('packages', ['packages:assets', 'packages:vendors']);
33+
$this->assertTaskDependencies('packages:sync', ['packages:push', 'packages:pull']);
34+
}
35+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Gaambo\DeployerWordpress\Tests\Integration\Tasks;
4+
5+
class PluginsTasksRegistrationTest extends TaskRegistrationTestCase
6+
{
7+
protected static function loadTasks(): void
8+
{
9+
// Require on each run, so they are registered again on the new Deployer instance.
10+
require __DIR__ . '/../../../tasks/plugins.php';
11+
}
12+
13+
public function testTasksAreRegistered(): void
14+
{
15+
// Verify plugins tasks are registered
16+
$this->assertTaskExists('plugins:push');
17+
$this->assertTaskExists('plugins:pull');
18+
$this->assertTaskExists('plugins:sync');
19+
$this->assertTaskExists('plugins:backup:remote');
20+
$this->assertTaskExists('plugins:backup:local');
21+
}
22+
23+
public function testTaskDependencies(): void
24+
{
25+
// Verify task dependencies
26+
$this->assertTaskDependencies('plugins:sync', ['plugins:push', 'plugins:pull']);
27+
}
28+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Gaambo\DeployerWordpress\Tests\Integration\Tasks;
4+
5+
use Deployer\Task\GroupTask;
6+
use Gaambo\DeployerWordpress\Tests\Integration\IntegrationTestCase;
7+
8+
abstract class TaskRegistrationTestCase extends IntegrationTestCase
9+
{
10+
abstract protected static function loadTasks(): void;
11+
12+
protected function setUp(): void
13+
{
14+
parent::setUp();
15+
// Require on each run, so they are registered again on the new Deployer instance.
16+
static::loadTasks();
17+
}
18+
19+
protected function assertTaskExists(string $taskName): void
20+
{
21+
$this->assertTrue(
22+
$this->deployer->tasks->has($taskName),
23+
"Task '$taskName' should be registered"
24+
);
25+
}
26+
27+
/**
28+
* @param string $taskName
29+
* @param string[] $expectedDependencies
30+
* @return void
31+
*/
32+
protected function assertTaskDependencies(string $taskName, array $expectedDependencies): void
33+
{
34+
$task = $this->deployer->tasks->get($taskName);
35+
$this->assertInstanceOf(GroupTask::class, $task);
36+
$this->assertEquals($expectedDependencies, $task->getGroup());
37+
}
38+
39+
abstract protected function testTasksAreRegistered(): void;
40+
abstract protected function testTaskDependencies(): void;
41+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Gaambo\DeployerWordpress\Tests\Integration\Tasks;
4+
5+
class ThemesTasksRegistrationTest extends TaskRegistrationTestCase
6+
{
7+
protected static function loadTasks(): void
8+
{
9+
// Require on each run, so they are registered again on the new Deployer instance.
10+
require __DIR__ . '/../../../tasks/themes.php';
11+
}
12+
13+
public function testTasksAreRegistered(): void
14+
{
15+
// Verify theme tasks are registered
16+
$this->assertTaskExists('theme:assets:vendors');
17+
$this->assertTaskExists('theme:assets:build');
18+
$this->assertTaskExists('theme:assets');
19+
$this->assertTaskExists('theme:vendors');
20+
$this->assertTaskExists('theme');
21+
$this->assertTaskExists('themes:push');
22+
$this->assertTaskExists('themes:pull');
23+
$this->assertTaskExists('themes:sync');
24+
$this->assertTaskExists('themes:backup:remote');
25+
$this->assertTaskExists('themes:backup:local');
26+
}
27+
28+
public function testTaskDependencies(): void
29+
{
30+
// Verify task dependencies
31+
$this->assertTaskDependencies('theme:assets', ['theme:assets:vendors', 'theme:assets:build']);
32+
$this->assertTaskDependencies('theme', ['theme:assets', 'theme:vendors']);
33+
$this->assertTaskDependencies('themes:sync', ['themes:push', 'themes:pull']);
34+
}
35+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Gaambo\DeployerWordpress\Tests\Integration\Tasks;
4+
5+
class UploadsTasksRegistrationTest extends TaskRegistrationTestCase
6+
{
7+
protected static function loadTasks(): void
8+
{
9+
// Require on each run, so they are registered again on the new Deployer instance.
10+
require __DIR__ . '/../../../tasks/uploads.php';
11+
}
12+
13+
public function testTasksAreRegistered(): void
14+
{
15+
// Verify uploads tasks are registered
16+
$this->assertTaskExists('uploads:push');
17+
$this->assertTaskExists('uploads:pull');
18+
$this->assertTaskExists('uploads:sync');
19+
$this->assertTaskExists('uploads:backup:remote');
20+
$this->assertTaskExists('uploads:backup:local');
21+
}
22+
23+
public function testTaskDependencies(): void
24+
{
25+
// Verify task dependencies
26+
$this->assertTaskDependencies('uploads:sync', ['uploads:push', 'uploads:pull']);
27+
}
28+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Gaambo\DeployerWordpress\Tests\Integration\Tasks;
4+
5+
class WpTasksRegistrationTest extends TaskRegistrationTestCase
6+
{
7+
protected static function loadTasks(): void
8+
{
9+
// Require on each run, so they are registered again on the new Deployer instance.
10+
require __DIR__ . '/../../../tasks/wp.php';
11+
}
12+
13+
public function testTasksAreRegistered(): void
14+
{
15+
// Verify wp tasks are registered
16+
$this->assertTaskExists('wp:download-core');
17+
$this->assertTaskExists('wp:push');
18+
$this->assertTaskExists('wp:pull');
19+
$this->assertTaskExists('wp:info');
20+
$this->assertTaskExists('wp:install-wpcli');
21+
}
22+
23+
/**
24+
* @doesNotPerformAssertions
25+
* @return void
26+
*/
27+
public function testTaskDependencies(): void
28+
{
29+
// No grouped tasks in wp.php
30+
}
31+
}

0 commit comments

Comments
 (0)