Пример #1
0
Test::create("fail actually fails", function (Test $test) {
    $test->fail("such a good fail");
});
Test::create("notOk checks for falsey", function (Test $test) {
    $test->notOk(false, "false is not okay");
    $test->notOk(true, "true is okay");
});
Test::create("throws looks for exceptions", function (Test $test) {
    $test->throws(function () {
        return true;
    }, "/Exception/", "you should have thrown an exception bruv");
    $test->throws(function () {
        throw new Exception("Aww yea");
    }, "/Exception/", "there you go");
});
Test::create("doesNotThrow should check exceptions are not thrown", function (Test $test) {
    $test->doesNotThrow(function () {
        return true;
    }, "looks good");
    $test->doesNotThrow(function () {
        throw new Exception("Aww yea");
    }, "you shouldn't have thrown an exception mate");
});
Test::create("equals", function (Test $test) {
    $test->equals(1, 1, "should be good");
    $test->equals(0, 1, "should fail");
});
Test::create("not equals", function (Test $test) {
    $test->notEquals(0, 1, "should be good");
    $test->notEquals(1, 1, "should fail");
});
Пример #2
0
<?php

use zacharyrankin\just_test\Test;
require_once __DIR__ . '/../vendor/autoload.php';
Test::create("something better fail", function (Test $test) {
    throw new Exception('Aww bad things going down.');
});
Пример #3
0
<?php

use zacharyrankin\just_test\Test;
require_once __DIR__ . '/../vendor/autoload.php';
Test::create("we should be testing globs", function (Test $test) {
    $test->pass("more testing is good");
});
Пример #4
0
});
Test::create('should tokenize html entities with another semicolon on the line', function (Test $test) {
    $tokenizer = new Tokenizer();
    $tokens = $tokenizer->tokenize("hello &nbsp; another;");
    $test->equals($tokens, [['type' => 'word', 'value' => 'hello'], ['type' => 'whitespace', 'value' => ' '], ['type' => 'html-entity', 'value' => '&nbsp;'], ['type' => 'whitespace', 'value' => ' '], ['type' => 'word', 'value' => 'another'], ['type' => 'punctuation', 'value' => ';']]);
});
Test::create('should tokenize punctuation', function (Test $test) {
    $tokenizer = new Tokenizer();
    $tokens = $tokenizer->tokenize("a!b@c&d ;");
    $test->equals($tokens, [['type' => 'word', 'value' => 'a'], ['type' => 'punctuation', 'value' => '!'], ['type' => 'word', 'value' => 'b'], ['type' => 'punctuation', 'value' => '@'], ['type' => 'word', 'value' => 'c'], ['type' => 'punctuation', 'value' => '&'], ['type' => 'word', 'value' => 'd'], ['type' => 'whitespace', 'value' => ' '], ['type' => 'punctuation', 'value' => ';']]);
});
Test::create('should tokenize html with gt/lt signs', function (Test $test) {
    $tokenizer = new Tokenizer();
    $tokens = $tokenizer->tokenize("5 < 6");
    $test->equals($tokens, [['type' => 'word', 'value' => '5'], ['type' => 'whitespace', 'value' => ' '], ['type' => 'punctuation', 'value' => '<'], ['type' => 'whitespace', 'value' => ' '], ['type' => 'word', 'value' => '6']]);
});
Test::create('should tokenize html with gt/lt signs and html', function (Test $test) {
    $tokenizer = new Tokenizer();
    $tokens = $tokenizer->tokenize("<p>5 < 6</p>");
    $test->equals($tokens, [['type' => 'html-tag', 'value' => '<p>'], ['type' => 'word', 'value' => '5'], ['type' => 'whitespace', 'value' => ' '], ['type' => 'punctuation', 'value' => '<'], ['type' => 'whitespace', 'value' => ' '], ['type' => 'word', 'value' => '6'], ['type' => 'html-tag', 'value' => '</p>']]);
});
Test::create('should tokenize html with html entities that have a hashtag', function (Test $test) {
    $tokenizer = new Tokenizer();
    $tokens = $tokenizer->tokenize("<p>testing &#8211;</p>");
    $test->equals($tokens, [['type' => 'html-tag', 'value' => '<p>'], ['type' => 'word', 'value' => 'testing'], ['type' => 'whitespace', 'value' => ' '], ['type' => 'html-entity', 'value' => '&#8211;'], ['type' => 'html-tag', 'value' => '</p>']]);
});
Test::create('should tokenize html with html entities that have a hashtag and another semicolon', function (Test $test) {
    $tokenizer = new Tokenizer();
    $tokens = $tokenizer->tokenize("<p>&#8211;evident;</p>");
    $test->equals($tokens, [['type' => 'html-tag', 'value' => '<p>'], ['type' => 'html-entity', 'value' => '&#8211;'], ['type' => 'word', 'value' => 'evident'], ['type' => 'punctuation', 'value' => ';'], ['type' => 'html-tag', 'value' => '</p>']]);
});
<?php

use zacharyrankin\just_test\Test;
require_once __DIR__ . '/../vendor/autoload.php';
Test::create("something better fail", function (Test $test) {
    $test->pass('Yup');
    $a = [];
    $a->bloo();
});
    $named = new NamedSqlParams();
    list($p_sql, $p_params) = $named->prep("SELECT :one", ['one' => '1']);
    $test->equals($p_sql, "SELECT ?", "should make prepared stmt");
    $test->equals($p_params, ['1'], "should have one parameter");
});
Test::create("debug function gets called", function (Test $test) {
    $named = new NamedSqlParams(['debug_fn' => function ($val) {
        return "'{$val}'";
    }]);
    list($p_sql, $p_params) = $named->prep("SELECT :one", ['one' => '1'], ['debug' => true]);
    $test->equals($p_sql, "SELECT '1'", "should inject value");
    $test->equals($p_params, [], "should not have any parameters");
});
Test::create("utilize different quote tokens", function (Test $test) {
    $named = new NamedSqlParams(['quoted_tokens' => ['?', '?'], 'unquoted_tokens' => ['!', '!']]);
    list($sql, $params) = $named->prep("SELECT ?one?, !two!", ['one' => '1', 'two' => '2']);
    $test->equals($sql, 'SELECT ?, 2', 'should make new sql');
    $test->equals($params, ['1'], 'should return 1 parameter');
});
Test::create("numeric placeholders", function (Test $test) {
    $named = new NamedSqlParams(['numeric_placeholders' => true]);
    list($p_sql, $p_params) = $named->prep("SELECT 1 FROM whatever WHERE one = :one AND two = :two", ['one' => 1, 'two' => 2]);
    $test->equals($p_params, [1, 2], "should return array of prepped params");
    $test->equals($p_sql, "SELECT 1 FROM whatever WHERE one = \$1 AND two = \$2", "should return sql with numeric placeholders");
});
Test::create("numeric array values", function (Test $test) {
    $named = new NamedSqlParams(['numeric_placeholders' => true]);
    list($p_sql, $p_params) = $named->prep("SELECT 1 FROM whatever WHERE id IN (:ids) AND id2 IN (:ids2)", ['ids' => [1, 2], 'ids2' => [3, 4]]);
    $test->equals($p_params, [1, 2, 3, 4], "should return single array for all values");
    $test->equals($p_sql, "SELECT 1 FROM whatever WHERE id IN (\$1, \$2) AND id2 IN (\$3, \$4)", "should return sql with numeric placeholders");
});