Exemplo n.º 1
0
 /**
  * @param \Tonic\Application $app
  * @param \Tonic\Request $request
  * @param \Tonic\ResourceMetadata $resourceMetadata
  * @param \Tonic\MethodMetadata $methodMetadata
  */
 function it_shows_options($app, $request, $resourceMetadata, $methodMetadata)
 {
     $request->getMethod()->willReturn('options');
     $request->getParams()->willReturn(array());
     $methodMetadata->getConditions()->willReturn(array('method' => array('options')));
     $resourceMetadata->getMethods()->willReturn(array('options' => $methodMetadata));
     $app->getResourceMetadata(\Prophecy\Argument::any())->willReturn($resourceMetadata);
     $response = $this->exec();
     $response->code->shouldBe(200);
     $response->getHeader('Allow')->shouldBe('OPTIONS');
     $response->body->shouldBe(array('OPTIONS'));
 }
Exemplo n.º 2
0
 /**
  * @param \Tonic\Application $app
  * @param \Tonic\Request $request
  * @param \Tonic\ResourceMetadata $resourceMetadata
  */
 function let($app, $request, $resourceMetadata, $mySecret)
 {
     $request->getMethod()->willReturn('GET');
     $request->getParams()->willReturn(array());
     $request->getAccept()->willReturn(array());
     $request->getAcceptLanguage()->willReturn(array());
     $mySecret->beADoubleOf('\\Tonic\\MethodMetadata');
     $mySecret->getConditions()->willReturn(array('method' => array('GET'), 'secure' => array('aUser aPassword')));
     $resourceMetadata->getClass()->willReturn('\\Tyrell\\Secret');
     $resourceMetadata->getUri()->willReturn(array(array('/secret')));
     $resourceMetadata->getMethod('setup')->willReturn(null);
     $resourceMetadata->getMethods()->willReturn(array('mySecret' => $mySecret));
     $resourceMetadata->getMethod('setup')->willReturn(null);
     $app->getResourceMetadata(\Prophecy\Argument::any())->willReturn($resourceMetadata);
     $this->beConstructedWith($app, $request);
 }
Exemplo n.º 3
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')));
 }
Exemplo n.º 4
0
 /**
  * @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');
 }