Skip to content

Commit

Permalink
fix(findPickupPoints): Wrap with array if result is flat
Browse files Browse the repository at this point in the history
  • Loading branch information
gaelreyrol committed Aug 5, 2019
1 parent f881d2a commit 11d236c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/DeliveryChoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(array $credentials, array $options = [])
* @param int|null $searchRadius Radius from the origin point
* @param string|null $activityType
* @param int $nbResults Number of results
* @return array
* @return PickupPoint[]
* @throws Exception
*/
public function findPickupPoints(
Expand Down Expand Up @@ -83,6 +83,12 @@ public function findPickupPoints(

$result = $result->WSI4_PointRelais_RechercheResult->PointsRelais->PointRelais_Details;

if (is_array($result) === false) {
return [
new PickupPoint($result)
];
}

$pickupPoints = array_map(
function ($pickupPoint) {
return new PickupPoint($pickupPoint);
Expand All @@ -96,7 +102,7 @@ function ($pickupPoint) {
/**
* @param string $country
* @param string $code
* @return array
* @return PickupPoint
* @throws Exception
*/
public function findPickupPointByCode(string $country, string $code)
Expand Down
24 changes: 24 additions & 0 deletions tests/DeliveryChoiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,30 @@ public function testFindPickupPointsWithError()
$delivery->findPickupPoints('Paris', '75001', 'FR');
}

public function testFindPickupPointsWithFlatResult()
{
$mockedPickupPointsResult = new \stdClass();
$mockedPickupPointsResult->STAT = 0;
$mockedPickupPointsResult->PointsRelais = new \stdClass();
$mockedPickupPointsResult->PointsRelais->PointRelais_Details = $this->pickupPointMock();

$mockedResult = new \stdClass();
$mockedResult->WSI4_PointRelais_RechercheResult = $mockedPickupPointsResult;

$this->mondialRelayWSDL
->expects($this->any())
->method('WSI4_PointRelais_Recherche')
->willReturn($mockedResult);

$delivery = new DeliveryChoice($this->credentials);
$delivery->soapClient = $this->mondialRelayWSDL;

$result = $delivery->findPickupPoints('Paris', '75001', 'FR');
$this->assertCount(1, $result);
$this->assertContainsOnlyInstancesOf(PickupPoint::class, $result);
}


public function testFindPickupPointsByCode()
{
$mockedPickupPoint = $this->pickupPointMock();
Expand Down

0 comments on commit 11d236c

Please sign in to comment.