I have test suites with lots of tests in them. here is a medium sized one:
ok 4 - CommodityBasketTest::testStartsOutEmpty
ok 5 - CommodityBasketTest::testCanAddACommodity
ok 6 - CommodityBasketTest::testWillAddOneCommodityByDefault
ok 7 - CommodityBasketTest::testCannotAddACommodityWithAnNonNumericQuantity
ok 8 - CommodityBasketTest::testAddingTheSameCommodityWillIncreaseItsQuantity
ok 9 - CommodityBasketTest::testMultipleCommodityCanBeAdded
ok 10 - CommodityBasketTest::testTakingFromAnEmptyBasketWontWork
ok 11 - CommodityBasketTest::testTakesFirstCommodityFromTheBasket
ok 12 - CommodityBasketTest::testCanRetrieveASpecificCommodity
ok 13 - CommodityBasketTest::testWillThrowExceptionOnMissingCommodity
ok 14 - CommodityBasketTest::testReturnsZeroWorthForEmptyBaskets
ok 15 - CommodityBasketTest::testReturnsProperWorthOfACommodity
ok 16 - CommodityBasketTest::testWillAccuratelyReturnStatistics
How can I rig PHPUnit so that I can somehow display the underlying method being tested like I have it in the paste?? I’m flexible on output; I’d just like to know that CommodityBasketTest::testReturnsZeroWorthForEmptyBaskets tests CommodityBasket::getValuation(), for instance.
This is what I’d like:
-- CommodityBasket::__construct() --
ok 4 - CommodityBasketTest::testStartsOutEmpty
-- CommodityBasket::add() --
ok 5 - CommodityBasketTest::testCanAddACommodity
ok 6 - CommodityBasketTest::testWillAddOneCommodityByDefault
ok 7 - CommodityBasketTest::testCannotAddACommodityWithAnNonNumericQuantity
ok 8 - CommodityBasketTest::testAddingTheSameCommodityWillIncreaseItsQuantity
ok 9 - CommodityBasketTest::testMultipleCommodityCanBeAdded
-- CommodityBasket::take() --
ok 10 - CommodityBasketTest::testTakingFromAnEmptyBasketWontWork
ok 11 - CommodityBasketTest::testTakesFirstCommodityFromTheBasket
ok 12 - CommodityBasketTest::testCanRetrieveASpecificCommodity
ok 13 - CommodityBasketTest::testWillThrowExceptionOnMissingCommodity
-- CommodityBasket::getValuation() --
ok 14 - CommodityBasketTest::testReturnsZeroWorthForEmptyBaskets
ok 15 - CommodityBasketTest::testReturnsProperWorthOfACommodity
-- CommodityBasket::dumpStats() --
ok 16 - CommodityBasketTest::testWillAccuratelyReturnStatistics
Thank you for your suggestions.
My approach would be a combination of the
@coversTag and a custom result printer.You should use the @covers tag anyways to generate more meaningful code coverage, especially in bigger test suites it is important to make sure that only the tests that are supposed to test a method really generate coverage for it.
I know your question isn’t related to coverage but we’ll get to that in a minute. And maybe just using that annotation is enough for you as every method that doesn’t have a test dedicated to it will show 0% coverage no matter if you run all your integration tests and so forth.
A custom result listener to collect the information you want
The implementation can surly be tuned, i just wanted to produce something that works reasonably well to show of the concept and hopefully give you something you can adapt.
The code is alpha as I’ve written it only for that question but it works with the current phpunit and I think i pasted everything you need.
The result:
I hope this matches your desired output. The formatting can be changed rather easily in the code below.
It prints this piece of information for every class you have a test for (an empty one is enough!)
If one tests @covers multiple methods it will show up for EVERY ONE of those methods
The class under Test
The Testcase
The phpunit.xml you need to register the test listener!
The Result Printer