<?php

require __DIR__ . '/../vendor/autoload.php';
use FUnit as fu;
use Knlv\Zf2\Validator\NotIdentical;
fu::setup(function () {
    $validator = new NotIdentical();
    fu::fixture('validator', $validator);
});
fu::test('Test not_identical validates correctly', function () {
    $validator = fu::fixture('validator');
    $validator->setToken('token');
    fu::not_ok($validator->isValid('value', array('token' => 'value')), 'Assert validator returns false on same');
    fu::ok($validator->isValid('value', array('token' => 'other')), 'Assert validator retuns true on different');
    fu::ok($validator->isValid('value'), 'Assert validator returns true if no context provided');
    fu::ok($validator->isValid('value', array('other_token' => 'value')), 'Assert validator returns true if token not found in context');
    $validator->setToken(null);
    fu::not_ok($validator->isValid('value', array('token' => 'value')), 'Assert validator return false if no token is set');
});
fu::test('Test not_identical messages', function () {
    $validator = fu::fixture('validator');
    $validator->setToken('token');
    $validator->isValid('value', array('token' => 'value'));
    fu::has($validator::SAME, $validator->getMessages(), 'Assert same message');
    $validator->isValid('value', array('token' => 'other'));
    $messages = $validator->getMessages();
    fu::ok(empty($messages), 'Assert empty messages if validator validates');
    $validator->setToken(null);
    $validator->isValid('value', array('token' => 'value'));
    fu::has($validator::MISSING_TOKEN, $validator->getMessages(), 'Assert missing token message');
});
Example #2
0
fu::test("this is a test", function () {
    fu::ok(1, "the integer '1' is okay");
    fu::ok(0, "the integer '0' is not okay");
    // this will fail!
});
fu::test("another test", function () {
    fu::equal(true, 1, "the integer '1' is truthy");
    fu::not_strict_equal(true, 1, "the integer '1' is NOT true");
    // access a fixture
    $foobar = fu::fixture('foobar');
    fu::equal($foobar['foo'], 'bar', "the fixture 'foobar' should have a key 'foo' equal to 'baz'");
    $fooarr = array('blam' => 'blaz');
    fu::has('blam', $fooarr, "\$fooarr has a key named 'blam'");
    $fooobj = new \StdClass();
    $fooobj->blam = 'blaz';
    fu::has('blam', $fooobj, "\$fooobj has a property named 'blam'");
});
fu::test('Checking for exceptions', function () {
    $callback = function () {
        throw new RuntimeException();
    };
    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 () {