Skip to content

Commit

Permalink
Updated econt client, req, res and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vasildakov committed Jan 6, 2024
1 parent 6ce649e commit f795636
Show file tree
Hide file tree
Showing 11 changed files with 18,382 additions and 9 deletions.
16 changes: 14 additions & 2 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
use VasilDakov\Econt\Econt;
use VasilDakov\Econt\Request\GetCitiesRequest;
use VasilDakov\Econt\Request\GetOfficesRequest;
use VasilDakov\Econt\Request\GetQuartersRequest;
use VasilDakov\Econt\Request\GetStreetsRequest;
use VasilDakov\Econt\Response\GetCitiesResponseFactory;
use VasilDakov\Econt\Response\GetClientProfilesResponse;
use VasilDakov\Econt\Response\GetOfficesResponseFactory;
use VasilDakov\Econt\Response\GetQuartersResponse;
use VasilDakov\Econt\Response\GetStreetsResponse;
use VasilDakov\Econt\Serializer\SerializerFactory;

chdir(dirname(__DIR__));
Expand Down Expand Up @@ -42,8 +46,8 @@
$json = $econt->getClientProfiles();

$serilizer = (new SerializerFactory())();
$object = $serilizer->deserialize($json, GetClientProfilesResponse::class, 'json');
dump($object);
//$object = $serilizer->deserialize($json, GetClientProfilesResponse::class, 'json');
//dump($object);


/*
Expand All @@ -57,3 +61,11 @@
$response = (new GetOfficesResponseFactory())($json);
dump($response);
*/

$json = $econt->getStreets(new GetStreetsRequest(cityId: '41'));
$object = $serilizer->deserialize($json, GetStreetsResponse::class, 'json');

//$json = $econt->getQuarters(new GetQuartersRequest(cityId: '41'));
//$object = $serilizer->deserialize($json, GetQuartersResponse::class, 'json');

dump($object->getStreets()->first());
12 changes: 10 additions & 2 deletions src/Econt.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,17 @@ public function getStreets(Request\GetStreetsRequest $object): string
}


public function getQuarters(array $data): string
public function getQuarters(Request\GetQuartersRequest $object): string
{
return '';
$request = $this->createRequest(
RequestMethodInterface::METHOD_POST,
self::API_URL . '/ee/services/Nomenclatures/NomenclaturesService.GetQuarters.json',
$object->toArray()
);

$response = $this->client->sendRequest($request);

return $response->getBody()->getContents();
}


Expand Down
2 changes: 1 addition & 1 deletion src/EcontInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function getOffices(Request\GetOfficesRequest $object): string;

public function getStreets(Request\GetStreetsRequest $object): string;

public function getQuarters(array $data): string;
public function getQuarters(Request\GetQuartersRequest $object): string;


public function createLabel(array $data): string;
Expand Down
4 changes: 1 addition & 3 deletions src/Model/Quarter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ public function __construct(

#[Serializer\Type('string')]
public ?string $nameEn = null,
) {

}
) {}

public function toArray(): array
{
Expand Down
19 changes: 19 additions & 0 deletions src/Request/GetQuartersRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace VasilDakov\Econt\Request;

use VasilDakov\Econt\Constants;

class GetQuartersRequest
{
public function __construct(public readonly string $cityId)
{
}

public function toArray(): array
{
return [
Constants::CITY_ID => $this->cityId,
];
}
}
17 changes: 17 additions & 0 deletions src/Response/GetQuartersResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace VasilDakov\Econt\Response;

use Doctrine\Common\Collections\ArrayCollection;
use JMS\Serializer\Annotation as Serializer;

class GetQuartersResponse
{
#[Serializer\Type("ArrayCollection<VasilDakov\Econt\Model\Quarter>")]
private ArrayCollection $quarters;

public function __construct()
{
$this->quarters = new ArrayCollection();
}
}
16 changes: 15 additions & 1 deletion src/Response/GetStreetsResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,21 @@

namespace VasilDakov\Econt\Response;

use Doctrine\Common\Collections\ArrayCollection;
use JMS\Serializer\Annotation as Serializer;

class GetStreetsResponse
{
#[Serializer\Type("ArrayCollection<VasilDakov\Econt\Model\Street>")]
private ArrayCollection $streets;

public function __construct()
{
$this->streets = new ArrayCollection();
}

}
public function getStreets(): ArrayCollection
{
return $this->streets;
}
}
Loading

0 comments on commit f795636

Please sign in to comment.