惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

PCI Perspectives
PCI Perspectives
Microsoft Security Blog
Microsoft Security Blog
MongoDB | Blog
MongoDB | Blog
T
The Blog of Author Tim Ferriss
罗磊的独立博客
人人都是产品经理
人人都是产品经理
The Cloudflare Blog
Engineering at Meta
Engineering at Meta
Y
Y Combinator Blog
宝玉的分享
宝玉的分享
Recorded Future
Recorded Future
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
月光博客
月光博客
Recent Announcements
Recent Announcements
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Apple Machine Learning Research
Apple Machine Learning Research
T
Threatpost
The GitHub Blog
The GitHub Blog
M
MIT News - Artificial intelligence
Scott Helme
Scott Helme
P
Palo Alto Networks Blog
T
Tenable Blog
P
Privacy International News Feed
V
Visual Studio Blog
F
Fortinet All Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
I
Intezer
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
AI
AI
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
S
Security Affairs
S
SegmentFault 最新的问题
C
Cisco Blogs
博客园 - 聂微东
MyScale Blog
MyScale Blog
V
Vulnerabilities – Threatpost
量子位
T
The Exploit Database - CXSecurity.com
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Security Latest
Security Latest
P
Proofpoint News Feed
阮一峰的网络日志
阮一峰的网络日志
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
T
Troy Hunt's Blog
T
Tailwind CSS Blog
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
A
About on SuperTechFans
The Last Watchdog
The Last Watchdog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Mutation Testing as Architecture Enforcement: Infection in 2026
Gabriel Anha · 2026-05-20 · via DEV Community

Picture the shape of bug that escapes a green pipeline. A team ships a refactor of a pricing module. The coverage report says 94%. CI is green. Days after release, a customer gets charged the wrong amount on a multi-pack discount that was supposed to drop the total by a clean percentage.

Then someone pulls up the test that was supposed to cover the discount math, and it ends like this:

public function testDiscountAppliesToMultiPack(): void
{
    $cart = new Cart();
    $cart->addItem(new Item('sku-1', 3, 1000));
    $price = $this->pricer->price($cart);

    $this->assertNotNull($price);
}

Enter fullscreen mode Exit fullscreen mode

The test ran the code. Coverage counted the lines. The assertion checked that the result was not null. Nothing checked the actual number. Months of changes had slipped past it.

Coverage tells you which lines ran. It does not tell you which lines were verified. Mutation testing closes that gap. It changes your code in small, deliberate ways and reruns the tests. Anything that still passes is a test that wasn't really testing.

Infection on PHP 8.3, a real surviving mutant, and the reason mutation testing isn't a vanity metric.

What mutation testing actually does

Infection reads your source, applies small code mutations (a > becomes >=, a + becomes -, a return $value becomes return null), and runs your test suite against each mutated version. There are three possible outcomes per mutation:

  • Killed. At least one test failed. Good — your tests noticed the bug.
  • Escaped. All tests passed against the mutated code. Bad — your tests are blind to that behavior.
  • Timed out / errored. The mutation broke the program in some other way. Treated as killed.

The headline number is the Mutation Score Indicator (MSI): the percentage of mutations killed. A second number, Covered Code MSI, restricts the denominator to lines your tests actually executed, so it isolates "tests that look at the code but do not really test it" from "tests that do not touch the code at all."

The two numbers tell different stories. Low coverage MSI means whole files are untested. If covered MSI is low, the tests that exist are weak. The second one is what bites you in production, because it hides under a green coverage badge.

Mutation testing flow: source code is mutated into variants, the test suite runs against each, and each mutant is killed or escapes

Setting up Infection on PHP 8.3

Install it as a dev dependency. Infection 0.29+ works with PHP 8.2 and 8.3, and pairs cleanly with PHPUnit 10/11.

composer require --dev infection/infection:^0.29

Enter fullscreen mode Exit fullscreen mode

Drop a configuration file at the project root:

{
    "$schema": "vendor/infection/infection/resources/schema.json",
    "source": {
        "directories": [
            "src/Domain",
            "src/Application"
        ]
    },
    "timeout": 10,
    "logs": {
        "text": "var/infection.log",
        "html": "var/infection.html",
        "summary": "var/infection-summary.log"
    },
    "mutators": {
        "@default": true
    },
    "testFramework": "phpunit",
    "minMsi": 75,
    "minCoveredMsi": 90
}

Enter fullscreen mode Exit fullscreen mode

Three things in this config matter for how you read the result later.

The source.directories block is the architecture lever. You point Infection at the layers where business behavior lives (Domain and Application in a hexagonal layout). You do not mutate Infrastructure, controllers, or framework glue. Mutating an Eloquent model's $fillable array or a Symfony controller's response code produces noise. The domain is the part worth testing hard, and Infection's source filter is how you encode that intent.

The minMsi and minCoveredMsi thresholds are the CI gate. If the score drops below the threshold, Infection exits non-zero. You wire that into your pipeline the same way you wire PHPStan or CS-Fixer.

Run it:

vendor/bin/infection --threads=8 --show-mutations

Enter fullscreen mode Exit fullscreen mode

The --threads flag matters more than people think. Mutation runs are embarrassingly parallel and the wall-clock cost without threading is what makes teams write mutation testing off as "too slow." On a domain folder of a few thousand lines, eight threads brings a full run under two minutes on a modern laptop.

A surviving mutant: what the report actually shows you

Here is a small domain class. It calculates a tiered discount on a cart subtotal.

<?php
declare(strict_types=1);

namespace App\Domain\Pricing;

final class TieredDiscount
{
    public function applyTo(int $subtotalCents): int
    {
        if ($subtotalCents > 10_000) {
            return (int) ($subtotalCents * 0.85);
        }

        if ($subtotalCents > 5_000) {
            return (int) ($subtotalCents * 0.95);
        }

        return $subtotalCents;
    }
}

Enter fullscreen mode Exit fullscreen mode

The accompanying test, with the kind of assertions a hurried code review will wave through:

<?php
declare(strict_types=1);

namespace App\Tests\Domain\Pricing;

use App\Domain\Pricing\TieredDiscount;
use PHPUnit\Framework\TestCase;

final class TieredDiscountTest extends TestCase
{
    public function testAppliesADiscount(): void
    {
        $discount = new TieredDiscount();

        $result = $discount->applyTo(20_000);

        $this->assertLessThan(20_000, $result);
    }

    public function testReturnsAnInteger(): void
    {
        $discount = new TieredDiscount();

        $result = $discount->applyTo(7_500);

        $this->assertIsInt($result);
    }
}

Enter fullscreen mode Exit fullscreen mode

PHPUnit reports 100% line coverage for TieredDiscount. Every branch executes at least once across the two tests.

Run Infection:

Mutation Score Indicator (MSI):       75%
Mutations:                            8
Killed:                               6
Escaped:                              2
Errors:                               0
Timeouts:                             0

Enter fullscreen mode Exit fullscreen mode

Two mutants escaped. Pull up the log:

1) src/Domain/Pricing/TieredDiscount.php:11    [M] GreaterThan

