コード例 #1
0
 /**
  * The inverse operation of calling toResponse.
  *
  * This function will attempt to parse a Response object into an
  * ApiResponse object, which can be useful for introspection and testing.
  *
  * @param Response $response
  *
  * @throws CoreException
  * @return static
  */
 public static function fromResponse(Response $response)
 {
     $body = Std::jsonDecode($response->getContent());
     $result = Spec::define(['messages' => Boa::arrOf(Boa::string()), 'status' => Boa::in(static::getValidStatuses()), 'code' => Boa::integer()])->check($body);
     if ($result->failed()) {
         throw new CoreException('Unable to parse an ApiResponse out of the content of a' . ' Response object. Make sure that the Response object was' . ' actually generated by an ApiResponse or a compatible' . ' implementation.');
     }
     return new static(Arr::except($body, static::getReservedKeys()), $body['status'], $body['messages']);
 }
コード例 #2
0
ファイル: ArrTest.php プロジェクト: chromabits/nucleus
 public function testExcept()
 {
     $this->assertEqualsMatrix([[[], Arr::except([1, 2, 3], [0, 1, 2])], [[1 => 2], Arr::except([1, 2, 3], [0, 2])], [[0 => 1, 2 => 3], Arr::except([1, 2, 3], [1])]]);
 }