Skip to content

Commit

Permalink
Merge pull request #8 from OgunsakinDamilola/feat/tests-and-upgrades
Browse files Browse the repository at this point in the history
test and workflow update
  • Loading branch information
ogunsakin01 committed Aug 26, 2022
2 parents 171f1d8 + 045f8d2 commit a50ea4e
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 75 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: run-tests

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [7.4, 8.0]
laravel: [8.*]
stability: [prefer-stable]
include:
- laravel: 8.*
testbench: ^6.2

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install Dependencies
run: composer update
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: Execute tests
run: vendor/bin/phpunit
2 changes: 1 addition & 1 deletion .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":1,"defects":{"OgunsakinDamilola\\Interswitch\\Tests\\Unit\\InterswitchPaymentModelTest::model_can_be_initiated_with_factory":4},"times":{"OgunsakinDamilola\\Interswitch\\Tests\\Unit\\InterswitchPaymentModelTest::model_can_be_initiated_with_factory":0.25}}
{"version":1,"defects":{"OgunsakinDamilola\\Interswitch\\Tests\\Unit\\InterswitchPaymentModelTest::model_can_be_initiated_with_factory":4},"times":{"OgunsakinDamilola\\Interswitch\\Tests\\Unit\\InterswitchPaymentModelTest::model_can_be_initiated_with_factory":0.295}}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![Latest Stable Version](https://poser.pugx.org/ogunsakindamilola/laravel-interswitch/v/stable.svg)](https://packagist.org/packages/ogunsakindamilola/laravel-interswitch)
[![License](https://poser.pugx.org/ogunsakindamilola/laravel-interswitch/license.svg)](LICENSE.md)
[![Total Downloads](https://img.shields.io/packagist/dt/ogunsakindamilola/laravel-interswitch.svg?style=flat-square)](https://packagist.org/packages/ogunsakindamilola/laravel-interswitch)
![GitHub Actions](https://github.com/ogunsakindamilola/laravel-interswitch/actions/workflows/master.yml/badge.svg)

A laravel package for Interswitch

Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/InterswitchController.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace OgunsakinDamilola\Interswitch\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Validator;
use OgunsakinDamilola\Interswitch\Facades\Interswitch;
use OgunsakinDamilola\Interswitch\InterswitchMailHandler;
Expand Down
4 changes: 2 additions & 2 deletions src/Interswitch.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function generatePayment($paymentData)
];
}

public function queryTransaction($reference, $amount): array
public function queryTransaction($reference, $amount)
{
$headers = [
"Hash:" . $this->queryTransactionHash($reference)
Expand All @@ -56,7 +56,7 @@ public function queryTransaction($reference, $amount): array
return $this->queryValidator($reference, $amount, $response);
}

private function queryValidator($reference, $amount, $response): array
private function queryValidator($reference, $amount, $response)
{
if (empty($response)) {
return [
Expand Down
15 changes: 8 additions & 7 deletions src/InterswitchTransactionsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct()
$this->environmentHandler();
}

protected function testEnvironmentHandler(): void
protected function testEnvironmentHandler()
{
if ($this->gateway === 'PAYDIRECT'):
$this->itemId = config('interswitch.test.payDirect.itemId');
Expand All @@ -50,7 +50,7 @@ protected function testEnvironmentHandler(): void
endif;
}

protected function liveEnvironmentHandler(): void
protected function liveEnvironmentHandler()
{
$this->itemId = config('interswitch.live.itemId');
$this->productId = config('interswitch.live.productId');
Expand All @@ -59,7 +59,7 @@ protected function liveEnvironmentHandler(): void
$this->requestUrl = config('interswitch.live.requestUrl');
}

protected function environmentHandler(): void
protected function environmentHandler()
{
switch ($this->env) {
case 'LIVE':
Expand All @@ -70,27 +70,28 @@ protected function environmentHandler(): void
}
}

protected function transactionReferenceHandler($reference = ''): string
protected function transactionReferenceHandler($reference = '')
{
if ($reference == ''):
return strtoupper(uniqid());
endif;
return $reference;
}

protected function initializeTransactionHash($reference, $amount): string
protected function initializeTransactionHash($reference, $amount)
{
$hashString = $reference . $this->productId . $this->itemId . $amount . $this->systemRedirectUrl . $this->macKey;
return hash('SHA512', $hashString);
}

protected function queryTransactionHash($reference): string
protected function queryTransactionHash($reference)
{
$hashString = $this->productId . $reference . $this->macKey;
return hash('SHA512', $hashString);
}

public function rebuildRedirectUrl(array $parameters): string{
public function rebuildRedirectUrl(array $parameters)
{
$returnUrl = $this->redirectUrl.'?';
foreach($parameters as $key => $parameter){
$returnUrl = $returnUrl.$key.'='.$parameter.'&';
Expand Down
34 changes: 0 additions & 34 deletions src/database/database.sqlite

This file was deleted.

21 changes: 0 additions & 21 deletions src/database/setup_default_tables_2022.php

This file was deleted.

21 changes: 12 additions & 9 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<?php

namespace OgunsakinDamilola\Interswitch\Tests;

use Orchestra\Testbench\TestCase as BaseTestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Database\Eloquent\Factory as EloquentFactory;
use OgunsakinDamilola\Interswitch\InterswitchServiceProvider;
use Orchestra\Testbench\TestCase as BaseTestCase;

class TestCase extends BaseTestCase
{
use RefreshDatabase;

public function setUp(): void
{
parent::setUp();

$this->app->make(EloquentFactory::class)->load($this->baseDir().DIRECTORY_SEPARATOR.'database'.DIRECTORY_SEPARATOR.'factories');

$this->app->make(EloquentFactory::class)->load($this->baseDir() . DIRECTORY_SEPARATOR . 'database' . DIRECTORY_SEPARATOR . 'factories');
}

protected function getPackageProviders($app)
Expand All @@ -22,14 +25,14 @@ protected function getPackageProviders($app)
];
}

protected function getEnvironmentSetUp($app)
protected function defineDatabaseMigrations()
{
include_once $this->baseDir().DIRECTORY_SEPARATOR.'database'.DIRECTORY_SEPARATOR.'setup_default_tables_2022.php';

(new \SetupDefaultTables2022)->up();
$this->loadMigrationsFrom($this->baseDir() . '/database/migrations');
}

private function baseDir(){
return str_replace('tests','src',__DIR__);

private function baseDir()
{
return str_replace('tests', 'src', __DIR__);
}
}

0 comments on commit a50ea4e

Please sign in to comment.