2017 © Pedro Peláez
 

library php-quickcheck

a generative testing library

image

steos/php-quickcheck

a generative testing library

  • Tuesday, March 15, 2016
  • by steos
  • Repository
  • 14 Watchers
  • 123 Stars
  • 1,496 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 7 Forks
  • 1 Open issues
  • 1 Versions
  • 58 % Grown

The README.md

PHPQuickCheck

PHPQuickCheck is a generative testing library for PHP based on clojure.test.check., (*1)

Don't write tests. Generate them. - John Hughes, (*2)

Huh?

Generative testing, also called property-based testing, is about describing the behaviour of your system in terms of properties that should hold true for all possible input., (*3)

Quickstart

Install PHPQuickCheck:, (*4)

composer require steos/quickcheck --dev

Create a property test test/stringsAreNeverNumeric.php:, (*5)

<?php
use QuickCheck\Generator as Gen;
use QuickCheck\Test;

Test::forAll(
    [Gen::asciiStrings()],
    function($str) {
        return !is_numeric($str);
    }
);

And run quickcheck against it:, (*6)

$> vendor/bin/quickcheck test/stringsAreNeverNumeric.php -t 1000
PHPQuickCheck 2.0.2. Don't write tests. Generate them.

  834/1000 [=========================================>--------]  83%

Time: 454 ms, Memory: 4.00 MB, Seed: 1578763578270, maxSize: 200

Failing inputs: array (
  0 => '9E70',
)

Shrinking inputs...done. (0.00 s)
Smallest failing inputs: array (
  0 => '0',
)

QED. (834 tests)

Documentation

API

Other Resources

xdebug

PHPQuickCheck uses a lot of functional programming techniques which leads to a lot of nested functions. With xdebug default settings it can quickly lead to this error:, (*7)

Error: Maximum function nesting level of '256' reached, aborting!

This happens due to the infinite recursion protection setting xdebug.max_nesting_level. Best is to disable this or set it to a high value. The phpunit config sets it to 9999., (*8)

Performance

  • Disable xdebug to get tests to run faster. It has a huge impact on the runtime performance., (*9)

  • Use the GMP extension. The RNG will use the gmp functions if available. Otherwise it falls back to very slow bit-fiddling in php userland., (*10)

Project Status

PHPQuickCheck is somewhat experimental. The core functionality of clojure.test.check (v0.5.9, August 2014) has been implemented. There have been a number of improvements to clojure.test.check since the initial port which have not been implemented yet., (*11)

Contributing

All contributions are welcome., (*12)

Feel free to fork and send a pull request. If you intend to make major changes please get in touch so we can coordinate our efforts., (*13)

Dev Setup

The repository contains a Dockerfile to quickly set up a dev environment. It is based on the php:7.3.18-cli image and adds xdebug, gmp and composer., (*14)

$ docker build -t php-quickcheck-dev dev-env
$ docker run --rm -it --mount src=$(pwd),target=/quickcheck,type=bind php-quickcheck-dev bash
# cd /quickcheck
# composer install
# vendor/bin/phpunit
# bin/quickcheck examples

The image also contains a small script toggle-ext to toggle php extensions on and off:, (*15)

root@c871096e2c92:/quickcheck# toggle-ext xdebug
xdebug is now disabled
root@c871096e2c92:/quickcheck#

Credits

All credit goes to clojure.test.check, this project is mostly just a port., (*16)

Requirements

Requires PHP 7.3.x with 64 bit integers. The gmp extension is recommended but not required., (*17)

License

Copyright © 2022, Stefan Oestreicher and contributors., (*18)

Distributed under the terms of the BSD (3-Clause) license., (*19)

The Versions

15/03 2016

dev-master

9999999-dev

a generative testing library

  Sources   Download

BSD-3-Clause

The Requires

  • php-64bit >=5.5.0

 

The Development Requires