<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: MicroUnit</title>
    <description>The latest articles on DEV Community by MicroUnit (@micro_unit_php).</description>
    <link>https://dev.to/micro_unit_php</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3665824%2F8162bb83-6ee8-4028-9f86-f70c5886dd54.png</url>
      <title>DEV Community: MicroUnit</title>
      <link>https://dev.to/micro_unit_php</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/micro_unit_php"/>
    <language>en</language>
    <item>
      <title>I write my PHP testing framework with AI. Here's how the quality stays high.</title>
      <dc:creator>MicroUnit</dc:creator>
      <pubDate>Mon, 23 Nov 2026 10:10:11 +0000</pubDate>
      <link>https://dev.to/micro_unit_php/i-write-my-php-testing-framework-with-ai-heres-how-the-quality-stays-high-4d25</link>
      <guid>https://dev.to/micro_unit_php/i-write-my-php-testing-framework-with-ai-heres-how-the-quality-stays-high-4d25</guid>
      <description>&lt;p&gt;MicroUnit 1.0 came out this week. It's a PHP testing framework with zero dependencies, and almost all of its code, tests and documentation started as AI output. I chose that on purpose, and I'm saying it up front because I know how that sentence lands in 2026. "Written with AI" reads to a lot of developers like "nobody really checked".&lt;/p&gt;

&lt;p&gt;So this post is about the checking. Not "trust me", but the actual setup, with links, so you can decide for yourself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why AI at all
&lt;/h2&gt;

&lt;p&gt;MicroUnit started in May 2025 as a side project. By the summer it had a public beta, and then it stalled. Code coverage, parallel runs, a browser UI, framework integrations: building all of that next to a full-time job was too much for one person. Testing it properly was even more.&lt;/p&gt;

&lt;p&gt;AI changed the capacity, not the standard. With it, I could test each feature from several sides, how it fails as well as how it passes, which I would never have had the time for on my own.&lt;/p&gt;

&lt;h2&gt;
  
  
  Who decides, who writes
&lt;/h2&gt;

&lt;p&gt;The split is simple. I decide what MicroUnit does and what it leaves out, how every public API reads in a test, and the architecture. AI implements those decisions, writes the tests for them and writes the docs from the source. Then I review every change.&lt;/p&gt;

&lt;p&gt;My review is the one step nobody can verify from the outside. It covers what no automated check can: whether a change is the right one, whether an API reads well, whether a test checks the right thing in the first place. Everything that can be checked automatically is, on every change, so my attention goes where only a person helps.&lt;/p&gt;

&lt;h2&gt;
  
  
  The harness the AI works in
&lt;/h2&gt;

&lt;p&gt;Every AI session starts with the same rules. &lt;code&gt;CLAUDE.md&lt;/code&gt; in the repo holds the code rules (zero dependencies, typed, &lt;code&gt;final readonly&lt;/code&gt; by default, no dead code), the commands, the known pitfalls and what "done" means: tests added, suite, canary, lint and PHPStan green, docs updated in the same change.&lt;/p&gt;

&lt;p&gt;MicroUnit also answers the agent in a format built for it: one compact JSON object with only the failures, each with the file and line, expected and actual values, plus a warning for every test that passes without asserting anything. The agent's attention goes to what broke, not to a wall of green dots.&lt;/p&gt;

&lt;h2&gt;
  
  
  Twelve runs for every change
&lt;/h2&gt;

&lt;p&gt;Every push and pull request runs the full suite twelve times: Ubuntu, Windows and macOS, PHP 8.5 and 8.6, once sequentially and once spread over four parallel workers. &lt;code&gt;error_reporting=-1&lt;/code&gt; and OPcache off, so every notice counts and every run compiles from scratch.&lt;/p&gt;

&lt;p&gt;The sequential/parallel pair catches a nasty class of bug: tests that quietly depend on what another test left behind. And the matrix earns its keep. Just before the release, it surfaced three real bugs that only appeared on some platforms, including a parallel worker on Windows with PHP 8.5 whose results got lost. Each fix shipped with a test.&lt;/p&gt;

