From 1e22556f6a52c8e7b2f9686e67d217c24e09838c Mon Sep 17 00:00:00 2001
From: Oliver Davies <oliver@oliverdavies.dev>
Date: Wed, 10 May 2023 12:20:55 +0100
Subject: [PATCH] feat(nvim): add Phpactor templates for Drupal tests

---
 config/phpactor/phpactor.yml                  |  4 ++++
 .../SourceCode.php.twig                       | 21 +++++++++++++++++++
 .../drupal-kernel-test/SourceCode.php.twig    | 21 +++++++++++++++++++
 .../drupal-unit-test/SourceCode.php.twig      | 13 ++++++++++++
 home-manager/modules/common.nix               |  5 +++++
 5 files changed, 64 insertions(+)
 create mode 100644 config/phpactor/phpactor.yml
 create mode 100644 config/phpactor/templates/drupal-functional-test/SourceCode.php.twig
 create mode 100644 config/phpactor/templates/drupal-kernel-test/SourceCode.php.twig
 create mode 100644 config/phpactor/templates/drupal-unit-test/SourceCode.php.twig

diff --git a/config/phpactor/phpactor.yml b/config/phpactor/phpactor.yml
new file mode 100644
index 0000000..9b11d77
--- /dev/null
+++ b/config/phpactor/phpactor.yml
@@ -0,0 +1,4 @@
+code_transform.class_new.variants:
+  drupal-functional-test: drupal-functional-test
+  drupal-kernel-test: drupal-kernel-test
+  drupal-unit-test: drupal-unit-test
diff --git a/config/phpactor/templates/drupal-functional-test/SourceCode.php.twig b/config/phpactor/templates/drupal-functional-test/SourceCode.php.twig
new file mode 100644
index 0000000..08340a2
--- /dev/null
+++ b/config/phpactor/templates/drupal-functional-test/SourceCode.php.twig
@@ -0,0 +1,21 @@
+<?php
+
+declare(strict_types=1);
+
+namespace {{ prototype.namespace }};
+
+use Drupal\Tests\BrowserTestBase;
+
+{% for class in prototype.classes %}
+final class {{ class.name }} extends BrowserTestBase {
+
+  public $defaultTheme = 'stark';
+
+  public static $modules = [];
+
+  public function setUp(): void {
+    parent::setUp();
+  }
+
+}
+{% endfor %}
diff --git a/config/phpactor/templates/drupal-kernel-test/SourceCode.php.twig b/config/phpactor/templates/drupal-kernel-test/SourceCode.php.twig
new file mode 100644
index 0000000..ce136fd
--- /dev/null
+++ b/config/phpactor/templates/drupal-kernel-test/SourceCode.php.twig
@@ -0,0 +1,21 @@
+<?php
+
+declare(strict_types=1);
+
+namespace {{ prototype.namespace }};
+
+use Drupal\KernelTests\KernelTestBase;
+
+{% for class in prototype.classes %}
+final class {{ class.name }} extends KernelTestBase {
+
+  public static $modules = [];
+
+  protected $strictConfigSchema = FALSE;
+
+  public function setUp(): void {
+    parent::setUp();
+  }
+
+}
+{% endfor %}
diff --git a/config/phpactor/templates/drupal-unit-test/SourceCode.php.twig b/config/phpactor/templates/drupal-unit-test/SourceCode.php.twig
new file mode 100644
index 0000000..b797a61
--- /dev/null
+++ b/config/phpactor/templates/drupal-unit-test/SourceCode.php.twig
@@ -0,0 +1,13 @@
+<?php
+
+declare(strict_types=1);
+
+namespace {{ prototype.namespace }};
+
+use Drupal\Tests\UnitTestCase;
+
+{% for class in prototype.classes %}
+final class {{ class.name }} extends UnitTestCase {
+
+}
+{% endfor %}
diff --git a/home-manager/modules/common.nix b/home-manager/modules/common.nix
index 2bedce5..bed1671 100644
--- a/home-manager/modules/common.nix
+++ b/home-manager/modules/common.nix
@@ -236,4 +236,9 @@ in
     source = ../../config/neovim;
     recursive = true;
   };
+
+  xdg.configFile.phpactor = {
+    source = ../../config/phpactor;
+    recursive = true;
+  };
 }