Skip to content

Commit

Permalink
Serialize objects inside GetMyFeesEstimates data array
Browse files Browse the repository at this point in the history
  • Loading branch information
jlevers committed Jun 21, 2024
1 parent 16d93ad commit cf88185
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 20 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"require-dev": {
"composer/semver": "^3.4",
"highsidelabs/saloon-sdk-generator": "^2.0",
"highsidelabs/saloon-sdk-generator": "^2.1.0",
"symfony/console": "^7.0",
"psy/psysh": "^0.12.0",
"voku/simple_html_dom": "^4.8",
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/UnknownDatetimeFormatException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

use Exception;

class UnknownDatetimeFormatException extends Exception {}
class UnknownDatetimeFormatException extends Exception {}
14 changes: 2 additions & 12 deletions src/Generator/Generators/RequestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
namespace SellingPartnerApi\Generator\Generators;

use Crescat\SaloonSdkGenerator\Data\Generator\Endpoint;
use Crescat\SaloonSdkGenerator\Enums\SimpleType;
use Crescat\SaloonSdkGenerator\Generators\RequestGenerator as SDKGenerator;
use Crescat\SaloonSdkGenerator\Helpers\NameHelper;
use Crescat\SaloonSdkGenerator\Helpers\Utils;
use Exception;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -172,16 +170,8 @@ protected function generateRequestClass(Endpoint $endpoint): PhpFile
->setType(Response::class);

if ($endpoint->bodySchema) {
$bodyType = $endpoint->bodySchema->type;
if (SimpleType::isScalar($bodyType)) {
$returnValText = '[$this->%s]';
} elseif ($bodyType === 'DateTime') {
$returnValText = '[$this->%s->format(\''.$this->config->datetimeFormat.'\')]';
} elseif (! Utils::isBuiltinType($bodyType)) {
$returnValText = '$this->%s->toArray()';
} else {
$returnValText = '$this->%s';
}
$returnValText = $this->generateDefaultBody($endpoint->bodySchema);

$classType
->addMethod('defaultBody')
->setReturnType('array')
Expand Down
2 changes: 1 addition & 1 deletion src/Seller/ProductFeesV0/Requests/GetMyFeesEstimates.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ public function createDtoFromResponse(Response $response): GetMyFeesEstimatesRes

public function defaultBody(): array
{
return $this->getMyFeesEstimatesRequest;
return array_map(fn ($item) => $item->toArray(), $this->getMyFeesEstimatesRequest);
}
}
12 changes: 7 additions & 5 deletions tests/Seller/ReportsV20210630/Responses/ReportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace Seller\ReportsV20210630\Responses;

use DateTime;
use DateTimeInterface;
use PHPUnit\Framework\TestCase;
use SellingPartnerApi\Exceptions\UnknownDatetimeFormatException;
use SellingPartnerApi\Seller\ReportsV20210630\Responses\Report;
use PHPUnit\Framework\TestCase;

class ReportTest extends TestCase
{
Expand All @@ -19,20 +21,20 @@ public function testDeserializeUnknownDateTime()
// German DateTime Format should throw an exception as it is not one of the valid formats
$this->expectException(UnknownDatetimeFormatException::class);
Report::deserialize([
'createdTime' => '20.06.2024 17:15:33'
'createdTime' => '20.06.2024 17:15:33',
]);
}

public function testDeserializeDateTime()
{
$now = new \DateTime();
$now = new DateTime();
$result = Report::deserialize([
'reportId' => 12345,
'reportType' => 'TEST_REPORT',
'createdTime' => $now->format(DATE_ATOM),
'processingStatus' => 'IN_QUEUE'
'processingStatus' => 'IN_QUEUE',
]);
$this->assertNotNull($result);
$this->assertInstanceOf(\DateTimeInterface::class, $result->createdTime);
$this->assertInstanceOf(DateTimeInterface::class, $result->createdTime);
}
}

0 comments on commit cf88185

Please sign in to comment.