Esempio n. 1
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();
Esempio n. 2
0
        $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';
        expect(pipes\php($filename))->to_be_false();
        expect(ob_get_clean())->to_be('');
    });
    it("should extract \$context as local variables for the include", function () {
        ob_start();
        $context = array('xyzzy' => 1337);
        $filename = __DIR__ . '/mock/path1/context.php';
        expect(pipes\php($filename, $context))->to_be_true();
        expect(ob_get_clean())->to_be("int(1337)\n");
    });
});
describe("render", function () {
    it("should run a file relative to the templates folder and return output", function () {
        pipes\options()->views = __DIR__ . '/views';
        ob_start();
        expect(pipes\render('foo.php'))->to_be('hello');
        expect(ob_get_clean())->to_be('');
    });
    it("should return false if the file does not exist", function () {
        ob_start();
        expect(pipes\render('bar.php'))->to_be_false();
        expect(ob_get_clean())->to_be('');
    });
});