require __DIR__ . '/../vendor/autoload.php';
use FUnit as fu;
use Knlv\Zf2\Validator\VatNumber;
fu::test('Test getValidator returns default composed validator', function () {
    $validator = new VatNumber();
    fu::ok($validator->getValidator() instanceof Ddeboer\Vatin\Validator);
});
fu::test('Test options are set', function () {
    $validator = new VatNumber(array('country' => 'EL', 'checkExistence' => false));
    fu::equal('EL', $validator->getCountry());
    fu::equal(false, $validator->getCheckExistence());
});
fu::test('Test throws exception on invalid country', function () {
    fu::throws(function () {
        $validator = new VatNumber(array('country' => 'GR'));
    }, array(), 'Zend\\Validator\\Exception\\InvalidArgumentException');
});
fu::test('Test validates same as composed validator', function () {
    $data = array(array(false, 'EL', '123456789', true), array(false, 'BE', '0123456789', true), array(true, 'NL', '987654321B01', false), array(true, 'NL', '7654321B01', false), array(true, 'BE', '01234567', false));
    $validator = new VatNumber();
    fu::all_ok($data, function ($values) use($validator) {
        $validator->setCheckExistence($values[0]);
        $validator->setCountry($values[1]);
        return $validator->isValid($values[2]) === $values[3];
    });
});
fu::test('Test messages', function () {
    $validator = new VatNumber();
    $validator->isValid("EL123456789");
    fu::equal($validator->getMessages(), array('vatInvalid' => 'The VAT is invalid'));
});
Example #2
0
    };
    fu::throws($callback, 'RuntimeException', 'Correct exception');
    $callback = function ($foo) {
        throw new RuntimeException($foo);
    };
    fu::throws($callback, array('bar'), 'LogicException', 'Not the correct exception');
});
fu::test('Forced failure', function () {
    fu::fail('This is a forced fail');
});
fu::test('Expected failure', function () {
    fu::expect_fail('This is a good place to describe a missing test');
});
fu::test('Forced Errors/Exception', function () {
    trigger_error('This was triggered inside a test', E_USER_ERROR);
    trigger_error('This was triggered inside a test', E_USER_NOTICE);
    throw new Exception('This was thrown inside a test');
});
fu::test('Checking iterables with all_ok', function () {
    $ints = array(1, 2, 3, 4, 5);
    fu::all_ok($ints, 'is_int', "\$ints are all integers");
    $ints = array(1, 2, 3, "four", 5);
    fu::all_ok($ints, 'is_int', "\$ints are all integers");
    $evens = array('a' => 2, 'b' => 42, 'c' => 68, 'd' => 800);
    $evens_ao = new ArrayObject($evens);
    fu::all_ok($evens_ao, function ($val) {
        return $val % 2 === 0;
    }, "\$evens_ao are all even");
});
$exit = fu::run();
exit($exit);