|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | +namespace Sequra\PhpClient\Tests; |
| 4 | + |
| 5 | +use PHPUnit\Framework\TestCase; |
| 6 | +use Sequra\PhpClient\Client; |
| 7 | +use Symfony\Component\Dotenv\Dotenv; |
| 8 | + |
| 9 | +final class ClientTest extends TestCase |
| 10 | +{ |
| 11 | + private static $username; |
| 12 | + private static $password; |
| 13 | + private static $endpoint; |
| 14 | + private static $merchant; |
| 15 | + |
| 16 | + public static function setUpBeforeClass(): void |
| 17 | + { |
| 18 | + $dotenv = new Dotenv(); |
| 19 | + $dotenv->load(__DIR__ . '/../.env'); |
| 20 | + self::$username = $_ENV['SEQURA_USERNAME']; |
| 21 | + self::$password = $_ENV['SEQURA_PASSWORD']; |
| 22 | + self::$endpoint = $_ENV['SEQURA_ENDPOINT']; |
| 23 | + self::$merchant = $_ENV['SEQURA_MERCHANT']; |
| 24 | + } |
| 25 | + |
| 26 | + public function testCanBeCreated(): void |
| 27 | + { |
| 28 | + $this->assertInstanceOf( |
| 29 | + Client::class, |
| 30 | + new Client(self::$username, self::$password, self::$endpoint) |
| 31 | + ); |
| 32 | + } |
| 33 | + |
| 34 | + public function testCanBeCreatedWithLogs(): void |
| 35 | + { |
| 36 | + $logfile = "/tmp/test_sequra.log"; |
| 37 | + $this->assertInstanceOf( |
| 38 | + Client::class, |
| 39 | + new Client(self::$username, self::$password, self::$endpoint, true, $logfile) |
| 40 | + ); |
| 41 | + $this->assertFileExists($logfile); |
| 42 | + unlink($logfile); |
| 43 | + } |
| 44 | + |
| 45 | + public function testIsValidAuth(): void |
| 46 | + { |
| 47 | + $client = new Client(self::$username, self::$password, self::$endpoint); |
| 48 | + $this->assertTrue($client->isValidAuth(), "isValidAuth() should return true for " . self::$username . " " . self::$password); |
| 49 | + $client = new Client(self::$username, 'INVALID PASSWORD', self::$endpoint); |
| 50 | + $this->assertFalse($client->isValidAuth(), "isValidAuth() should return false"); |
| 51 | + } |
| 52 | + |
| 53 | + public function testGetAvailableDisbursements(): void |
| 54 | + { |
| 55 | + $client = new Client(self::$username, self::$password, self::$endpoint); |
| 56 | + $client->getAvailableDisbursements(self::$merchant); |
| 57 | + $disbursements = $client->getJson(); |
| 58 | + $this->assertIsList($disbursements, "getAvailableDisbursements() should return a list of available disbursements"); |
| 59 | + } |
| 60 | + |
| 61 | + public function testGetDisbursementDetails(): void |
| 62 | + { |
| 63 | + $client = new Client(self::$username, self::$password, self::$endpoint); |
| 64 | + $client->getAvailableDisbursements(self::$merchant); |
| 65 | + $disbursements = $client->getJson(); |
| 66 | + $client->getAvailableDisbursements($disbursements[0]['disbursement']['path']); |
| 67 | + $disbursement = $client->getJson(); |
| 68 | + $this->assertIsArray($disbursement['disbursement'], "getDisbursementDetails() should return a disbursement"); |
| 69 | + } |
| 70 | +} |
0 commit comments