Ejemplo n.º 1
0
 public function marshal_exceptions()
 {
     $this->fixture->addMarshaller('unittest.AssertionFailedError', newinstance(TypeMarshaller::class, [], '{
   public function marshal($t) {
     return "assert:".$t->message;
   }
   public function unmarshal(\\lang\\Type $target, $name) {
     // Not needed
   }
 }'));
     $this->assertEquals(\webservices\rest\srv\Response::error(500)->withPayload(new \webservices\rest\Payload('assert:expected 1 but was 2', ['name' => 'exception'])), $this->fixture->asResponse(new \unittest\AssertionFailedError('expected 1 but was 2')));
 }
Ejemplo n.º 2
0
 public function error_with_message()
 {
     $r = Response::error(503, 'Come back later');
     $this->assertEquals(new Payload('Come back later'), $r->payload);
 }
 public function raised_exception($status, $exception)
 {
     $handler = newinstance(Object::class, [$exception], ['exception' => null, '__construct' => function ($exception) {
         $this->exception = $exception;
     }, '#[@webmethod(verb= "GET")] fixture' => function () {
         throw new $this->exception('Test', null);
     }]);
     $this->assertEquals(Response::error($status)->withPayload(new Payload(['message' => 'Test'], ['name' => 'exception'])), $this->handle($handler));
 }
 public function error_503()
 {
     $r = Response::error(503);
     $this->assertEquals(503, $r->status);
 }
    public function raised_exception($status, $class)
    {
        $handler = newinstance('lang.Object', array($class), '{
      protected $class;

      public function __construct($class) {
        $this->class= $class;
      }

      #[@webmethod(verb= "GET")]
      public function fixture() {
        raise($this->class, "Test", NULL);
      }
    }');
        $this->assertEquals(Response::error($status)->withPayload(new Payload(array('message' => 'Test'), array('name' => 'exception'))), $this->handle($handler));
    }
 public function marshal_exceptions()
 {
     $this->fixture->addMarshaller('unittest.AssertionFailedError', newinstance('webservices.rest.TypeMarshaller', array(), '{
   public function marshal($t) {
     return "expected ".xp::stringOf($t->expect)." but was ".xp::stringOf($t->actual);
   }
   public function unmarshal(Type $target, $name) {
     // Not needed
   }
 }'));
     $this->assertEquals(\webservices\rest\srv\Response::error(500)->withPayload(new \webservices\rest\Payload('expected 1 but was 2', array('name' => 'exception'))), $this->fixture->mapException(new \unittest\AssertionFailedError('Test', 2, 1)));
 }