steos/quickcheck
Composer 安装命令:
composer require steos/quickcheck
包简介
a generative testing library
README 文档
README
PHPQuickCheck is a generative testing library for PHP based on clojure.test.check.
Don't write tests. Generate them. - John Hughes
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.
Quickstart
Install PHPQuickCheck:
composer require steos/quickcheck --dev
Create a property test test/stringsAreNeverNumeric.php:
<?php use QuickCheck\Generator as Gen; use QuickCheck\Test; Test::forAll( [Gen::asciiStrings()], function($str) { return !is_numeric($str); } );
And run quickcheck against it:
$> 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:
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.
Performance
-
Disable xdebug to get tests to run faster. It has a huge impact on the runtime performance.
-
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.
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.
Contributing
All contributions are welcome.
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.
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.
$ 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:
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.
Requirements
Requires PHP 7.3.x with 64 bit integers. The gmp extension is recommended but not required.
License
Copyright © 2022, Stefan Oestreicher and contributors.
Distributed under the terms of the BSD (3-Clause) license.
steos/quickcheck 适用场景与选型建议
steos/quickcheck 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 23.3k 次下载、GitHub Stars 达 191, 最近一次更新时间为 2020 年 01 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 steos/quickcheck 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 steos/quickcheck 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 23.3k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 192
- 点击次数: 11
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2020-01-09