<?php /* * How to use after_each. */ namespace Preview\DSL\BDD; require_once __DIR__ . '/../ok.php'; describe("after_each", function () { after_each(function () { $this->usage = "run after_each each test case"; }); after_each(function () { $this->note = "after_each hooks are run in order"; }); });
<?php describe("halt()", function () { it("should throw a HaltException", function () { expect(function () { pipes\halt(); })->to_throw('pipes\\HaltException'); }); }); 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(pipes\request())->to_be($oldRequest); }); }); describe("Request", function () { before_each(function ($context) { $oldServer = $_SERVER; $oldRequest = $_REQUEST; $_SERVER['REQUEST_URI'] = '/foo/bar/baz.biff'; $_SERVER['REQUEST_METHOD'] = 'PUT'; $_REQUEST['a'] = 1; $_REQUEST['b'] = 2; $request = new pipes\Request(); return array_merge($context, compact('oldServer', 'oldRequest', 'request')); }); after_each(function ($context) { $_SERVER = $context['oldServer']; $_REQUEST = $context['oldRequest']; }); it("should copy \$_SERVER['REQUEST_URI'] to \$request->uri", function ($context) { extract($context); expect($request->uri)->to_be($_SERVER['REQUEST_URI']); }); it("should copy \$_SERVER['REQUEST_METHOD'] to \$request->method", function ($context) { extract($context); expect($request->method)->to_be($_SERVER['REQUEST_METHOD']); }); it("should merge \$_REQUEST into \$request->params hash", function ($context) { extract($context); expect($request->params->a)->to_be(1); expect($request->params->b)->to_be(2); }); it("should allow \$request->params->_method to override real method", function ($context) {
it('should add a new probe by config if not exist', function ($scope) { $scope->p->update(array('name' => 'p1'), 123); expect($scope->p->probes->p1->args)->to_be(array(123)); }); }); describe('#increment', function () { before_each(function ($scope) { $scope = (object) $scope; $scope->p = new Provider(array('name' => 'p')); return $scope; }); after_each(function ($scope) { expect(get_object_vars($scope->p->probes))->to_have_count(2); $count = 0; $scope->p->on('sample', function () use(&$count) { $count++; }); $scope->p->probes->p1->sample('c1'); expect($count)->to_be(1); }); it('should use an existent probe by name', function ($scope) { $po = $scope->p->addProbe('p1', 'number'); $scope->p->probes->p1->update(5); $scope->p->increment('p1'); expect($scope->p->probes->p1->args)->to_be(array(6)); expect($scope->p->probes->p1->id)->to_be($po->id); }); it('should add a new probe by name if not exist', function ($scope) { $scope->p->increment('p1'); expect($scope->p->probes->p1->args)->to_be(array(1)); });