Esempio n. 1
0
});
$tests->claim('$tests->clear should work', function () use($testTests) {
    $testTests->claim('fail', function () {
        return false;
    });
    $testTests->clear()->check();
    return $testTests->getRaw('nogroup') === array();
});
$tests->claim('$tests->reps should work', function ($reps) use($testTests) {
    $i = 0;
    $testTests->reps($reps);
    $testTests->test('reps', function () use(&$i) {
        $i++;
    });
    return $i === $reps;
}, array(PHPCheck::Integer(1, 10)));
$tests->claim('Failed claims should be failed', function () use($testTests) {
    $testTests->claim('fail', function () {
        return false;
    });
    $testTests->check();
    return $testTests->getRaw('nogroup') === array(array('fail', false));
});
$tests->claim('Missing claims should be missed', function () use($testTests) {
    $testTests->claim('missing', function () {
    });
    return $testTests->getRaw('nogroup') === array(array('missing', null));
});
$tests->claim('Groups should work', function () use($testTests) {
    $testTests->group('Test group');
    $testTests->claim('missing', function () {
Esempio n. 2
0
<?php

include '../src/PHPCheck.php';
$tests = new PHPCheck();
$testTests = new PHPCheck();
$tests->setup(function () use($testTests) {
    $testTests->clear();
});
$handle = opendir('./');
while ($file = readdir($handle)) {
    if (preg_match('/^tests\\_[a-z]+\\.php$/', $file)) {
        include $file;
    }
}
echo $tests->check()->getHTML();
Esempio n. 3
0
    }
    return true;
}, array(PHPCheck::OneOf(array(function () use($OO_a) {
    $OO_a++;
    return 'a';
}, function () use($OO_b) {
    $OO_b++;
    return 'b';
}))));
$tests->claim('OneOf specifier (string)', function ($c, $d) {
    return strlen($c) === 1 && $c > 'b' && $c < 'h' && $d === 'a';
}, array(PHPCheck::OneOf('cdefg'), PHPCheck::OneOf('a')));
$tests->claim('SpecArray specifier', function ($ary) {
    if (!is_int($ary[0]) || !is_int($ary[1])) {
        return false;
    }
    return $ary[0] < $ary[1];
}, array(PHPCheck::SpecArray(array(PHPCheck::Integer(2), PHPCheck::Integer(3, 5)))));
$tests->claim('SpecArray specifier 2 (with keys)', function ($ary) {
    if (!is_int($ary['foo']) || !is_int($ary['bar'])) {
        return false;
    }
    return $ary['foo'] < $ary['bar'];
}, array(PHPCheck::SpecArray(array('foo' => PHPCheck::Integer(2), 'bar' => PHPCheck::Integer(3, 5)))));
$tests->claim('String specifier (simple value)', function ($a, $b, $c) {
    return $a === '23' && ($b === '5' || $b === '6') && $c === '["a","b"]';
}, array(PHPCheck::String(23), PHPCheck::String(PHPCheck::Integer(5, 6)), PHPCheck::String(array('a', 'b'))));
$tests->claim('String specifier (num values)', function ($a, $b) {
    return $a === 'aaa' && ($b === 'aa' || $b === 'aaa');
}, array(PHPCheck::String(3, PHPCheck::OneOf('a')), PHPCheck::String(PHPCheck::Integer(2, 3), 'a')));
 /**
  * Returns a stringified value, using json_encode.
  *
  * @param mixed $value Value to stringify.
  */
 public static function String($num, $value = false)
 {
     if ($value) {
         $num = PHPCheck::evalSpecifier($num);
         return function () use($num, $value) {
             $string = '';
             for ($i = 0; $i < $num; $i++) {
                 $string .= PHPCheck::evalSpecifier($value);
             }
             return $string;
         };
     } else {
         $value = $num;
         return function () use($value) {
             return json_encode(PHPCheck::evalSpecifier($value));
         };
     }
 }