&lt;h2&gt;
  
  
  MicroUnit is tested with MicroUnit
&lt;/h2&gt;

&lt;p&gt;The suite runs on MicroUnit itself. That's a loop: a change goes in, its own suite runs with the code that just changed, a test turns red, the fix comes with a test that stays forever.&lt;/p&gt;

&lt;p&gt;The obvious question: could a broken MicroUnit pass its own tests? It's harder than it sounds, because dozens of tests check that assertions &lt;em&gt;fail&lt;/em&gt; when they should, and those are checked by different code (&lt;code&gt;Assert::throws()&lt;/code&gt; checking &lt;code&gt;Assert::exact()&lt;/code&gt;, for example). Integration tests run the real command line as a separate process against projects with known outcomes.&lt;/p&gt;

&lt;p&gt;The one thing a loop can't judge about itself is whether failures get reported at all. That's what the canary is for: a tiny script that loads none of MicroUnit's code, runs four tests with known outcomes (one passes, three fail in different ways) and checks the exit code and the report with plain PHP. If MicroUnit ever stops telling red from green, the canary goes red first.&lt;/p&gt;

&lt;h2&gt;
  
  
  The check I'd point to first
&lt;/h2&gt;

&lt;p&gt;When a test goes red, an agent can make it green the wrong way: delete the assertion, change the expected value to whatever the code returns now, add a skip. That's the specific risk that comes with AI, so MicroUnit has a check for exactly that. It compares the tests with the previous version and lists removed assertions, changed expected values, new skips and removed tests.&lt;/p&gt;

&lt;p&gt;In an agent session it runs after every test run, so the agent hears about it while it's still working. On pull requests, any finding fails the build. And it isn't special tooling for my repo: any project can turn it on with &lt;code&gt;withIntegrityCheck()&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The rest of the safety net
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Static analysis:&lt;/strong&gt; PHPStan at max on all of &lt;code&gt;src/&lt;/code&gt; and &lt;code&gt;bin/&lt;/code&gt;, no baseline file. It runs as a PHAR, so it doesn't break the zero-dependency rule.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Coverage floor:&lt;/strong&gt; about half of &lt;code&gt;src/&lt;/code&gt; is covered, and CI fails below 47%. That number undercounts, honestly: the coverage tool measures the framework it's part of, so the files that start a run (the coverage tool itself, the CLI, the config) are already loaded before measuring begins and show 0% even though they have tests.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Docs lint:&lt;/strong&gt; the docs are written by AI from the source, so CI checks that every CLI flag, config option, assertion and fluent method appears in them, and that every link leads somewhere. Whether every sentence is &lt;em&gt;right&lt;/em&gt; is still my review.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Real projects before a release
&lt;/h2&gt;

&lt;p&gt;My own suite only contains the cases I thought of. So before a release, MicroUnit runs the test suites of six real open-source projects: brick/math, nesbot/carbon, webmozart/assert, league/commonmark, symfony/yaml and monolog/monolog. Their tests are translated with &lt;code&gt;microunit migrate&lt;/code&gt;, nobody touches the result by hand, and a project only counts when every test passes and MicroUnit runs exactly as many tests as PHPUnit does. The same runs feed the benchmarks, and everything is reproducible.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where this leaves me
&lt;/h2&gt;

&lt;p&gt;I don't think AI makes software trustworthy or untrustworthy on its own. What makes it trustworthy is what surrounds it, and whether you can see that. Everything above is public: the pipeline, the canary, the lint, the PHPStan config, the integrity check.&lt;/p&gt;

