コード例 #1
0
ファイル: simple.php プロジェクト: ngonchan/koi
<?php

require_once __DIR__ . '/helper.php';
require_once __DIR__ . '/apps/simple.php';
use Waffles\Test;
Test::group("Test a very basic application", function () {
    Test::add("Run a simple hello world example", function ($test) {
        global $app;
        // Fake a request
        $app_response = run_application('/', $app);
        $test->expects($app_response)->to()->equal('Hello, index!');
    });
    Test::add("Run a method with a parameter", function ($test) {
        global $app;
        // Fake a request
        $app_response = run_application('/param/yorick/peterse', $app);
        $test->expects($app_response)->to()->equal('hello yorick peterse');
    });
});
// Run all our tests
Test::run_all();
コード例 #2
0
ファイル: routes.php プロジェクト: ngonchan/koi
        // Fake a request
        $app_response = run_application('/abc123', $app);
        $test->expects($app_response)->to()->equal('alphanumeric method');
    });
    Test::add("Test a regex route", function ($test) {
        global $app;
        // Fake a request
        $app_response = run_application('/koi-123', $app);
        $test->expects($app_response)->to()->equal('regex method');
    });
    Test::add("Test a 404 route", function ($test) {
        global $app;
        // Fake a request
        $app_response = run_application('/does-not-exist', $app);
        $test->expects($app_response)->to()->equal('404 method');
    });
    Test::add("Test a sub 404 route", function ($test) {
        global $app;
        // Fake a request
        $app_response = run_application('/sublevel/does-not-exist', $app);
        $test->expects($app_response)->to()->equal('sub 404 method');
    });
    Test::add("Test a route with arguments", function ($test) {
        global $app;
        // Fake a request
        $app_response = run_application('/route_args/123', $app);
        $test->expects($app_response)->to()->equal('route with args method 123');
    });
});
// Run all our tests
Test::run_all();
コード例 #3
0
ファイル: returns.php プロジェクト: ngonchan/koi
<?php

require_once __DIR__ . '/helper.php';
require_once __DIR__ . '/apps/returns.php';
use Waffles\Test;
Test::group("Test if methods can return customized values, HTTP status codes and content types", function () {
    Test::add('return: array("index method", 200, "text/html")', function ($test) {
        global $app;
        $app_response = run_application('/', $app);
        $test->expects($app_response)->to()->equal("index method");
        $test->expects($app->last_http_status)->to()->equal('HTTP/1.1 200 OK');
        $test->expects($app->last_content_type)->to()->equal('text/html');
    });
    Test::add('return: array("not_found method", 404, "text/html")', function ($test) {
        global $app;
        $app_response = run_application('/not_found', $app);
        $test->expects($app_response)->to()->equal("not_found method");
        $test->expects($app->last_http_status)->to()->equal('HTTP/1.1 404 Not Found');
        $test->expects($app->last_content_type)->to()->equal('text/html');
    });
    Test::add('return: array("no_content method", 200)', function ($test) {
        global $app;
        $app_response = run_application('/no_content', $app);
        $test->expects($app_response)->to()->equal("no_content method");
        $test->expects($app->last_http_status)->to()->equal('HTTP/1.1 200 OK');
        $test->expects($app->last_content_type)->to()->equal('text/html');
    });
});
Test::run_all();