--- Original
+++ New
- if ($subtotalCents > 10_000) {
+ if ($subtotalCents >= 10_000) {

Enter fullscreen mode Exit fullscreen mode

Infection changed > to >=. The boundary at exactly 10,000 cents now falls into the 15% discount tier instead of the 5% tier. Neither test passes anything close to 10,000 cents (one uses 20,000, the other 7,500), so the change goes unnoticed. The boundary is silent.

2) src/Domain/Pricing/TieredDiscount.php:15    [M] FloatNegation

--- Original
+++ New
- return (int) ($subtotalCents * 0.95);
+ return (int) ($subtotalCents * -0.95);

Enter fullscreen mode Exit fullscreen mode

The discount factor flipped to negative. A 7,500-cent subtotal now returns -7,125 cents, a refund disguised as a charge. The test asserts the result is an integer. -7,125 is an integer. The mutant survives.

Two escaped mutants. Two real bugs that production would have caught for you, with customers as your test fixtures.

The fix is to write the tests the assertions were pretending to be:

public function testTopTierDiscount(): void
{
    $discount = new TieredDiscount();

    $this->assertSame(17_000, $discount->applyTo(20_000));
}

public function testMidTierDiscount(): void
{
    $discount = new TieredDiscount();

    $this->assertSame(7_125, $discount->applyTo(7_500));
}

public function testTopTierBoundaryExclusive(): void
{
    $discount = new TieredDiscount();

    $this->assertSame(9_500, $discount->applyTo(10_000));
}

public function testMidTierBoundaryExclusive(): void
{
    $discount = new TieredDiscount();

    $this->assertSame(5_000, $discount->applyTo(5_000));
}

public function testNoDiscountBelowThreshold(): void
{
    $discount = new TieredDiscount();

    $this->assertSame(3_000, $discount->applyTo(3_000));
}

Enter fullscreen mode Exit fullscreen mode

Rerun Infection. MSI: 100%. The two mutants that escaped before now die on the boundary tests and the exact-value assertions.

The old tests asked "did something happen?" The new tests ask "what is the answer?" Mutation testing forces that shift in question without you having to enforce it by hand in code review.

Why this belongs in the architecture conversation

A hexagonal codebase puts business behavior in one place and infrastructure in another. The split exists so the parts that encode the rules of the business (the parts the company actually pays for) are testable without a database, without a framework boot, without any of the slow stuff. That is the architectural promise.

Mutation testing is how you verify the promise was kept.

If you point Infection at src/Domain and the MSI is 90%, your domain tests are doing real work. If you point it at the same folder and the MSI is 40%, the architecture is a fiction. The code is structured for testability, and nobody is actually testing it.

This is why the source filter in the Infection config is not a performance tweak. It is a statement about what the codebase is for. The domain is where mutation testing earns its cost. Adapters get integration tests with real Postgres, real HTTP, real queues. Those tests run end-to-end, and a mutation framework adds little signal on top. The domain is the place where pure logic concentrates, and the only place where mutation testing is the right tool.

A pragmatic CI setup encodes that:

- name: PHPUnit
  run: vendor/bin/phpunit

- name: Infection (domain layer)
  run: vendor/bin/infection
       --threads=8
       --min-msi=85
       --min-covered-msi=95
       --only-covered

Enter fullscreen mode Exit fullscreen mode

CLI flags override the JSON config when both are set, so the CI run lifts the thresholds above the local baseline.

Two gates. The first one says the tests must pass. The second one says the tests must mean something. A pull request that adds a new domain class without tests does not regress coverage if the file is empty of behavior, but it regresses MSI, because Infection sees an unverified line and counts it. MSI catches the empty-shell class; coverage doesn't.

A coverage badge fades while a mutation score takes its place. Coverage shows what ran; mutation shows what was tested

What to skip and what to tune

Three pitfalls catch teams adopting Infection for the first time.

Mutating the wrong layer. If you point Infection at the whole project, you get hundreds of escaped mutants in infrastructure code: Doctrine entity mappings, HTTP response codes, container configuration. They are noise. The mutator does not know that a switched route status is meaningless in your test setup, and you do not want it to. Keep the source filter tight on domain and application.

Treating MSI as a vanity metric. A perfect 100% MSI on a thousand-line domain is achievable, expensive, and the marginal mutant rarely surfaces real bugs. The honest target for production code is around 85–90% on the domain, with the gate set at the level you actually maintain. Teams that chase 100% end up writing tests that assert the mutator can't reach a branch, not tests that catch bugs.

Running it on every commit. A full Infection run on a large domain takes minutes, not seconds. Run PHPUnit on every commit, Infection on every merge to main, and a full diff-mode run (--git-diff-filter=A, mutating only changed files) on PRs. That is the trade-off most teams settle on after a quarter of usage.

The infrastructure for tracking the score over time exists in the tool. The HTML report shows trends, escaped-mutant categories, and the specific lines that lose points. The escaped-mutant list is the new code-review prompt: instead of "are there enough tests?" the question becomes "why did this mutant escape?"


If this was useful

The hex layout in Decoupled PHP is what makes mutation testing tractable in the first place: a domain you can mutate without booting Laravel or Symfony, a port boundary that tells Infection where to stop, and a use-case layer thin enough that every escaped mutant points at a real gap. The book walks through the testing chapters in the same order this post does: contract tests at the ports, mutation tests in the center, end-to-end on the adapters.

Decoupled PHP — Clean and Hexagonal Architecture for Applications That Outlive the Framework

Available on Kindle, Paperback, and Hardcover. English, German, and Japanese editions out now — Portuguese and Spanish coming soon.