Exemple #1
0
 /**
  * @param \Tonic\Application $app
  * @param \Tonic\Request $request
  */
 function it_should_feed_the_computer($app, $request)
 {
     $request->getMethod()->willReturn('POST');
     $request->getContentType()->willReturn('application/json');
     $request->getData()->willReturn('{"hello": "computer"}');
     $request->setData(Argument::any())->will(function ($args) use($request) {
         $request->getData()->willReturn($args[0]);
     });
     $request->getAccept()->willReturn(array('application/json'));
     $response = $this->exec();
     $response->code->shouldBe(200);
     $response->contentType->shouldBe('application/json');
     $response->body->shouldBe(json_encode(array('hello' => 'computer')));
 }
 /**
  * @param \Tonic\Request $request
  */
 function it_should_set_the_correct_response_mimetype($request)
 {
     $request->getUri()->willReturn('/foo/bar');
     $request->getMethod()->willReturn('GET');
     $request->getContentType()->willReturn('application/x-www-form-urlencoded');
     $request->getAccept()->willReturn(array('text/plain'));
     $request->getParams()->willReturn(array());
     $request->setParams(array())->willReturn(null);
     $resource = $this->getResource($request);
     $response = $resource->exec();
     $response->shouldHaveType('Tonic\\Response');
     $response->body->shouldBe('Example');
     $response->contentType->shouldBe('text/plain');
 }