Exemplo n.º 1
0
assert_equals($simpleStruct->f, null);
$simpleJson3 = "{\n}";
$simpleStruct = new mySimpleStruct(array());
test_exception($simpleStruct, $simpleJson3);
/**
 * Test String (empty, null, and normal)
 */
$strJson1 = "{\n  \"a\": \"\"\n}";
$stringStruct->readFromJson($strJson1);
assert_equals($stringStruct->a, "");
$strJson2 = "{\n}";
$stringStruct->readFromJson($strJson2);
assert_equals($stringStruct->a, null);
$strJson3 = "{\n  \"a\": \"foobar\"\n}";
$stringStruct->readFromJson($strJson3);
assert_equals($stringStruct->a, "foobar");
/**
 * Integration Test
 * This config file is from configerator/materialize_configs/ffuuu
 * It should not product any exceptions
 */
try {
    $config = new Config(array());
    $config->readFromJson(file_get_contents($HERE . '/config.json'));
} catch (Exception $e) {
    print_r($e);
    fail("Fail intregation test!");
}
/**
 * Test invalid JSON string
 */
Exemplo n.º 2
0
assert_equals(0, $r->im_optional);
assert_equals(0, $w->im_default);
write_to_read($r, $w);
assert_equals(0, $r->im_optional);
assert_equals(0, $w->im_default);
// Default <-> Required
$w = new Tricky1();
$r = new Tricky3();
$w->im_default = 0;
$r->im_required = 10;
write_to_read($w, $r);
assert_equals(0, $r->im_required);
assert_equals(0, $w->im_default);
write_to_read($r, $w);
assert_equals(0, $r->im_required);
assert_equals(0, $w->im_default);
echo "Tests passed!\n";
function write_to_read($write_struct, $read_struct)
{
    $protocol = new TBinaryProtocol(new TMemoryBuffer());
    $write_struct->write($protocol);
    $read_struct->read($protocol);
}
function assert_true($bool)
{
    if (!$bool) {
        throw new Exception("Assertion is false");
    }
}
function assert_equals($expected, $actual)
{
Exemplo n.º 3
0
    } else {
        println('Passed!');
    }
}
function assert_url($is)
{
    if (!preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $is)) {
        exit(1);
    } else {
        println('Passed!');
    }
}
function println($text)
{
    echo $text . "\n";
}
require 'Googl.class.php';
#
# IMPORTANT: Please add your API key to make the tests work
#
$googl = new Googl('YOUR_API_KEY');
println('#1 - Assert that shortening http://www.google.ch results in an URL');
assert_url($googl->shorten('http://www.google.ch'));
println('#2 - Assert that expanding http://goo.gl/KSggQ resolves to http://www.google.com/');
assert_equals($googl->expand('http://goo.gl/KSggQ'), 'http://www.google.com/');
println('#3 - Assert that shortening https://www.facebook.com results in an URL');
assert_url($googl->shorten('https://www.facebook.com'));
println('#4 - Assert that expanding http://goo.gl/wCWWd resolves to http://www.php.net/');
assert_equals($googl->expand('http://goo.gl/wCWWd'), 'http://www.php.net/');
# If this point is reached, all tests have passed
println('All tests have successfully passed!');
Exemplo n.º 4
0
        context("nested in a context", function () {
            setup(function () {
                transient()->setup3 = true;
            });
            should("have called all three setups", function () {
                assert_equals(true, transient()->setup1);
                assert_equals(true, transient()->setup2);
                assert_equals(true, transient()->setup3);
            });
            should("have the proper test description", function () {
                assert_equals("a context nested in a context nested in a context should have the proper test description", Smoothie::instance()->test_description());
            });
        });
    });
    should("have ran teardown", function () {
        assert_true($GLOBALS['I_RAN_TEARDOWN']);
    });
    context("with no setup", function () {
        should("work", function () {
            assert_true(true);
        });
    });
    // TODO
    should("cause a failure", function () {
        assert_equals(1, 2);
    });
    // TODO
    should("cause an error", function () {
        throw new \Exception("exception!");
    });
});
/**
*
* @param string	$file	the file to run through
*
* @return boolean
* @access public
*/
function process_errors_file($path, $file)
{
    bam('ERRORS ' . $file);
    $xml_object = new XML_Tree($file);
    $root = $xml_object->getTreeFromFile();
    assert_equals($root->name, 'files');
    echo $locale = $root->attributes['locale'];
    for (reset($root->children); null !== ($file_index = key($root->children)); next($root->children)) {
        $file_tag =& $root->children[$file_index];
        $file_name = $path . '/' . $file_tag->attributes['source'] . '/' . $locale . '/lang_errors.xml';
        // now create the file (and directory if required)
        create_directory($path . '/' . $file_tag->attributes['source'] . '/' . $locale);
        string_to_file($file_tag->children[0]->get(), $file_name);
    }
    return true;
}
Exemplo n.º 6
0
 context("filtering", function () {
     should("accept -n", function () {
         $smoothie = new Smoothie(array("-n", "your regex"));
         assert_equals("/your regex/", $smoothie->filter);
     });
     should("accept --filter", function () {
         $smoothie = new Smoothie(array("--filter", "your regex"));
         assert_equals("/your regex/", $smoothie->filter);
     });
     should("add slashes if missing", function () {
         $smoothie = new Smoothie(array("-n", "your regex"));
         assert_equals("/your regex/", $smoothie->filter);
     });
     should("not add slahes if already there", function () {
         $smoothie = new Smoothie(array("-n", "/your regex/"));
         assert_equals("/your regex/", $smoothie->filter);
     });
     should("return true if no filter was set", function () {
         $smoothie = new Smoothie();
         assert_true($smoothie->passes_filter("my awesome test"));
     });
     context("tests with passes_filter()", function () {
         setup(function () {
             transient()->smoothie = new Smoothie(array("-n", "/my awesome test/"));
         });
         should("return true if filter was set and passes", function () {
             assert_true(transient()->smoothie->passes_filter("this is my awesome test that is awesome"));
         });
         should("return false if filter was set and does not pass", function () {
             assert_false(transient()->smoothie->passes_filter("blah"));
         });
Exemplo n.º 7
0
<?php

require 'remoteling.php';
$r = new Remoteling('2b0846cab17d80d2dae115bbedc3aa75cd732dccb5f412ea5e2451d6afd31fb9');
## Store
$rand_string = preg_replace('/([ ])/e', 'chr(rand(97,122))', '     ');
$r->set('foobar', $rand_string);
assert_equals($r->get('foobar'), $rand_string);
## Queues
$rand_string = preg_replace('/([ ])/e', 'chr(rand(97,122))', '     ');
$rand_q = preg_replace('/([ ])/e', 'chr(rand(97,122))', '     ');
$r->push($rand_q, $rand_string);
assert_equals($r->pop($rand_q), $rand_string);
assert_equals($r->pop($rand_q), ' ');
## Execution
$r->set('foobar_test_results', null);
$code = "Remoteling.store('foobar_test_results','yarr')";
$r->run_serialized($code, 'foobar');
sleep(2);
assert_equals('yarr', $r->get('foobar_test_results'));
## Test Helpers
function assert_equals($a, $b)
{
    if ($a == $b) {
        echo ".";
    } else {
        echo "\nFAILURE, was looking for {$a} and got {$b}\n";
    }
}
Exemplo n.º 8
0
}
function println($text)
{
    echo $text . "\n";
}
require 'Googl.class.php';
#
# IMPORTANT: Please add your API key to make the tests work
#
$googl = new Googl('YOUR_API_KEY');
println('#1 - Assert that shortening http://www.google.ch results in an URL');
assert_url($googl->shorten('http://www.google.ch'));
println('#2 - Assert that expanding http://goo.gl/KSggQ resolves to http://www.google.com/');
assert_equals($googl->expand('http://goo.gl/KSggQ'), 'http://www.google.com/');
println('#3 - Assert that shortening https://www.facebook.com results in an URL');
assert_url($googl->shorten('https://www.facebook.com'));
println('#4 - Assert that expanding http://goo.gl/wCWWd resolves to http://www.php.net/');
assert_equals($googl->expand('http://goo.gl/wCWWd'), 'http://www.php.net/');
unset($googl);
$googl = new Googl('BAD_KEY');
println('---Assert with Bad key---');
println('#1 - Assert that shortening http://www.google.ch results in an URL');
assert_url($googl->shorten('http://www.google.ch', true));
println('#2 - Assert that expanding http://goo.gl/KSggQ resolves to http://www.google.com/');
assert_equals($googl->expand('http://goo.gl/KSggQ', true), 'http://goo.gl/KSggQ');
println('#3 - Assert that shortening https://www.facebook.com results in an URL');
assert_url($googl->shorten('https://www.facebook.com', true));
println('#4 - Assert that expanding http://goo.gl/wCWWd resolves to http://www.php.net/');
assert_equals($googl->expand('http://goo.gl/wCWWd', true), 'http://goo.gl/wCWWd');
# If this point is reached, all tests have passed
println('All tests have successfully passed!');
Exemplo n.º 9
0
<?php

namespace Smoothie;

require_once dirname(__FILE__) . '/../Smoothie.php';
context("assertions", function () {
    context("with assert_equals", function () {
        setup(function () {
            assert_equals("bob", "bob!");
        });
        should_eventually("report failure if expected does not match actual value");
    });
});