For years, the test framework EcomDev_PHPUnit is quasi-standard for Magento unit tests. The current version is 0.3.7 and last state of official documentation is version 0.2.0 – since then, much has changed which you have to search yourself in code and GitHub issues. This series shall collect practical usage tips.
Tip #2: Expectation Keys
This is a short one: expected('works %s sprintf', 'like')
.
Which expectations should be loaded, usually depends on input data, so if your expectation file looks like this:
- product-1-qty-10: - answer: 42 - product-2-qty-10: - answer: 42
you can load it in the test like this:
/** * @test * @loadExpectation * @loadFixture * @dataProvider dataProvider */ public function testSomething($productId, $qty) { $expectedAnswer = $this->expected('product-%s-qty-%s', $productId, $qty); }