<?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();
expect($request->params->a)->to_be(3); expect($request->params->b)->to_be(4); }); it("should strip requestBasePath option from \$request->uri", function ($context) { pipes\options()->requestBasePath = '/foo'; $request = new pipes\Request(); pipes\options()->delete('requestBasePath'); expect($request->uri)->to_be('/bar/baz.biff'); expect($request->method)->to_be('PUT'); expect($request->params->a)->to_be(1); expect($request->params->b)->to_be(2); }); it("should not strip requestBasePath from \$request->uri if they don't match", function ($context) { pipes\options()->requestBasePath = '/ohai'; $request = new pipes\Request(); pipes\options()->delete('requestBasePath'); expect($request->uri)->to_be('/foo/bar/baz.biff'); expect($request->method)->to_be('PUT'); expect($request->params->a)->to_be(1); expect($request->params->b)->to_be(2); }); it("should set \$request->path to \$request->uri without the extension", function ($context) { extract($context); expect($request->path)->to_be('/foo/bar/baz'); }); it("should copy the lowercased extension to \$request->format", function ($context) { extract($context); expect($request->format)->to_be('biff'); }); it("should also copy the format into \$request->params->format", function ($context) { extract($context);