Quality and maintenance · Question 10 of 12

A unit test should check a price calculation with several inputs. How do you provide the data in PHPUnit 13?

1 answer is correct. Medium

Show answer

Answer

  • B With the attribute #[DataProvider('priceProvider')] on the test and a public static function priceProvider() that returns the data sets

Explanation

Since PHPUnit 12, PHPUnit only reads attributes, and annotations in the DocBlock are ignored. The provider must be public and static, each data set is run as a separate test, and named keys appear in the output. A loop in one test stops at the first failure and does not show which other inputs fail as well.

Certifications & exams

Which exam comes next?

You can already practise for 19 exams, and 21 are up for a vote. See all certifications with their official information, cast your vote or suggest your exam.

See all certifications