Пример #1
0
}
class AlwaysValidRule extends Rule
{
    public function condition($value)
    {
        return true;
    }
}
$tf = new Testify('Flute Tests');
$tf->test('Parameter-less Rule', function ($tf) {
    $obj = new TestObject();
    $obj->name = 'Test Object';
    $validator = new Validator();
    $validator->rule_for('name')->always_valid();
    $result = $validator->validate($obj);
    $tf->assert($result->valid(), 'Object should be valid');
});
$tf->test('Rule for multiple fields', function ($tf) {
    $validator = new Validator();
    $validator->rule_for('first_name')->and_for('last_name')->not_empty();
    $obj = new TestObject();
    $obj->first_name = '';
    $obj->last_name = 'Valid name';
    $tf->assertFalse($validator->validate($obj)->valid(), 'One property is invalid');
    $obj->first_name = 'Valid name';
    $tf->assert($validator->validate($obj)->valid(), 'All properties are valid.');
});
$tf->test('Parameter rule', function ($tf) {
    $validator = new Validator();
    $validator->rule_for('name')->max_length(10);
    $obj = new TestObject();
Пример #2
0
<?php

/*
 * This is a minimal example of Testify
 * 
 */
require '../testify/testify.class.php';
$tf = new Testify("A basic test suite.");
// Add a test case
$tf->test("Just testing around", function ($tf) {
    $tf->assert(true);
    $tf->assertFalse(false);
    $tf->assertEqual(1, '1');
    $tf->assertIdentical(1, 1);
    $tf->assertInArray('a', array(1, 2, 3, 4, 5, 'a'));
    $tf->pass();
});
$tf->test("I've got a bad feeling about this one", function ($tf) {
    $tf->assert(false);
    $tf->assertFalse(true);
    $tf->assertEqual(1, '-21');
    $tf->assertIdentical(1, '1');
    $tf->assertInArray('b', array(1, 2, 3, 4, 5, 'a'));
    $tf->fail();
});
$tf->run();