Exemplo n.º 1
0
    });
    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';
        expect(pipes\php($filename))->to_be_true();
        expect(ob_get_clean())->to_be('foo1');
    });
    it("should return false if the file was not included", function () {
        ob_start();
        $filename = __DIR__ . '/does/not/exist.php';
Exemplo n.º 2
0
<?php

require __DIR__ . '/../pipes.php';
pipes\options()->views = __DIR__ . '/views';
pipes\get('/', function () {
    return "Hello, world!";
});
pipes\get('/form', function () {
    return pipes\render('form.php');
});
pipes\post('/form', function ($params) {
    if (empty($params->name)) {
        return pipes\render('form.php', array('error' => 'You must enter a name'));
    } else {
        return pipes\redirect('/' . urlencode($params->name));
    }
});
pipes\get('/:name', function ($params) {
    return "Hello, {$params->name}!";
});
pipes\run();
Exemplo n.º 3
0
        expect(pipes\routes())->to_be(array($route));
    });
});
describe("delete()", function () {
    it("should create a route for the DELETE method", function () {
        pipes\routes(array());
        $route = pipes\delete('/foo/bar', function () {
        });
        expect($route)->to_be_a('pipes\\Route');
        expect($route->options->method)->to_be('DELETE');
    });
});
describe("get()", function () {
    it("should create a route for the GET method", function () {
        pipes\routes(array());
        $route = pipes\get('/foo/bar', function () {
        });
        expect($route)->to_be_a('pipes\\Route');
        expect($route->options->method)->to_be('GET');
        expect(pipes\routes())->to_be(array($route));
    });
});
describe("post()", function () {
    it("should create a route for the POST method", function () {
        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));
    });
});