&lt;p&gt;If you find a hole in this setup, I'd genuinely like to hear it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The whole process, with links to every check: &lt;a href="https://mitarnik04.github.io/MicroUnit/quality-with-ai/" rel="noopener noreferrer"&gt;https://mitarnik04.github.io/MicroUnit/quality-with-ai/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;MicroUnit on GitHub: &lt;a href="https://github.com/mitarnik04/MicroUnit" rel="noopener noreferrer"&gt;https://github.com/mitarnik04/MicroUnit&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Docs: &lt;a href="https://mitarnik04.github.io/MicroUnit/" rel="noopener noreferrer"&gt;https://mitarnik04.github.io/MicroUnit/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>php</category>
      <category>testing</category>
      <category>ai</category>
      <category>opensource</category>
    </item>
    <item>
      <title>How I Refactored My Test Output Architecture for MicroUnit</title>
      <dc:creator>MicroUnit</dc:creator>
      <pubDate>Thu, 18 Dec 2025 22:01:47 +0000</pubDate>
      <link>https://dev.to/micro_unit_php/how-i-refactored-my-test-output-architecture-for-microunit-a5i</link>
      <guid>https://dev.to/micro_unit_php/how-i-refactored-my-test-output-architecture-for-microunit-a5i</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Disclaimer: every time I use the word &lt;strong&gt;TestWriter&lt;/strong&gt; I am referring to the different implementations of the &lt;code&gt;ITestWriter&lt;/code&gt; interface.  &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When I first released MicroUnit, I rushed the beta and left some design baggage in the code. Specifically, the output formatting logic was scattered across multiple classes like assertions, the Diff helper, and even a few other places. &lt;/p&gt;

&lt;p&gt;This approach did get the job done and allowed me to show the kind of test output I wanted. However, it was clear from the start that I wasn’t happy with it. So even then it was clear → it had to go at some point. Now I can finally say I found the time to refactor this part of the code. &lt;/p&gt;

&lt;p&gt;In this article, I'm going to try to explain exactly how this part of the code works, what the problem was and my idea + implementation to fix it. &lt;/p&gt;

&lt;p&gt;Enjoy !&lt;/p&gt;




&lt;h2&gt;
  
  
  The Core Architecture
&lt;/h2&gt;

&lt;p&gt;Let me give you a little insight on how the core architecture of MicroUnit is designed so you understand what I'm talking about. &lt;/p&gt;

&lt;p&gt;So simplifying it to only the things relevant for this post, the flow is as follows: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Case: Test failing on Assertion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Tester&lt;/code&gt; runs a test &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Test calls for example &lt;code&gt;Assert::equals($expected, $actual)&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Assert::equals(...)&lt;/code&gt; throws &lt;code&gt;TestFailedException&lt;/code&gt; containing a formatted error message (possibly with a diff view)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Tester&lt;/code&gt; catches the Exception and creates a &lt;code&gt;TestResult&lt;/code&gt; with the same message&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;TestResult&lt;/code&gt; gets passed to one or more implementation(s) of &lt;code&gt;ITestWriter&lt;/code&gt; (depending on your custom configuration)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TestWriters&lt;/strong&gt; use the formatted error message and re-format it accordingly to be able to output to their according source (console, file, html, etc.)&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;While it works, having an architecture like this introduces many problems to the code: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Essentially, the errors are being formatted twice. Once by the assertion methods and once by the &lt;strong&gt;TestWriters&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Since the diff view gets concatenated to the error message, the &lt;strong&gt;TestWriters&lt;/strong&gt; get it as one string, having to either work with everything as a whole or having to pick apart the string in order to be able to get the diff separately. &lt;/li&gt;
&lt;li&gt;With all the formatting being applied to the string, it's nearly impossible for people that might want to create their own &lt;code&gt;ITestWriter&lt;/code&gt; implementation to predict how the string is going to act in the environment they paste it in.&lt;/li&gt;
&lt;li&gt;It violates the "separation of concerns" principle, since the formatting should only be the concern of the &lt;strong&gt;TestWriters&lt;/strong&gt;. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To give you an idea as to how this bad implementation looked in practice, here is the old &lt;code&gt;Assert::equals(...)&lt;/code&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;equals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;mixed&lt;/span&gt; &lt;span class="nv"&gt;$expected&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;mixed&lt;/span&gt; &lt;span class="nv"&gt;$actual&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$expected&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="nv"&gt;$actual&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nv"&gt;$diff&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Diff&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;generate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ValueExporter&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;export&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$expected&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;ValueExporter&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;export&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$actual&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TestFailedException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="s1"&gt;'The provided two values are not equal'&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="no"&gt;PHP_EOL&lt;/span&gt;
                    &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nc"&gt;ValueExporter&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;export&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$diff&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  The Idea To Solve This
