Files
boursecu_server/tests/Unit/ShayeganClientErrorMessageTest.php
T

58 lines
1.7 KiB
PHP
Raw Normal View History

<?php
namespace Tests\Unit;
use App\Services\ShayeganClient;
use PHPUnit\Framework\TestCase;
use ReflectionMethod;
class ShayeganClientErrorMessageTest extends TestCase
{
public function test_extract_error_message_from_top_level(): void
{
$client = $this->clientWithoutConstruct();
$method = new ReflectionMethod(ShayeganClient::class, 'extractErrorMessage');
$method->setAccessible(true);
$msg = $method->invoke($client, [
'ErrorMessage' => 'missing account',
'Result' => [['ErrorMessage' => '', 'Number' => '1']],
]);
$this->assertSame('missing account', $msg);
}
public function test_extract_error_message_from_result_row(): void
{
$client = $this->clientWithoutConstruct();
$method = new ReflectionMethod(ShayeganClient::class, 'extractErrorMessage');
$method->setAccessible(true);
$msg = $method->invoke($client, [
'ErrorMessage' => '',
'Result' => [['ErrorMessage' => 'row failed', 'Number' => null]],
]);
$this->assertSame('row failed', $msg);
}
public function test_empty_error_message_is_success_signal(): void
{
$client = $this->clientWithoutConstruct();
$method = new ReflectionMethod(ShayeganClient::class, 'extractErrorMessage');
$method->setAccessible(true);
$msg = $method->invoke($client, [
'ErrorMessage' => '',
'Result' => [['ErrorMessage' => '', 'Number' => '12', 'GuId' => 'abc']],
]);
$this->assertSame('', $msg);
}
private function clientWithoutConstruct(): ShayeganClient
{
return (new \ReflectionClass(ShayeganClient::class))->newInstanceWithoutConstructor();
}
}