public function testURLsSetToNullIfInvalid()
 {
     $problem = new HTTPProblem(400, 'msg');
     $problem->withType('http://example.com')->withInstance('http://example.com/page.html');
     $this->assertSame('http://example.com', $problem->type());
     $this->assertSame('http://example.com/page.html', $problem->instance());
     $problem->withType('not-a-url')->withInstance('not-a-url-2');
     $this->assertSame(null, $problem->type());
     $this->assertSame(null, $problem->instance());
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function body(HTTPProblem $problem)
 {
     $data = ['status' => $problem->status()];
     if ($problem->title()) {
         $data['title'] = $problem->title();
     }
     if (!in_array($problem->type(), [null, 'about:blank'], true)) {
         $data['type'] = $problem->type();
     }
     if ($problem->detail()) {
         $data['detail'] = $problem->detail();
     }
     if ($problem->instance()) {
         $data['instance'] = $problem->instance();
     }
     $data += $problem->extensions();
     return json_encode($data, $this->encodingOptions);
 }