&lt;/h2&gt;

&lt;p&gt;Now, the basic idea to solving all of this was to have the &lt;code&gt;Assert&lt;/code&gt; class and all its methods work with a data only representation of a failed test. Just passing on information from the assertion without worrying about any presentation details. &lt;/p&gt;

&lt;p&gt;The Diff view should be a separate optional thing also not formatted and would be generated by calling &lt;code&gt;Diff::generate(...)&lt;/code&gt; by the assertion methods that need it. &lt;/p&gt;

&lt;p&gt;This way all the formatting is left to the &lt;strong&gt;TestWriters&lt;/strong&gt;, and they get the unformatted Diff and error message separately and can assemble them freely to match their respective output format. &lt;/p&gt;

&lt;p&gt;In this post, I want to walk through what I changed, why I changed it, and the benefits of the refactor.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Implementation
&lt;/h2&gt;

&lt;p&gt;In order to implement this, I introduced the &lt;code&gt;AssertionFailure&lt;/code&gt; class. Which would contain all the necessary information about why the assertion failed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;final&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AssertionFailure&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;__construct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Unknown Assertion Failure'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="kt"&gt;mixed&lt;/span&gt; &lt;span class="nv"&gt;$expected&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="kt"&gt;mixed&lt;/span&gt; &lt;span class="nv"&gt;$actual&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="nc"&gt;Diff&lt;/span&gt; &lt;span class="nv"&gt;$diff&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="kt"&gt;array&lt;/span&gt; &lt;span class="nv"&gt;$metadata&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To the &lt;code&gt;TestFailedException&lt;/code&gt; I added a &lt;code&gt;AssertionFailure $failure&lt;/code&gt; property to hold all relevant information. &lt;/p&gt;

&lt;p&gt;Now the assertion methods just had to throw a &lt;code&gt;TestFailedException&lt;/code&gt; and pass the correct information to an instance of &lt;code&gt;AssertionFailure&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I also removed all formatting logic from the &lt;code&gt;Diff&lt;/code&gt; class and moved it into a &lt;code&gt;DiffFormatter&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;DiffFormatter&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Diff&lt;/span&gt; &lt;span class="nv"&gt;$diff&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$converted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="s1"&gt;'--- Expected'&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="no"&gt;PHP_EOL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;$converted&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'+++ Actual'&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="no"&gt;PHP_EOL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;$converted&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'@@ @@'&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="no"&gt;PHP_EOL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$diff&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;diffLines&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$line&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nv"&gt;$prefix&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;match&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$line&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nc"&gt;DiffLineType&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nc"&gt;Same&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'  '&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="nc"&gt;DiffLineType&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nc"&gt;ExpectedDifferent&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'- '&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="nc"&gt;DiffLineType&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nc"&gt;ActualDifferent&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'+ '&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nv"&gt;$converted&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$prefix&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nf"&gt;rtrim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$line&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"\r\n"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="no"&gt;PHP_EOL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$converted&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="no"&gt;PHP_EOL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I did this because the logic to generate a string representation of a Diff is consistent across all &lt;strong&gt;TestWriters&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Then all there was left to do was to change the &lt;code&gt;ITestWriter&lt;/code&gt; instances to consume the raw data from the &lt;code&gt;AssertionFailure&lt;/code&gt; and assemble/format it correctly, depending on the output type (console, file, html, etc.). &lt;/p&gt;

&lt;p&gt;For comparison here is the &lt;code&gt;Assert::equals(...)&lt;/code&gt; method after the refactoring:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;equals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;mixed&lt;/span&gt; &lt;span class="nv"&gt;$expected&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;mixed&lt;/span&gt; &lt;span class="nv"&gt;$actual&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$expected&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="nv"&gt;$actual&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TestFailedException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;AssertionFailure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                    &lt;span class="s1"&gt;'Expected values to be equal'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="nv"&gt;$expected&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="nv"&gt;$actual&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="nc"&gt;Diff&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;generate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$expected&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$actual&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Key Takeaway
&lt;/h2&gt;

