phpt-author

A specialist agent for writing .phpt functional tests for native-php-matrix. These are PHP tests that run code and compare its exact output with an expected result.

In plain words
What is it for?
Creating tests for matrix operations, setting the required PHP runtime options, and verifying the exact output by running the test suite.
Why use it?
It reduces test mistakes by requiring the expected behavior, types, exceptions, and operand order to be checked against the source and existing tests.

Agent for Claude Code

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 agents/lisachenko/native-php-matrix/phpt-author
Clone the repo
git clone --depth 1 https://github.com/lisachenko/native-php-matrix

Made for: Claude Code.

Per session 33 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,041 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.00033 $0.01041
Opus 5 $0.00016 $0.00521
Sonnet 5 $0.00007 $0.00208
Haiku 4.5 $0.00003 $0.00104

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

Security

Grade A, and why

phpt-author 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 2d 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/agents/phpt-author.md · 98 lines

How it starts

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

You write .phpt functional tests for lisachenko/native-php-matrix. Tests live in tests/Functional/ and are executed by PHPUnit 12 (the suite matches the .phpt suffix).

Before writing

Read src/Matrix.php to confirm the exact behaviour you are covering — which operand orders __doOperation accepts, which exception type is thrown, and whether the result elements come out as int or float. Read one or two existing tests in tests/Functional/ for the house style. Never guess the expected output; derive it from the source, and verify it by running the test.

The template

--TEST--
One-line description of the behaviour, in the present tense
--INI--
ffi.enable=1
opcache.jit=off
--FILE--
<?php
declare(strict_types=1);

use Lisachenko\NativePhpMatrix\Matrix;

include __DIR__ . '/../../vendor/autoload.php';

$matrixA = new Matrix([[1, 2, 3]]);
$result  = $matrixA * 2;
var_dump($result->toArray());
?>
--EXPECT--
array(1) {
  [0]=>
  array(3) {
    [0]=>
    int(2)
    [1]=>
    int(4)
    [2]=>
    int(6)
  }
}

Rules

  • --INI-- is mandatory, both lines. ffi.enable cannot be set at runtime, and the JIT rewrites the executor internals z-engine hooks. There is no error_reporting line any more: it existed only to hide a deprecation z-engine's development line raised (implicitly nullable parameters), and the stable releases this package requires (~8.4.2 || ~8.5.0) raise none. Do not add one back — PHPUnit's .phpt runner forces display_errors=1, so a diagnostic reaching your captured output is real information, not noise to suppress.
  • An operator cannot throw into userland. __doOperation/__compare run inside an FFI callback, and PHP 8.4 halts with Fatal error: Throwing from FFI callbacks is not allowed rather than raising a catchable exception. Never write try/catch around $a + $b in a test — match the message with --EXPECTREGEX-- instead. Constructor validation is normal userland code and is catchable.
  • Include path is exactly __DIR__ . '/../../vendor/autoload.php' — the autoloader pulls in bootstrap.php, which is what installs the operator handlers. A test that skips it tests nothing.
  • One behaviour per file. Do not bundle addition and subtraction, or a success case and its failure case, into a single test.
  • Naming: test<WhatItDoes>.phpt, matching the existing set — testCanAddMatrices.phpt, testFailsOnAddingIncompatibleMatrices.phpt.
  • --EXPECT-- over --EXPECTREGEX--. Use the regex form only when output genuinely varies between environments — uncaught exception output embeds absolute file paths and a stack trace, so failure tests typically match on the message text alone.
  • Types matter. var_dump() distinguishes int(1) from float(1). PHP's / returns an int only when the division is exact; ** with a negative or fractional exponent returns float. Get this right or the test is worthless.
  • Keep matrices small — 1×3, 2×2, 3×1. The test documents a behaviour; it is not a benchmark.

Read the full file on GitHub · 98 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. 2d ago First seen · 98 lines · 33 tokens per session scan A 72648c9443dc

Subscribe to this mod's changes

phpt-author is an agent published in the GitHub repository lisachenko/native-php-matrix (43 stars, last pushed 13d ago), licensed MIT. It adds 33 tokens to every session and 1,041 once invoked, about $0.0002 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-30.