data-provider / example
An example of the DataProvider in PHP Unit.
0.0.2
2015-07-17 10:26 UTC
Requires (Dev)
- phpunit/phpunit: 4.7.*
This package is not auto-updated.
Last update: 2024-10-26 16:47:03 UTC
README
Build
Code Quality
Code Style
Description
This is a simple example of using data provider in PHP Unit. It can be used to write less test with multiple data sets keeping the code coverage high.
/** * Data provider for testCalculateTotal * variables are in the order of * $paymentMethod, $expectedTotal * * @return type */ public function paymentMethodProvider() { return [ ['Cash', 100.00], ['Credit Card', 95.00], ]; } /** * Test to check if the order total is calculated correctly * for given payment method. * * @param string $paymentMethod * @param float $expectedTotal * * @dataProvider paymentMethodProvider */ public function testCalculateTotal($paymentMethod, $expectedTotal) { $this->checkout->calculateTotal($paymentMethod); $this->assertEquals( $this->checkout->getTotal(), $expectedTotal, sprintf('Testing total calculation for %s.', $paymentMethod) ); }
The description of how use data provider in PHP Unit is provided in my blog post.
Tests
You can run composer update
~> composer update --prefer-dist
and then run the tests using the command below on folder where the repo is cloned.
phpunit --bootstrap=vendor/autoload.php tests
Available in packagist
The package is availabe in packagist. You can use it for reference by adding the followign line to you composer.json file
"data-provider/example" : "0.0.2",
What Next?
Issues are put in HuBorad, do have a look.
Contribution Guide
This is just an example