Skip to content

Provide simple PHPUnit constraint #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 8, 2020
Merged

Provide simple PHPUnit constraint #15

merged 2 commits into from
Jan 8, 2020

Conversation

Vinai
Copy link
Contributor

@Vinai Vinai commented Jan 8, 2020

This is a simple PHPUnit integration for php-quickcheck.
It consists of a custom assertion and a static factory method.

To use this in a PHPUnit test, call

$this->assertThat(Gen::forAll($generators, $prop), Prop::check(100));

The output of a failing test looks like:

Failed asserting that property is true.
Tests runs: 16, failing size: 15, seed: 1578486446175, smallest shrunk value(s):
array (
  0 => <failed shrunk value>,
)

The smallest shrunk value is displayed using var_export so it can be copied and pasted into the property Closure for easy debugging.

Please consider the constraint class name and the factory method name as a suggestion - happy to rename them to something better.

Due to the method signatures of the overridden methods from PHPUnit\Framework\Constraint\Constraint, the constraint class is only PHP 7 compatible.
It would be possible to provide alternative implementations of the custom assertion for ancient PHPUnit versions that are compatible with PHP 5.6, but I doubt it is worth the effort.

@Vinai
Copy link
Contributor Author

Vinai commented Jan 8, 2020

This PR is a more lightweight alternative to #7. I would like to think it behaves a bit like the defspec macro from clojure.test.check.
It should also work well in conjunction with #7 actually.

@Vinai Vinai changed the title Provide simple PHPUnit integration Provide simple PHPUnit constraint Jan 8, 2020
@Vinai Vinai force-pushed the phpunit branch 4 times, most recently from 6a25f72 to e5fddb0 Compare January 8, 2020 17:17
@Vinai
Copy link
Contributor Author

Vinai commented Jan 8, 2020

Sorry about all the updates, sitting in a train trying to find better names.

This is a simple PHPUnit integration for php-quickcheck.
It consists of a custom assertion and a static factory method.

To use this in a PHPUnit test, call

$this->assertThat(Gen::forAll($generators, $property), Prop::check(10));
@steos
Copy link
Owner

steos commented Jan 8, 2020

This seems great, thank you very much!
Let me know if I can merge it or if you still want to make some changes here.

@Vinai
Copy link
Contributor Author

Vinai commented Jan 8, 2020

I'm good with the current shape.

@Vinai
Copy link
Contributor Author

Vinai commented Jan 8, 2020

Well, I can add a blurb to the readme maybe.

@Vinai
Copy link
Contributor Author

Vinai commented Jan 8, 2020

Now I think I'm okay with the PR, so if you are happy with it, too, it's ready to be merged.

@Vinai
Copy link
Contributor Author

Vinai commented Jan 8, 2020

Since the README can't be the cause, maybe some changes you made while adding dontShrink broke the PHP 5 builds?

@steos
Copy link
Owner

steos commented Jan 8, 2020

It's all good. Looks like there was some temporary error with composer install and the random shrink test sometimes doesn't generate a failing case.

Thanks again for your efforts!

@steos steos merged commit 68bb65e into steos:master Jan 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants