Beispiel #1
0
<?php

describe("run", function () {
    before_each(function ($context) {
        $oldServer = $_SERVER;
        $oldRequest = $_REQUEST;
        $_SERVER['REQUEST_URI'] = '/foo';
        $_SERVER['REQUEST_METHOD'] = 'GET';
        $_REQUEST['a'] = 1;
        $_REQUEST['b'] = 2;
        pipes\routes(array());
        $options = pipes\options(new pipes\Hash());
        $request = pipes\request(new pipes\Request());
        $response = pipes\response(new pipes\Response());
        return array_merge($context, compact('oldServer', 'oldRequest', 'request'));
    });
    after_each(function ($context) {
        $_SERVER = $context['oldServer'];
        $_REQUEST = $context['oldRequest'];
    });
    it("should run and return the first matching route", function () {
        $route1 = pipes\get('/foo', function () {
            return 'bar';
        });
        $route2 = pipes\get('/foo', function () {
            return 'baz';
        });
        ob_start();
        expect(pipes\run())->to_be_type('object')->and_to_be($route1);
        expect(ob_get_clean())->to_be('bar');
    });
Beispiel #2
0
        pipes\routes(array());
        $route = pipes\post('/foo/bar', function () {
        });
        expect($route)->to_be_a('pipes\\Route');
        expect($route->options->method)->to_be('POST');
        expect(pipes\routes())->to_be(array($route));
    });
});
describe("put()", function () {
    it("should create a route for the PUT method", function () {
        pipes\routes(array());
        $route = pipes\put('/foo/bar', function () {
        });
        expect($route)->to_be_a('pipes\\Route');
        expect($route->options->method)->to_be('PUT');
        expect(pipes\routes())->to_be(array($route));
    });
});
describe("Route", function () {
    it("should accept a pattern as the first parameter", function () {
        $route = new pipes\Route('/foo/:bar', function () {
        });
        expect($route->rawPattern)->to_be('/foo/:bar');
    });
    it("should not compile the pattern until used", function () {
        $route = new pipes\Route('/foo/:bar', function () {
        });
        expect($route->pattern)->to_be_null();
    });
    it("should accept an array or hash of options as the second parameter", function () {
        $callback = function () {