Skip to content

Commit

Permalink
fixed single entity response parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
sykorax committed Jun 19, 2019
1 parent aec5ef1 commit 6e3e8ec
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Internal/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public function getProducts()
);

// Convert response to OOP style.
return Collection::wrap(Arr::wrap($payload['Product']))->map(function ($rawProduct) {
return Collection::wrap(Arr::wrapNumeric($payload['Product']))->map(function ($rawProduct) {
return new Product($rawProduct);
});
});
Expand Down
15 changes: 15 additions & 0 deletions src/Laravel/Support/UnasServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,27 @@


use Illuminate\Contracts\Container\Container;
use Illuminate\Support\Arr;
use Illuminate\Support\ServiceProvider;
use SzuniSoft\Unas\Internal\Client;

class UnasServiceProvider extends ServiceProvider
{

public function boot()
{
Arr::macro('wrapNumeric', function ($arr) {

$arr = Arr::wrap($arr);

if (Arr::isAssoc($arr)) {
return [$arr];
}

return $arr;
});
}

public function register()
{
$this->registerConfigs();
Expand Down
6 changes: 6 additions & 0 deletions tests/Client/GetProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@

use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Collection;
use SzuniSoft\Unas\Laravel\Support\UnasServiceProvider;
use SzuniSoft\Unas\Model\Product;

class GetProductTest extends AuthenticatedTestCase
{

use WithFaker;

protected function getPackageProviders($app)
{
return [UnasServiceProvider::class];
}

/** @test */
public function can_return_with_products()
{
Expand Down

0 comments on commit 6e3e8ec

Please sign in to comment.