/** * Map each item in response data to instance of ResultObjectInterface * @param array $response * @param MethodResultCollectionInterface $method * * @return array */ public function mapCollection(array $response, MethodResultCollectionInterface $method) { $return = []; foreach ($response as $item) { $return[] = $this->map($item, $method->createResultObject()); } return $return; }
function it_maps_result_containing_collection_of_items(MethodResultCollectionInterface $method, ClientInterface $client, ValidatorInterface $validator, ResultObjectMapperInterface $mapper) { $result = [['id' => '3c4e8dcf']]; $resultObject = new Payment(); $method->getMethod()->willReturn('POST'); $method->getAction()->willReturn('payment'); $method->getAttributes()->willReturn([]); $method->createResultObject()->willReturn($resultObject); $validator->validate($method)->shouldBeCalled(); $mapper->mapCollection($result, $method)->shouldBeCalled()->willReturn([$resultObject]); $client->sendRequest($method, 'POST', 'payment', ['headers' => ['Content-Type' => 'application/json'], 'body' => '{}'])->shouldBeCalled()->willReturn($result); $this->call($method)->shouldReturn([$resultObject]); }