steos / php-quickcheck Goto Github PK
View Code? Open in Web Editor NEWgenerative testing for PHP
License: BSD 3-Clause "New" or "Revised" License
generative testing for PHP
License: BSD 3-Clause "New" or "Revised" License
I took the liberty of running php-quickcheck through scrutinizer and most of the issues it finds are PSR2 violations.
Would a PR that makes the code PSR-2 compliant be welcomed?
I quickly hacked up this to support testing my class that uses DateTime's extensively.
Could it be of interest to others? The function can of course just be copy-pasted straight into the argument generation, but I figured this might help someone else. If only as an issue that be found through searching.
class GeneratorWithDates extends Gen
{
/**
* Generate DateTime objects
*
* @return Generator
*/
public static function dates($from = 1000, $to = 3000)
{
return self::choose($from, to)->map(
function ($i) {
return new DateTime($i);
}
);
}
}
This will improve shrinking performance for examples like the one given in #14.
See clojure/test.check@1f1e4fc
PHP 7.3 still is actively supported for the next 10 months (https://www.php.net/supported-versions.php).
It would be helpful to have php-quickcheck available for builds using 7.3.
Personally I'm also using php-quickcheck in projects that don't yet support PHP 7.4 (sadly).
I haven't seen any technical reasons why php-quickcheck should not run on 7.3. Or am I overlooking something?
Clojures gen/vector
has multiple arrities:
[generator]
[generator num-elements]
[generator min-elements max-elements]
It's quite handy at times to be able to bound the array, or to have a simple tuple with two identical types. It would be convenient to have this option in steos/quickcheck, too.
It would be lovely to have something like gen/vector-distinct
, only for our trusty PHP arrays.
Since the initial port test.check has changed the RNG from java.util.Random to an immutable version of java.util.SplittableRandom. https://github.com/clojure/test.check/blob/000000076395383d824ec8a468a88ee2baa6f121/src/main/clojure/clojure/test/check/random.clj
Looking through the code, I encountered many static methods. For various reasons (available on request) this is considered a poor practice for anything that is not a factory(ish) function.
What is the rationale behind making so many things static?
Since the initial port test.check has gained a generator for floating point values. It would be great to have this available in PHPQuickCheck as well.
PHP runs out of memory after roughly 30 seconds (during shrinking according to the stacktrace).
The PHP memory_limit
set to 2GB.
Here is a simple test that reliably reproduces the issue on my machine
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use QCheck\Generator as Gen;
use QCheck\Quick;
class QcheckTest extends TestCase
{
public function testStrings(): void
{
$prop = Gen::forAll([Gen::strings()], function ($s): bool {
$this->assertLessThan(100, strlen($s));
return true;
});
$this->assertNotFail(Quick::check(135, $prop, ['echo' => true]));
}
private function assertNotFail(array $result): void
{
if (isset($result['fail'])) {
printf("Tests runs: %d, seed: %s, failing value: \n", $result['num_tests'], $result['seed']);
var_export($result['fail'][0]);
throw $result['result'] instanceof Exception ?
$result['result'] :
new \PHPUnit\Framework\Exception(
sprintf('Property check returned result: "%s"', var_export($result['result'], true))
);
}
}
}
I love clojure.test.check and would love to use PBT in PHP, too. The php-quickcheck API is very nice to use from a developer perspective, but I'm afraid the implementation makes it unusable for practical work. I only took a cursory glance, but from that I guess some of the recursion needs to be replaced with mutating iteration.
Currently I'm using https://github.com/giorgiosironi/eris/ to do PBT, but unfortunately the maintainer isn't responsive. Even though there are issues with Eris, too, it at least allows me to use it during work.
I would very much like to be able to use php-quickcheck, since the API matches what I'm use to from clojure.test.check more closely.
OOM is reached after roughly 30 seconds.
I am running php with -dxdebug.max_nesting_level=9999
, otherwise the stack is blown quickly.
PHP Versions: 7.3.8, 7.2.21 and 7.1.26.
Machine: 2.2GHz Intel i7 MBP, 32GB RAM.
I found this repository as I was fiddling around with the idea of creating a similar library and I was wondering whether this repository is still considered to be alive and if not, what considerations led to its discontinued development? I read some remarks about interoperability issues with PHPUnit but couldn't quite make out if that was the main problem.
Anyway, I hope to see this kind of testing framework be more prevalent in the php world so any response would be appreciated!
Why would you have the 7.3
as min requirement in the composer.json
but 7.4
in the Dev Setup?
composer.json
to require the >=7.4
version?Otherwise, I would downgrade the dev setup Dockerfile to use the php:7.3
.
I say this because I believe it's better to develop something using the same tool-versions as the real/end environment where it's going to be used.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.