100% line coverage did not catch the one bug that mattered
Symfony shipped a TUI component in 8.1 — a widget tree, a layout engine and a renderer for building full-screen terminal applications in PHP. One thing up front, because someone will ask: php-tui/php-tui has been around much longer, it is mature, and it has around ninety times the downloads on Packagist. I picked symfony/tui because the project was already on Symfony and pulling in a second…
Symfony released a Terminal User Interface (TUI) component in version 8.1, providing a widget tree, layout engine, and renderer for creating full-screen terminal applications in PHP. The author decided to build a scrollable, sortable, and filterable table using this component. After writing 92 tests and achieving full line coverage of the widget code, the author was confident in the component's reliability.
However, upon integrating the widget into a real command in one of their own projects, they discovered that the header of the table was not being displayed correctly. The issue arose because the widget did not read the terminal's height correctly, resulting in the header being pushed out of view. This bug was not caught by the extensive test suite, as the tests were written based on the author's assumptions about the widget's behavior rather than testing the actual contract.
Through testing the widget in a real application, the author uncovered additional issues with the API. For example, hard-coded English strings were displayed in a Russian interface, paging behavior was inconsistent depending on the terminal size, and the widget required manual mapping of column keys to headers for status lines. These problems were not defects in the code itself but rather in the design and API of the TUI component, which the tests were not designed to catch.
Furthermore, the author found that the component leaked frames when exiting, and a pseudo-terminal with an unset window size caused the component to produce an uncaught exception and exit with an error code. Both of these issues were addressed and merged into the 8.1 release of Symfony.
The author's experience highlights the importance of using the technology in real-world scenarios rather than solely relying on tests. Writing comprehensive tests is essential, but they only cover the aspects that have been explicitly modeled and tested. By interacting with the software and observing its behavior in actual use, developers can uncover bugs and issues that tests alone may not reveal.
The author emphasizes the value of dogfooding - using the software in production-like environments to identify and fix problems.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.