php-quickcheck
php-quickcheck copied to clipboard
Add a helper to user generators as PHPUnit data providers
Using this, you can easily use generators as providers like it is done in the tests :
function provider($name, $n = 10) {
return DataProvider::provider(array(
Generator::strings(),
Generator::ints(),
Generator::booleans()
), $n);
}
/**
* @dataProvider provider
*/
function testDataProvider($s, $i, $b) {
// this test is only supposed to prove that we have a valid provider
$this->assertTrue(is_string($s));
$this->assertTrue(is_int($i));
$this->assertTrue(is_bool($b));
}
I'd love to have this, but in my experiments with PHPUnit integration it seemed to run all the data providers up front before executing any tests, so startup became very slow and memory usage can get out of hand quickly. I'm afraid for this to be useful in the real world it would require some changes to PHPUnit or a custom TestCase implementation.
You're right, according to https://github.com/sebastianbergmann/phpunit/blob/master/src/Framework/TestSuite.php#L569 the full test suites including the data are built before they are run.
I'll think about all that a bit to see if something could be made. Probably adding the possibility to do lazy test data evaluation in PHPUnit would be a great thing now that people use Generators more and more.
Yeah, I'd really like to have some structured way of organizing properties and tests and running whole suites of them. My first idea was of course to integrate with PHPUnit. Unfortunately it doesn't seem to be modular enough to do so without significant work.
My first goal however is a way to describe stateful systems based on John Hughes presentation of Erlang QuickCheck in his talk "Testing the Hard Stuff and Staying Sane". I have a working prototype in Clojure using clojure.test.check but it's still a little rough around the edges and I haven't yet tried it on real-world examples. Once I'm satisfied that it works well enough I definitely want to implement it in PHP as well.
So if you want to look into PHPUnit integration or work on some other way to organize tests etc. that would be great.
this looks very cool, any progress here?
Not with regards to PHPUnit integration. I did some prototyping for a standalone test runner but I've been busy with other things so nothing to show yet.