forked from apoloz/alfa-bank-sdk
refactor(core): enhance SDK structure and documentation
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
51
tests/Feature/FileExchangeTest.php
Normal file
51
tests/Feature/FileExchangeTest.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
use Apoloz\AlfaBank\Core\AlfaBankConnector;
|
||||
use Apoloz\AlfaBank\Core\AlfaConfig;
|
||||
use Apoloz\AlfaBank\Requests\FileExchange\UploadFileRequest;
|
||||
use Apoloz\AlfaBank\Requests\FileExchange\DownloadFileRequest;
|
||||
use Saloon\Http\Faking\MockResponse;
|
||||
|
||||
test('can upload a file', function () {
|
||||
$mockClient = new \Saloon\Http\Faking\MockClient([
|
||||
'*' => MockResponse::make([], 200),
|
||||
]);
|
||||
|
||||
$config = new AlfaConfig(
|
||||
baseUrl: 'https://test.com',
|
||||
certificatePath: __DIR__ . '/../test_key.pem',
|
||||
privateKeyPath: __DIR__ . '/../test_key.pem'
|
||||
);
|
||||
$connector = new AlfaBankConnector($config);
|
||||
$connector->withMockClient($mockClient);
|
||||
|
||||
$stream = fopen('php://memory', 'r+');
|
||||
fwrite($stream, 'test content');
|
||||
rewind($stream);
|
||||
|
||||
$request = new UploadFileRequest('https://upload.url', $stream, 12);
|
||||
$response = $connector->send($request);
|
||||
|
||||
expect($response->status())->toBe(200);
|
||||
fclose($stream);
|
||||
});
|
||||
|
||||
test('can download a file', function () {
|
||||
$mockClient = new \Saloon\Http\Faking\MockClient([
|
||||
'*' => MockResponse::make('file content', 200),
|
||||
]);
|
||||
|
||||
$config = new AlfaConfig(
|
||||
baseUrl: 'https://test.com',
|
||||
certificatePath: __DIR__ . '/../test_key.pem',
|
||||
privateKeyPath: __DIR__ . '/../test_key.pem'
|
||||
);
|
||||
$connector = new AlfaBankConnector($config);
|
||||
$connector->withMockClient($mockClient);
|
||||
|
||||
$request = new DownloadFileRequest('https://download.url');
|
||||
$response = $connector->send($request);
|
||||
|
||||
expect($response->status())->toBe(200)
|
||||
->and($response->body())->toBe('file content');
|
||||
});
|
||||
Reference in New Issue
Block a user