&lt;p&gt;When designing an open-source project, there are always going to be parts of your code that you are going to be unhappy about. &lt;/p&gt;

&lt;p&gt;Especially in the early stages of development where you are mostly working on your own, you sometimes make sacrifices to quality in order to make more progress in the limited time you have. &lt;/p&gt;

&lt;p&gt;While there is nothing wrong about this, it's very important to take the time, revisit these "flaws" and refactor them one by one every once in a while. &lt;/p&gt;

&lt;p&gt;That way, you can maintain a high quality code base while still making steady progress towards finishing the project or implementing new features. &lt;/p&gt;

&lt;p&gt;It's the mix of both refactoring and adding new things that makes the magic ;)&lt;/p&gt;

&lt;p&gt;If you want to see MicroUnit in action, check it out on &lt;a href="https://github.com/mitarnik04/MicroUnit" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Or install it via &lt;strong&gt;Packagist&lt;/strong&gt;: microunit/microunit&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>php</category>
      <category>opensource</category>
      <category>unittest</category>
    </item>
    <item>
      <title>A new PHP8+ Unit Testing Framework called MicroUnit</title>
      <dc:creator>MicroUnit</dc:creator>
      <pubDate>Wed, 17 Dec 2025 00:15:03 +0000</pubDate>
      <link>https://dev.to/micro_unit_php/a-new-php8-unit-testing-framework-called-microunit-1416</link>
      <guid>https://dev.to/micro_unit_php/a-new-php8-unit-testing-framework-called-microunit-1416</guid>
      <description>&lt;p&gt;For a really long time, I was a professional C# developer and as time moved on I fell more and more in love with the language. However, I always loved looking beyond the horizon so to speak and because of that I also dabbled in frontend and became sort of a full stack developer with a backend focus.&lt;/p&gt;

&lt;p&gt;Now a little while ago I decided that I wanted to pick up PHP again since the last time I really used it had been a pretty long while ago.&lt;/p&gt;

&lt;p&gt;I discovered that when it came to Unit Testing, everyone was still relying on pretty much solely PHPUnit. And don't get me wrong, this is a Unit Testing framework that has stood the test of time and still remains one of the best Unit Testing Frameworks for PHP. It has become a staple for a reason and that's why MicroUnit is aiming to be "a fresh modern and different" solution focusing on simplicity, speed, and a zero-dependency philosophy, without sacrificing functionality and &lt;strong&gt;not&lt;/strong&gt; "A competition to PHPUnit".&lt;/p&gt;

&lt;p&gt;So I had a vision, I wanted to create a modern PHP Unit testing framework built from the ground up with PHP 8+ that had a modern bloat free syntax, leveraged the newest features, was insanely fast and built with zero dependencies.&lt;/p&gt;

&lt;p&gt;So I coded everything from scratch, added all the basic features you could ask for, even going so far as to adding build in mocking, set up a GitHub pages documentation site and a great repo with an informative Readme.&lt;/p&gt;

&lt;p&gt;With the project now being on its 6th beta release, I can say I am very proud of what it has become.&lt;/p&gt;

&lt;p&gt;But of course it still has a long way to go and that's where I would really appreciate your help.&lt;/p&gt;

&lt;p&gt;Maybe you could check out the project, try using it for unit testing one of your own projects, or if you feel especially motivated even contribute to it and help me bring this project one step closer to it's first stable release.&lt;/p&gt;

&lt;p&gt;Any help and feedback and/or contribution would be so amazing !&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;GitHub link is below&lt;/strong&gt;, and it is of course also available via &lt;strong&gt;Packagist: microunit/microunit&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/mitarnik04/MicroUnit" rel="noopener noreferrer"&gt;https://github.com/mitarnik04/MicroUnit&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>php</category>
      <category>testing</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
