Skip to content

Commit 29dca1a

Browse files
committed
Add GitHub Actions workflow for testing and implement initial test cases for routes and service provider
1 parent 4e8421b commit 29dca1a

3 files changed

Lines changed: 148 additions & 0 deletions

File tree

.github/workflows/tests.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
tests:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
include:
16+
- laravel: "8.*"
17+
testbench: "6.*"
18+
php: "8.1"
19+
- laravel: "9.*"
20+
testbench: "7.*"
21+
php: "8.1"
22+
- laravel: "10.*"
23+
testbench: "8.*"
24+
php: "8.2"
25+
- laravel: "11.*"
26+
testbench: "9.*"
27+
php: "8.3"
28+
- laravel: "12.*"
29+
testbench: "10.*"
30+
php: "8.3"
31+
32+
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}
33+
34+
steps:
35+
- name: Checkout
36+
uses: actions/checkout@v4
37+
38+
- name: Setup PHP
39+
uses: shivammathur/setup-php@v2
40+
with:
41+
php-version: ${{ matrix.php }}
42+
coverage: none
43+
tools: composer:v2
44+
45+
- name: Cache dependencies
46+
uses: actions/cache@v4
47+
with:
48+
path: ~/.composer/cache/files
49+
key: composer-${{ runner.os }}-${{ matrix.php }}-${{ matrix.laravel }}-${{ hashFiles('composer.json') }}
50+
restore-keys: |
51+
composer-${{ runner.os }}-${{ matrix.php }}-${{ matrix.laravel }}-
52+
composer-${{ runner.os }}-${{ matrix.php }}-
53+
54+
- name: Install matrix dependencies
55+
run: |
56+
composer require --no-interaction --no-update \
57+
illuminate/support:${{ matrix.laravel }} \
58+
orchestra/testbench:${{ matrix.testbench }}
59+
composer update --prefer-dist --no-interaction --no-progress --with-all-dependencies
60+
61+
- name: Run tests
62+
run: composer test

tests/RoutesTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Binkode\Paystack\Tests;
4+
5+
use Binkode\Paystack\Http\Controllers\HookController;
6+
use Binkode\Paystack\Http\Controllers\TransactionController;
7+
use Illuminate\Routing\Route;
8+
9+
class RoutesTest extends TestCase
10+
{
11+
public function test_transaction_list_route_is_registered(): void
12+
{
13+
$route = $this->findRouteByAction(TransactionController::class . '@list');
14+
15+
$this->assertInstanceOf(Route::class, $route);
16+
$this->assertContains('GET', $route->methods());
17+
}
18+
19+
public function test_hook_route_is_registered(): void
20+
{
21+
$route = $this->findRouteByAction(HookController::class . '@hook');
22+
23+
$this->assertInstanceOf(Route::class, $route);
24+
$this->assertStringContainsString('hooks', $route->uri());
25+
$this->assertContains('POST', $route->methods());
26+
}
27+
28+
private function findRouteByAction(string $action): ?Route
29+
{
30+
foreach ($this->app['router']->getRoutes() as $route) {
31+
if ($route->getActionName() === $action) {
32+
return $route;
33+
}
34+
}
35+
36+
return null;
37+
}
38+
}

tests/ServiceProviderTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Binkode\Paystack\Tests;
4+
5+
use Binkode\Paystack\Facades\Paystack as PaystackFacade;
6+
use Binkode\Paystack\Http\Middleware\DisabledRoute;
7+
use Binkode\Paystack\Http\Middleware\ValidatePaystackHook;
8+
use Binkode\Paystack\Paystack;
9+
use Binkode\Paystack\PaystackConfig;
10+
11+
class ServiceProviderTest extends TestCase
12+
{
13+
public function test_paystack_service_is_bound_as_singleton(): void
14+
{
15+
$first = $this->app->make('paystack');
16+
$second = $this->app->make('paystack');
17+
18+
$this->assertInstanceOf(Paystack::class, $first);
19+
$this->assertSame($first, $second);
20+
}
21+
22+
public function test_facade_resolves_the_paystack_singleton(): void
23+
{
24+
$resolved = PaystackFacade::getFacadeRoot();
25+
26+
$this->assertInstanceOf(Paystack::class, $resolved);
27+
$this->assertSame($this->app->make('paystack'), $resolved);
28+
}
29+
30+
public function test_default_config_values_are_merged_and_accessible(): void
31+
{
32+
$this->assertSame('https://api.paystack.co', config('paystack.url'));
33+
$this->assertSame('api', config('paystack.route.prefix'));
34+
$this->assertSame(['paystack_route_disabled', 'api'], config('paystack.route.middleware'));
35+
$this->assertSame(config('paystack.route.prefix'), PaystackConfig::config('route.prefix'));
36+
}
37+
38+
public function test_route_middlewares_are_registered(): void
39+
{
40+
$middlewares = $this->app['router']->getMiddleware();
41+
42+
$this->assertArrayHasKey('paystack_route_disabled', $middlewares);
43+
$this->assertSame(DisabledRoute::class, $middlewares['paystack_route_disabled']);
44+
45+
$this->assertArrayHasKey('validate_paystack_hook', $middlewares);
46+
$this->assertSame(ValidatePaystackHook::class, $middlewares['validate_paystack_hook']);
47+
}
48+
}

0 commit comments

Comments
 (0)