Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Adds basic test around body param handling
  • Loading branch information
jacobemerick committed Apr 23, 2017
1 parent b702434 commit 68919d7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Parameter/ParameterCheck.php
Expand Up @@ -85,13 +85,13 @@ protected function checkRequired(array $param)
*/
protected function checkBodySchema(array $param)
{
// todo move parsing of body to swagger-router-middleware
$bodyParam = array_merge(
$param['schema'],
[
'value' => json_decode($param['value']),
'value' => $param['value'],
]
);

return $this->checkParamValue($bodyParam);
}

Expand Down
31 changes: 31 additions & 0 deletions tests/unit/src/Parameter/ParameterCheckTest.php
Expand Up @@ -251,6 +251,37 @@ public function testCheckRequiredContinuesOnRequiredSetParam()
$reflectedCheckRequired->invokeArgs($parameterCheck, [ $mockParam ]);
}

public function testCheckBodySchemaPassesAlongRefactoredParams()
{
$mockParam = [
'schema' => [
'type' => 'some type',
],
'value' => 'some value',
];

$refactoredParam = [
'type' => 'some type',
'value' => 'some value',
];

$reflectedParameterCheck = new ReflectionClass(ParameterCheck::class);
$reflectedCheckBodySchema = $reflectedParameterCheck->getMethod('checkBodySchema');
$reflectedCheckBodySchema->setAccessible(true);

$parameterCheck = $this->getMockBuilder(ParameterCheck::class)
->disableOriginalConstructor()
->setMethods([
'checkParamValue',
])
->getMock();
$parameterCheck->expects($this->once())
->method('checkParamValue')
->with($refactoredParam);

$reflectedCheckBodySchema->invokeArgs($parameterCheck, [ $mockParam ]);
}

public function testCheckParamValueCallsCheckParamValueForEachItemInArray()
{
$mockParam = [
Expand Down

0 comments on commit 68919d7

Please sign in to comment.