-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b40454
commit a8b0f98
Showing
7 changed files
with
223 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VasilDakov\EcontTest\Integration; | ||
|
||
use GuzzleHttp\Client; | ||
use Laminas\Diactoros\RequestFactory; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Http\Client\ClientInterface; | ||
use Psr\Http\Message\RequestFactoryInterface; | ||
use VasilDakov\Econt\Configuration; | ||
use VasilDakov\Econt\Econt; | ||
|
||
final class EcontTest extends TestCase | ||
{ | ||
private Configuration $configuration; | ||
private ClientInterface $client; | ||
private RequestFactoryInterface $factory; | ||
|
||
|
||
protected function setUp(): void | ||
{ | ||
$this->configuration = new Configuration('iasp-dev','1Asp-dev'); | ||
//$this->client = $this->createMock(ClientInterface::class); | ||
//$this->factory = $this->createMock(RequestFactoryInterface::class); | ||
|
||
$this->client = new Client(); | ||
$this->factory = new RequestFactory(); | ||
|
||
parent::setUp(); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function itCanGetClientProfiles(): void | ||
{ | ||
$econt = $this->getEcontClient(); | ||
|
||
$array = json_decode($econt->getClientProfiles(), true); | ||
self::assertArrayHasKey(key: 'profiles', array: $array); | ||
self::assertArrayHasKey(key: 'client', array: $array['profiles'][0]); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function itCanGetCountries(): void | ||
{ | ||
$econt = $this->getEcontClient(); | ||
$array = json_decode($econt->getCountries(), true); | ||
self::assertArrayHasKey(key:'countries', array: $array); | ||
} | ||
|
||
private function getEcontClient(): Econt | ||
{ | ||
return new Econt( | ||
configuration: $this->configuration, | ||
client: $this->client, | ||
factory: $this->factory | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
<?php | ||
|
||
namespace VasilDakov\EcontTest\Unit; | ||
|
||
use Fig\Http\Message\RequestMethodInterface; | ||
use GuzzleHttp\Client; | ||
use Laminas\Diactoros\RequestFactory; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Http\Client\ClientInterface; | ||
use Psr\Http\Message\RequestFactoryInterface; | ||
use Psr\Http\Message\RequestInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\StreamInterface; | ||
use VasilDakov\Econt\Configuration; | ||
use VasilDakov\Econt\Econt; | ||
use VasilDakov\Econt\Request\GetCitiesRequest; | ||
use function PHPUnit\Framework\once; | ||
|
||
class EcontTest extends TestCase | ||
{ | ||
private Configuration $configuration; | ||
private ClientInterface $client; | ||
private RequestFactoryInterface $factory; | ||
private RequestInterface $request; | ||
private ResponseInterface $response; | ||
private StreamInterface $stream; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->configuration = new Configuration('iasp-dev','1Asp-dev'); | ||
$this->client = $this->createMock(ClientInterface::class); | ||
$this->factory = $this->createMock(RequestFactoryInterface::class); | ||
$this->request = $this->createMock(RequestInterface::class); | ||
$this->response = $this->createMock(ResponseInterface::class); | ||
$this->stream = $this->createMock(StreamInterface::class); | ||
|
||
parent::setUp(); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function itCanBeCreatedWithValidArguments(): void | ||
{ | ||
self::assertInstanceOf( | ||
expected: Econt::class, | ||
actual: new Econt( | ||
configuration: $this->configuration, | ||
client: $this->client, | ||
factory: $this->factory | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function itCanGetCountries(): void | ||
{ | ||
$json = file_get_contents('./data/GetCountriesResponse.json'); | ||
|
||
$econt = new Econt( | ||
configuration: $this->configuration, | ||
client: $this->client, | ||
factory: $this->factory | ||
); | ||
|
||
$this->factory | ||
->expects(self::once()) | ||
->method('createRequest') | ||
->with(RequestMethodInterface::METHOD_POST) | ||
->willReturn($this->request) | ||
; | ||
|
||
$this->request | ||
->expects(self::exactly(2)) | ||
->method('withAddedHeader') | ||
->willReturnOnConsecutiveCalls($this->request, $this->request) | ||
; | ||
|
||
$this->client | ||
->expects(self::once()) | ||
->method('sendRequest') | ||
->with($this->request) | ||
->willReturn($this->response) | ||
; | ||
|
||
$this->response | ||
->expects(self::once()) | ||
->method('getBody') | ||
->willReturn($this->stream) | ||
; | ||
|
||
$this->stream | ||
->expects(self::once()) | ||
->method('getContents') | ||
->willReturn($json) | ||
; | ||
|
||
self::assertJson($econt->getCountries()); | ||
} | ||
|
||
|
||
/** | ||
* @test | ||
*/ | ||
public function itCanGetCities(): void | ||
{ | ||
$json = file_get_contents('./data/GetCitiesResponse.json'); | ||
|
||
$econt = new Econt( | ||
configuration: $this->configuration, | ||
client: $this->client, | ||
factory: $this->factory | ||
); | ||
|
||
$this->factory | ||
->expects(self::once()) | ||
->method('createRequest') | ||
->with(RequestMethodInterface::METHOD_POST) | ||
->willReturn($this->request) | ||
; | ||
|
||
$this->request | ||
->expects(self::exactly(2)) | ||
->method('withAddedHeader') | ||
->willReturnOnConsecutiveCalls($this->request, $this->request) | ||
; | ||
|
||
$this->client | ||
->expects(self::once()) | ||
->method('sendRequest') | ||
->with($this->request) | ||
->willReturn($this->response) | ||
; | ||
|
||
$this->response | ||
->expects(self::once()) | ||
->method('getBody') | ||
->willReturn($this->stream) | ||
; | ||
|
||
$this->stream | ||
->expects(self::once()) | ||
->method('getContents') | ||
->willReturn($json) | ||
; | ||
|
||
self::assertJson($econt->getCities(new GetCitiesRequest('BGR'))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters