drupal-unit-test

drupal-unit-test is a skill for Claude Code, Codex from trebormc/drupal-ai-agents. It costs 136 tokens per session (2,828 once invoked), scanned A, original, Apache-2.0.

A process for generating PHPUnit unit tests for Drupal 10 and 11 custom modules. Unit tests check PHP code in isolation, using substitutes for outside services instead of starting Drupal or a browser.

In plain words
What is it for?
Use it to read a source class, inspect existing tests, create a test class with Drupal-compatible annotations, and run the test and code-style checks.
Why use it?
It helps test services, plugins, forms, controllers, and event subscribers while keeping tests compatible with both supported Drupal versions.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/trebormc/drupal-ai-agents/drupal-unit-test
Any agent
npx skills add trebormc/drupal-ai-agents --skill drupal-unit-test
Clone the repo
git clone --depth 1 https://github.com/trebormc/drupal-ai-agents

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for drupal-unit-test

README.md
[![agentmods](https://agentmods.dev/badge/skills/trebormc/drupal-ai-agents/drupal-unit-test.svg)](https://agentmods.dev/skills/trebormc/drupal-ai-agents/drupal-unit-test)
Your own site
<a href="https://agentmods.dev/skills/trebormc/drupal-ai-agents/drupal-unit-test"><img src="https://agentmods.dev/badge/skills/trebormc/drupal-ai-agents/drupal-unit-test.svg" alt="Measured on agentmods" height="20"></a>
Per session 136 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,828 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00136 $0.02828
Opus 5 $0.00068 $0.01414
Sonnet 5 $0.00027 $0.00566
Haiku 4.5 $0.00014 $0.00283

Measured 3d ago against content hash 7010a234d927, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

drupal-unit-test scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/skills/drupal-unit-test/SKILL.md · 302 lines

How it starts

The opening of the file, as written. The whole thing — 302 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Environment

All commands via ssh web. Use $DDEV_DOCROOT for paths. Detect test gaps: ssh web drush audit:run phpunit --filter="module:MODULE" --format=json

Drupal 10+11 Compatibility (CRITICAL)

Use PHPDoc annotations only — NEVER PHP 8 attributes. Drupal 10 = PHPUnit 9.x (no attribute support).

Use THIS NOT this
@coversDefaultClass \My\Class #[CoversClass(MyClass::class)]
@covers ::methodName #[Covers('methodName')]
@group mymodule #[Group('mymodule')]
@dataProvider providerName #[DataProvider('providerName')]

Workflow

  1. Read source class in src/
  2. Check existing tests in tests/src/Unit/
  3. Generate test class following templates below
  4. Run test (Form ROOT — requires project phpunit.xml; if missing, use Form CORE from the drupal-testing skill): ssh web ./vendor/bin/phpunit $DDEV_DOCROOT/modules/custom/MODULE/tests/src/Unit/Service/MyServiceTest.php
  5. Run PHPCS — always try Audit module first:
    # Preferred: Audit module (check if installed first)
    ssh web drush audit:run phpcs --filter="module:MODULE" --format=json
    # Fallback only if Audit module not installed:
    ssh web ./vendor/bin/phpcs --standard=Drupal,DrupalPractice $DDEV_DOCROOT/modules/custom/MODULE/tests/src/Unit/
    

File Structure & Namespace

$DDEV_DOCROOT/modules/custom/MODULE/tests/src/Unit/
├── Service/MyServiceTest.php        # Drupal\Tests\MODULE\Unit\Service
├── Plugin/Block/MyBlockTest.php     # Drupal\Tests\MODULE\Unit\Plugin\Block
├── Form/MyFormTest.php              # Drupal\Tests\MODULE\Unit\Form
└── Controller/MyControllerTest.php  # Drupal\Tests\MODULE\Unit\Controller

Template: Service Test (Complete Example)

<?php

declare(strict_types=1);

namespace Drupal\Tests\mymodule\Unit\Service;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\ImmutableConfig;
use Drupal\mymodule\Service\MyService;
use Drupal\Tests\UnitTestCase;

/**
 * Tests the MyService class.
 *
 * @coversDefaultClass \Drupal\mymodule\Service\MyService
 * @group mymodule
 */
class MyServiceTest extends UnitTestCase {

  protected MyService $service;
  protected ConfigFactoryInterface $configFactory;

  /**
   * {@inheritdoc}
   */
  protected function setUp(): void {
    parent::setUp();
    $this->configFactory = $this->createMock(ConfigFactoryInterface::class);
    $this->service = new MyService($this->configFactory);
  }

  /**
   * @covers ::process
   */
  public function testProcessValidInput(): void {
    $config = $this->createMock(ImmutableConfig::class);
    $config->method('get')->willReturn('value');
    $this->configFactory->method('get')->willReturn($config);
    $result = $this->service->process('test');
    $this->assertIsArray($result);
    $this->assertNotEmpty($result);
  }

  /**
   * @covers ::process
   * @dataProvider processDataProvider
   */
  public function testProcessScenarios(string $input, bool $expectEmpty): void {
    $config = $this->createMock(ImmutableConfig::class);
    $config->method('get')->willReturn('default');
    $this->configFactory->method('get')->willReturn($config);
    $result = $this->service->process($input);
    $this->assertEquals($expectEmpty, empty($result));
  }

  /**
   * @return array
   *   Test scenarios.
   */
  public static function processDataProvider(): array {
    return [
      'valid input' => ['valid', FALSE],
      'another case' => ['other', FALSE],
    ];
  }

}

Read the full file on GitHub · 302 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 302 lines · 136 tokens per session scan A 7010a234d927

Subscribe to this mod's changes

drupal-unit-test is a skill published in the GitHub repository trebormc/drupal-ai-agents (10 stars, last pushed 1mo ago), licensed Apache-2.0. It adds 136 tokens to every session and 2,828 once invoked, about $0.0007 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.