<?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();
}); }); describe("redirect()", function () { 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'));