Untitled
unknown
php
a year ago
4.1 kB
13
Indexable
<?php
declare(strict_types=1);
namespace Deposit\Tests\Integration;
use Deposit\Model\BankTransferDeposit\BankTransferDeposit;
use ExchangeTechnologies\Test\DoctrineFixturesTrait;
use InterNations\Component\HttpMock\PHPUnit\HttpMockTrait;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
class GlobitexBankTransferImportTest extends KernelTestCase
{
use DoctrineFixturesTrait;
use HttpMockTrait;
public static function setUpBeforeClass(): void
{
static::setUpHttpMockBeforeClass('8085', 'localhost');
}
public static function tearDownAfterClass(): void
{
static::tearDownHttpMockAfterClass();
}
public function setUp(): void
{
parent::setUp();
$this->setUpHttpMock();
}
public function testItShouldImportDepoositsFromGlobitexAPI(): void
{
$this->purgeDatabase();
$kernel = static::bootKernel();
$kernel->boot();
$application = new Application($kernel);
$application->setAutoExit(false);
$this->mockGLobitexStatementResponse();
$this->mockWireTransferTitleRequest('9KHAY39KKRY', '8e4082ef-d7ef-4741-84a6-d81ae288146f');
$this->mockWireTransferTitleRequest('9JM7F39JPNF', 'd8949819-4140-41d2-a9a3-0439e3f1405c');
$this->http->mock->once()
->when()
->methodIs('GET')
->pathIs('/api/v1/checkwirecode/ASASCE9H9')
->then()
->statusCode(404)
->end();
$this->http->setUp();
$input = new ArrayInput(['command' => 'app:import:globitex']);
$repository = $kernel->getContainer()->get('doctrine')->getRepository(BankTransferDeposit::class);
$deposits = $repository->findAllByProvider('globitex');
$this->assertCount(0, $deposits);
$output = new NullOutput();
$application->run($input, $output);
/**
* @var BankTransferDeposit
* @var BankTransferDeposit $deposit2
* @var BankTransferDeposit $deposit3
* @var BankTransferDeposit $deposit4
*/
$deposit1 = $repository->findOneBy(
['wireTransferTitle.wireTransferTitle' => '9KHAY39KKRY', 'paymentProvider.value' => 'globitex']
);
$this->assertEquals('8e4082ef-d7ef-4741-84a6-d81ae288146f', $deposit1->userId()->toString());
$this->assertEquals('waiting_for_approval', $deposit1->status()->toString());
$deposit2 = $repository->findOneBy(
['wireTransferTitle.wireTransferTitle' => '9JM7F39JPNF', 'paymentProvider.value' => 'globitex']
);
$this->assertEquals('d8949819-4140-41d2-a9a3-0439e3f1405c', $deposit2->userId()->toString());
$this->assertEquals('waiting_for_approval', $deposit2->status()->toString());
$deposit3 = $repository->findOneBy(
['wireTransferTitle.wireTransferTitle' => 'ASASCE9H9', 'paymentProvider.value' => 'globitex']
);
$this->assertEquals(null, $deposit3->userId());
$this->assertEquals('waiting_for_approval', $deposit3->status()->toString());
}
private function mockGLobitexStatementResponse(): void
{
$statementResponse = file_get_contents(__DIR__.'/../resources/globitex/globitex_statement_response.json');
$this->http->mock->once()
->when()
->pathIs('/api/1/eurowallet/payments/history')
->methodIs('GET')
->then()
->statusCode(200)
->body($statementResponse)
->end();
}
private function mockWireTransferTitleRequest(string $wireTransferTitle, string $userId): void
{
$this->http->mock->once()
->when()
->methodIs('GET')
->pathIs('/api/v1/checkwirecode/'.$wireTransferTitle)
->then()
->statusCode(200)
->body('{"uuid":"'.$userId.'"}')
->end();
}
}
Editor is loading...
Leave a Comment