Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
omalizadeh committed May 19, 2023
1 parent dca0fb2 commit 87109ef
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 61 deletions.
6 changes: 3 additions & 3 deletions src/Facades/PaymentGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
* @method static Receipt verify(Invoice $invoice)
* @method static array refund(Invoice $invoice)
* @method static array unverifiedPayments()
* @method static \Omalizadeh\MultiPayment\PaymentGateway setGateway(string $gateway)
* @method static string getGatewayName()
* @method static string getGatewayConfigKey()
* @method static \Omalizadeh\MultiPayment\PaymentGateway setProvider(string $providerName, string $providerInstanceConfigKey)
* @method static string getProviderName()
* @method static string getProviderInstanceConfigKey()
*
* @see \Omalizadeh\MultiPayment\PaymentGateway
*/
Expand Down
44 changes: 0 additions & 44 deletions tests/GatewayConfigTest.php

This file was deleted.

10 changes: 5 additions & 5 deletions tests/InvoiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

class InvoiceTest extends TestCase
{
public function testTomansToRialsAutoConversion(): void
public function test_tomans_to_rials_auto_conversion(): void
{
$invoice = new Invoice(12000);

$this->assertEquals(120000, $invoice->getAmount());
$this->assertEquals(12000, $invoice->getAmountInTomans());
}

public function testRialsToTomansAutoConversion(): void
public function test_rials_to_tomans_auto_conversion(): void
{
config(['multipayment.convert_to_rials' => false]);

Expand All @@ -24,23 +24,23 @@ public function testRialsToTomansAutoConversion(): void
$this->assertEquals(1200, $invoice->getAmountInTomans());
}

public function testUuidIsAutoGenerated(): void
public function test_uuid_is_generated_automatically(): void
{
$invoice = new Invoice(111);

$this->assertNotEmpty($invoice->getUuid());
$this->assertIsString($invoice->getUuid());
}

public function testUuidIsRandom(): void
public function test_uuid_is_random(): void
{
$firstInvoice = new Invoice(111);
$secondInvoice = new Invoice(222);

$this->assertNotEquals($firstInvoice->getUuid(), $secondInvoice->getUuid());
}

public function testStringAmountIsAcceptable(): void
public function test_string_amount_is_accepted_and_converted(): void
{
config(['multipayment.convert_to_rials' => false]);

Expand Down
6 changes: 3 additions & 3 deletions tests/NovinDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class NovinDriverTest extends TestCase
{
protected function getEnvironmentSetUp($app)
protected function getEnvironmentSetUp($app): void
{
parent::getEnvironmentSetUp($app);

Expand All @@ -16,11 +16,11 @@ protected function getEnvironmentSetUp($app)
$app['config']->set('gateway_novin', $novinSettings);
}

public function testUnverifiedPaymentsThrowsNotImplementedException(): void
public function test_fetching_unverified_payments_throws_exception(): void
{
$this->expectException(DriverNotFoundException::class);
$this->expectExceptionMessage('Driver does not implement');

PaymentGateway::setGateway('novin.main')->unverifiedPayments();
PaymentGateway::setProvider('novin', 'main')->unverifiedPayments();
}
}
30 changes: 30 additions & 0 deletions tests/PaymentGatewayConfigTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Omalizadeh\MultiPayment\Tests;

use Omalizadeh\MultiPayment\Exceptions\InvalidConfigurationException;
use Omalizadeh\MultiPayment\Facades\PaymentGateway;

class PaymentGatewayConfigTest extends TestCase
{
public function test_default_gateway_is_set_correctly(): void
{
$this->assertEquals('zarinpal', PaymentGateway::getProviderName());
$this->assertEquals('main', PaymentGateway::getProviderInstanceConfigKey());
}

public function test_gateway_can_be_changed(): void
{
PaymentGateway::setProvider('zarinpal', 'other');

$this->assertEquals('zarinpal', PaymentGateway::getProviderName());
$this->assertEquals('other', PaymentGateway::getProviderInstanceConfigKey());
}

public function test_invalid_gateway_config_throws_exception(): void
{
$this->expectException(InvalidConfigurationException::class);

PaymentGateway::setProvider('zarinpal', 'invalid_key');
}
}
4 changes: 2 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

class TestCase extends \Orchestra\Testbench\TestCase
{
protected function getPackageProviders($app)
protected function getPackageProviders($app): array
{
return [
MultiPaymentServiceProvider::class,
];
}

protected function getEnvironmentSetUp($app)
protected function getEnvironmentSetUp($app): void
{
$zarinpalSettings = require __DIR__.'../../config/gateway_zarinpal.php';

Expand Down
8 changes: 4 additions & 4 deletions tests/ZarinpalDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class ZarinpalDriverTest extends TestCase
{
public function testInvoiceCanBePurchased(): void
public function test_invoice_can_be_purchased(): void
{
$invoice = new Invoice(1200);

Expand All @@ -27,7 +27,7 @@ public function testInvoiceCanBePurchased(): void
$this->assertStringContainsString('testing-authority', $redirect['action']);
}

public function testInvoiceCanBeVerified(): void
public function test_paid_invoice_can_be_verified(): void
{
Http::fake([
'https://sandbox.zarinpal.com/pg/v4/payment/verify.json' => Http::response([
Expand All @@ -47,7 +47,7 @@ public function testInvoiceCanBeVerified(): void
$this->assertEquals('66-****-99', $receipt->getCardNumber());
}

public function testPaymentCanBeRefunded(): void
public function test_payment_can_be_refunded(): void
{
Http::fake([
'https://sandbox.zarinpal.com/pg/v4/payment/refund.json' => Http::response([
Expand All @@ -67,7 +67,7 @@ public function testPaymentCanBeRefunded(): void
$this->assertEquals('IR-XXX-XXXX', $response['iban']);
}

public function testUnverifiedPaymentsList(): void
public function test_unverified_payments_can_be_fetched(): void
{
Http::fake([
'https://sandbox.zarinpal.com/pg/v4/payment/unVerified.json' => Http::response([
Expand Down

0 comments on commit 87109ef

Please sign in to comment.