Skip to content

Commit 59a18d3

Browse files
committed
Add some tests
1 parent f2a271f commit 59a18d3

File tree

6 files changed

+455
-0
lines changed

6 files changed

+455
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.history
2+
.env
3+
.phpunit.cache/
4+
.phpunit.result.cache
5+
composer.lock
6+
vendor/

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,9 @@
2424
"psr-4": {
2525
"Sequra\\PhpClient\\": "src/"
2626
}
27+
},
28+
"require-dev": {
29+
"phpunit/phpunit": "^10",
30+
"symfony/dotenv": "^7.0"
2731
}
2832
}

phpcs.xml

Lines changed: 347 additions & 0 deletions
Large diffs are not rendered by default.

phpunit.xml.dist

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd" backupGlobals="false" colors="true" processIsolation="false" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" cacheDirectory=".phpunit.cache" requireCoverageMetadata="false">
3+
<coverage/>
4+
<testsuites>
5+
<testsuite name="SeQura PHP Client Test Suite">
6+
<directory>./tests</directory>
7+
</testsuite>
8+
</testsuites>
9+
<source>
10+
<include>
11+
<directory suffix=".php">src</directory>
12+
</include>
13+
</source>
14+
</phpunit>

phpunit.xml.dist.bak

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd" backupGlobals="false" colors="true" processIsolation="false" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" cacheDirectory=".phpunit.cache" requireCoverageMetadata="false">
3+
<coverage/>
4+
<testsuites>
5+
<testsuite name="SeQura PHP Client Test Suite">
6+
<directory>./tests</directory>
7+
</testsuite>
8+
</testsuites>
9+
<source>
10+
<include>
11+
<directory suffix=".php">src</directory>
12+
</include>
13+
</source>
14+
</phpunit>

tests/ClientTest.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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

Comments
 (0)