Beispiel #1
0
<?php

/*
 * A more complex example using beforeEach and data
 * 
 */
require '../testify/testify.class.php';
$tf = new Testify("A bit more advanced test suite");
// Before each is called before every test case
$tf->beforeEach(function ($tf) {
    // Use the data property to share variables across tests
    $tf->data->arr = array('a', 'b', 'c', 'd', 'e', 'f');
});
$tf->test("Testing Array Pop", function ($tf) {
    $arr =& $tf->data->arr;
    $tf->assertEqual(array_pop($arr), 'f');
    $tf->assertEqual(array_pop($arr), 'e');
    $tf->assertEqual(array_pop($arr), 'd');
    $tf->assertEqual(array_pop($arr), 'c');
});
$tf->test("Testing In Array", function ($tf) {
    // beforeEach has restored the array
    $arr =& $tf->data->arr;
    $tf->assertInArray('a', $arr);
    $tf->assertInArray('b', $arr);
    $tf->assertInArray('c', $arr);
    $tf->assertInArray('d', $arr);
    $tf->assertInArray('e', $arr);
    $tf->assertInArray('f', $arr);
    $tf->assertNotInArray('g', $arr);
});
Beispiel #2
0
require '../src/flute.php';
class TestObject
{
    public function __call($name, $args)
    {
        return $this->{$name};
    }
}
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');
Beispiel #3
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();