fromArray() public static method

public static fromArray ( array $arrayConfig ) : Element
$arrayConfig array
return Element
 function it_match_when_headers_from_config_are_equal_headers_from_request()
 {
     $responseConfig = Element::fromArray(['request' => ['path' => '/foo', 'headers' => ['Header' => 'Value', 'Header1' => 'Value1']]]);
     $request = Request::create('/foo');
     $request->headers->add(['Header' => 'Value', 'Header1' => 'Value1']);
     $this->match($request, $responseConfig)->shouldReturn(true);
 }
Beispiel #2
0
 /**
  * @param Loader $loader
  * @param MatchingPolicy $matchingPolicy
  */
 public function __construct(Loader $loader, MatchingPolicy $matchingPolicy)
 {
     $this->configs = [];
     foreach ($loader->getResponsesArray() as $responseArrayConfig) {
         $this->configs[] = Element::fromArray($responseArrayConfig);
     }
     $this->matchingPolicy = $matchingPolicy;
 }
Beispiel #3
0
 function it_returns_true_when_all_policies_can_match_request_to_response_config(MatchingPolicy $positiveMatchingPolicy1, MatchingPolicy $positiveMatchingPolicy2)
 {
     $this->addMatchingPolicy($positiveMatchingPolicy1);
     $this->addMatchingPolicy($positiveMatchingPolicy2);
     $responseConfig = Element::fromArray(['request' => ['path' => '/foo']]);
     $request = Request::create('/foo');
     $positiveMatchingPolicy1->match($request, $responseConfig)->willReturn(true);
     $positiveMatchingPolicy2->match($request, $responseConfig)->willReturn(true);
     $this->match($request, $responseConfig)->shouldReturn(true);
 }
 function it_return_false_when_request_method_is_not_in_response_config_allowed_methods()
 {
     $responseConfig = Element::fromArray(['request' => ['path' => '/foo', 'methods' => ['POST']]]);
     $request = Request::create('/foo', 'GET');
     $this->match($request, $responseConfig)->shouldReturn(false);
 }
Beispiel #5
0
 function it_not_match_when_request_body_not_match_config_body()
 {
     $responseConfig = Element::fromArray(['request' => ['path' => '/foo', 'headers' => [], 'body' => 'HELLO WORLD']]);
     $request = Request::create('/foo', 'GET', [], [], [], [], 'WORLD HELLO');
     $this->match($request, $responseConfig)->shouldReturn(false);
 }
Beispiel #6
0
 function it_does_not_match_when_request_path_is_not_matching_response_config_path()
 {
     $responseConfig = Element::fromArray(['request' => ['path' => '/foo/bar']]);
     $request = Request::create('/foo/baz');
     $this->match($request, $responseConfig)->shouldReturn(false);
 }
 function it_match_when_request_config_query_and_body_parameters_match_parameters_from_request()
 {
     $responseConfig = Element::fromArray(['request' => ['path' => '/foo', 'query' => ['foo' => 'bar'], 'request' => ['foo' => 'bar']]]);
     $request = Request::create('/foo?foo=bar', 'POST', ['foo' => 'bar']);
     $this->match($request, $responseConfig)->shouldReturn(true);
 }