Skip to content

Commit

Permalink
- allow mixed parsed body for Transfer attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Mogliev committed Feb 23, 2022
1 parent 95c411a commit 7618039
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 26 deletions.
19 changes: 0 additions & 19 deletions spec/Articus/PathHandler/Attribute/TransferSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,6 @@ public function it_transfers_data_from_parsed_body(DTService $dt, Request $in, R
$this->__invoke($in)->shouldBe($out);
}

public function it_throws_on_data_transfer_from_invalid_parsed_body(DTService $dt, Request $in, Invokable $instanciator, \stdClass $object)
{
$source = PH\Attribute\Transfer::SOURCE_POST;
$type = \stdClass::class;
$subset = '';
$objectAttr = 'object';
$instanciatorArgAttrs = [];
$errorAttr = null;

$data = 123;

$in->getParsedBody()->shouldBeCalledOnce()->willReturn($data);

$dt->transferToTypedData($data, $object, $subset)->shouldNotBeCalled();

$this->beConstructedWith($dt, $source, $type, $subset, $objectAttr, $instanciator, $instanciatorArgAttrs, $errorAttr);
$this->shouldThrow(PH\Exception\BadRequest::class)->during('__invoke', [$in]);
}

public function it_transfers_data_from_headers(DTService $dt, Request $in, Request $out, Invokable $instanciator, \stdClass $object)
{
$source = PH\Attribute\Transfer::SOURCE_HEADER;
Expand Down
9 changes: 2 additions & 7 deletions src/Articus/PathHandler/Attribute/Transfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,9 @@ public function __invoke(Request $request): Request

/**
* @param Request $request
* @return array
* @throws Exception\BadRequest
* @return mixed
*/
protected function getData(Request $request): array
protected function getData(Request $request)
{
$data = null;
switch ($this->source)
Expand All @@ -133,10 +132,6 @@ protected function getData(Request $request): array
break;
case self::SOURCE_POST:
$data = $request->getParsedBody();
if (!\is_array($data))
{
throw new Exception\BadRequest('Unexpected content');
}
break;
case self::SOURCE_ROUTE:
$routeResult = $request->getAttribute(RouteResult::class);
Expand Down

0 comments on commit 7618039

Please sign in to comment.