Skip to content

Commit

Permalink
First attempt to mix validation of POST/GET parameters
Browse files Browse the repository at this point in the history
In this case there are POST parameters and the additional GET parameter shouldn't be considered during the validation
  • Loading branch information
DavidePastore committed Jan 3, 2019
1 parent bab72b2 commit 728b363
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/ValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -853,4 +853,58 @@ public function routeParamValidationProvider()
),
);
}

public function testArrayParametersWithGet() {
$uri = Uri::createFromString('https://example.com:443/foo/bar?test=1');
$headers = new Headers();
$headers->set('Content-Type', 'application/json;charset=utf8');
$cookies = [];
$env = Environment::mock([
'SCRIPT_NAME' => '/index.php',
'REQUEST_URI' => '/foo',
'REQUEST_METHOD' => 'POST',
]);
$serverParams = $env->all();
$body = new RequestBody();
$json = array(
array(
'id' => 1234
),
);
$body->write(json_encode($json));
$this->request = new Request('POST', $uri, $headers, $cookies, $serverParams, $body);
$this->response = new Response();
$expectedValidators = v::allOf(
v::each(
v::keySet(
v::key("id", v::intVal())
)
),
v::key('test', v::stringType())
);
$expectedTranslator = null;
$expectedErrors = array();
$mw = new Validation($expectedValidators, $expectedTranslator);

$errors = null;
$hasErrors = null;
$validators = null;
$translator = null;
$next = function ($req, $res) use (&$errors, &$hasErrors, &$validators, &$translator) {
$errors = $req->getAttribute('errors');
$hasErrors = $req->getAttribute('has_errors');
$validators = $req->getAttribute('validators');
$translator = $req->getAttribute('translator');

return $res;
};

$response = $mw($this->request, $this->response, $next);

$this->assertEquals($expectedErrors, $errors);
$this->assertEquals(false, $hasErrors);

$this->assertEquals($expectedValidators, $validators);
$this->assertEquals($expectedTranslator, $translator);
}
}

0 comments on commit 728b363

Please sign in to comment.