Example #1
0
        expect(ob_get_clean())->to_be('bar');
    });
    it("should return null if no route matched the request", function () {
        ob_start();
        expect(pipes\run())->to_be_null();
        expect(ob_get_clean())->to_be('');
    });
    it("should not flush the response if \$options->flush is false", function () {
        pipes\get('/foo', function () {
            return 'bar';
        });
        ob_start();
        pipes\run(array('flush' => false));
        expect(ob_get_clean())->to_be('');
        ob_start();
        pipes\response()->flush();
        expect(ob_get_clean())->to_be('bar');
    });
    it("should use the 'path' sub-pattern, if matched", function () {
        $_SERVER['REQUEST_URI'] = '/toe/foo';
        $request = pipes\request(new pipes\Request());
        pipes\get('/toe/(?<path>\\w+)', array('paths' => array(__DIR__ . '/mock/path1', __DIR__ . '/mock/path2')));
        ob_start();
        pipes\run();
        expect(ob_get_clean())->to_be('foo1foo2');
    });
});
describe("php", function () {
    it("should return true if the file was included", function () {
        ob_start();
        $filename = __DIR__ . '/mock/path1/foo.php';
Example #2
0
<?php

describe("response()", function () {
    it("should return the current pipes\\Response instance", function () {
        $response = pipes\response();
        expect($response)->to_be_a('pipes\\Response');
        expect(pipes\response())->to_be($response);
    });
    it("should allow you to override the current instance", function () {
        $oldResponse = pipes\response();
        $newResponse = new pipes\Request();
        expect(pipes\response($newResponse))->to_be($newResponse);
        expect(pipes\response())->to_be($newResponse);
        expect(pipes\response($oldResponse))->to_be($oldResponse);
        expect(pipes\response())->to_be($oldResponse);
    });
});
describe("Response", function () {
    before_each(function ($context) {
        pipes\headers(array());
        $context['response'] = new pipes\Response();
        return $context;
    });
    it("should be empty by default", function ($context) {
        extract($context);
        expect($response->body)->to_be_type('array')->and_to_be_empty();
        expect($response->headers)->to_be_a('pipes\\Hash')->to_have_count(0);
        expect($response->length)->to_be(0);
    });
    it("should allow you to specify headers", function ($context) {
        extract($context);
Example #3
0
    after_each(function () {
        pipes\response(new pipes\Response());
    });
    it("should add a 302 status and location to the response", function () {
        expect(function () {
            pipes\redirect('/foo');
        })->to_throw('pipes\\HaltException');
        expect(pipes\response()->status)->to_be(302);
        expect(pipes\response()->headers['Location'])->to_Be('/foo');
    });
    it("should allow you to override the status", function () {
        expect(function () {
            pipes\redirect('/foo', 304);
        })->to_throw('pipes\\HaltException');
        expect(pipes\response()->status)->to_be(304);
        expect(pipes\response()->headers['Location'])->to_Be('/foo');
    });
});
describe("routes()", function () {
    it("should return the array of routes", function () {
        $routes = pipes\routes();
        expect($routes)->to_be_type('array')->and_to_be_empty();
    });
    it("should allow you to override the current array", function () {
        $oldRoutes = pipes\routes();
        $newRoutes = pipes\routes(array('foo', 'bar'));
        expect($oldRoutes)->to_be_empty();
        expect($newRoutes)->to_be(array('foo', 'bar'));
        expect(pipes\routes())->to_be($newRoutes);
        pipes\routes($oldRoutes);
    });