PHPUnit: Guides and Practical Know-how | Page 9 | mironsoft Blog
PHPUnit
-
Mar 31, 2025
GraphQL APIs without systematic tests are fragile: every schema change can silently break frontends. Query tests, snapshots, and contract tests together form a testing layer that catches regressions early and keeps frontend contracts stable over the long run.
-
Mar 28, 2025
The most common misallocation in test automation: too many slow end-to-end tests and too few fast unit tests. The test pyramid provides the right weighting, three levels with clearly separated responsibilities that together form a reliable test strategy.
-
Mar 20, 2025
Anyone who tests HTTP clients only with real API calls ends up with slow, fragile tests that turn red the moment the network hiccups. Guzzle's MockHandler, response stacks and custom HTTP adapters give you full control over every response scenario, success, timeout, server outage and retry cascade, directly inside PHPUnit, deterministic and fast.
-
Mar 19, 2025
Tests that depend on the current time, randomly generated UUIDs, or pseudo-random values are flaky: they sometimes fail and sometimes don't, and the cause is hard to reproduce. Clock interfaces, UUID factories, and controlled randomness solve this problem at its root, without complicating the production code.
-
Mar 15, 2025
Anyone developing PHP inside Docker containers but still wanting to run tests directly from the IDE faces a configuration challenge: PhpStorm needs to know which PHP interpreter lives in the container, how Xdebug can be reached, and how paths are mapped between host and container. This article shows the full path.
-
Mar 13, 2025
Adminhtml controllers bundle access control, form processing, and redirect logic in one place, which is why unit and integration tests need to complement each other to cover both the pure logic and the interplay with the Magento backend stack.
-
Feb 25, 2025
Example-based tests only check the cases a developer happened to think of. Property-based testing flips the approach around: instead of concrete inputs, you formulate invariants, properties that must hold for every conceivable input, and let the library search for thousands of random counterexamples.
-
Feb 17, 2025
Vulnerabilities in production dependencies tend to get taken seriously, while test and dev dependencies like PHPUnit plugins or coverage tools are often ignored. Yet exactly these packages run with full privileges in the CI/CD pipeline and form a real entry point for supply chain attacks, one composer audit can uncover deliberately.
-
Feb 10, 2025
Mocking everything a class touches, indiscriminately, produces unit tests that break on every refactor even though the application's behavior never changed. Gerard Meszaros' taxonomy distinguishes dummy, stub, fake, spy and mock as five clearly separated roles, each with a different purpose, a different verification logic and a different degree of coupling to implementation details. This article walks through the theory behind every test double using hand-written PHP implementations, independent of any particular testing framework.
-
Feb 9, 2025
Duplicated test data in every setUp, magic arrays in DataProviders, and hardcoded IDs scattered across hundreds of test classes. These are the typical signs of a test suite without a clear data organization strategy. The Builder pattern, fixture classes and factory methods bring order without overengineering.