Skip to content

Commit

Permalink
Try github actions for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
cybersai committed Dec 20, 2023
1 parent ac7088d commit 10e23ec
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 9 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: PHP Composer

on:
push:
branches: [ "3.x" ]
pull_request:
branches: [ "3.x" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run test suite
run: composer run-script test
26 changes: 26 additions & 0 deletions me.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Laravel Ussd
*
* Build Ussd (Unstructured Supplementary Service Data) applications with Laravel without breaking a sweat.
*
* @package Laravel Ussd
* @version 3.0.0
* @author Sparors
* @link https://sparors.github.io/ussd-docs/
*
* @see https://packagist.org/packages/sparors/laravel-ussd
* @see https://travis-ci.com/sparors/laravel-ussd
*
* @license MIT
*/
# Laravel Ussd

[![Latest Version on Packagist][ico-version]][link-packagist]
[![Total Downloads][ico-downloads]][link-downloads]
[![Build Status][ico-travis]][link-travis]

Build Ussd (Unstructured Supplementary Service Data) applications with Laravel without breaking a sweat.

## Installation

You can install the package via composer:
30 changes: 27 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ namespace App\Http\Controllers;

use Sparors\Ussd\Facades\Ussd;
use App\Http\Ussd\States\Welcome;
use App\Http\Ussd\Configurators\Nsano'
use App\Http\Ussd\Configurators\Nsano;

// Using it in a controller
class UssdController extends Controller
Expand All @@ -257,8 +257,32 @@ You'll find the documentation on [https://sparors.github.io/ussd-docs](https://s

### Testing

``` bash
$ vendor/bin/phpunit
You can easily test how your ussd application will respond to user input

``` php
<?php

namespace App\Tests\Feature;

use Sparors\Ussd\Ussd;

final class UssdTest extends TestCase
{
public function test_ussd_runs()
{
Ussd::test(WelcomeState::class)
->additional(['network' => 'MTN', 'phone_number' => '123123123'])
->actingAs('isaac')
->start()
->assertSee('Welcome...')
->assertContextHas('network', 'MTN')
->assertContextHas('phone_number')
->assertContextMissing('name')
->input('1')
->assertSee('Now see the magic...')
->assertRecordHas('choice');
}
}
```

### Change log
Expand Down
8 changes: 8 additions & 0 deletions src/Contracts/InitialAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Sparors\Ussd\Contracts;

interface InitialAction extends Action
{

}
3 changes: 2 additions & 1 deletion src/Tests/PendingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Sparors\Ussd\Contracts\InitialState;
use Sparors\Ussd\Contracts\ContinueState;
use Sparors\Ussd\Contracts\ExceptionHandler;
use Sparors\Ussd\Contracts\InitialAction;

class PendingTest
{
Expand All @@ -23,7 +24,7 @@ class PendingTest
private ?Closure $exceptionHandler;

public function __construct(
private string|InitialState $initialState,
private string|InitialState|InitialAction $initialState,
private int $continuingMode = ContinuingMode::START,
private null|int|DateInterval|DateTimeInterface $continuingTtl = null,
private null|string|ContinueState $continuingState = null
Expand Down
3 changes: 2 additions & 1 deletion src/Tests/Testing.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Sparors\Ussd\Contracts\ExceptionHandler;
use PHPUnit\Framework\Assert;
use Sparors\Ussd\Context;
use Sparors\Ussd\Contracts\InitialAction;
use Sparors\Ussd\Record;
use Sparors\Ussd\Ussd;

Expand All @@ -25,7 +26,7 @@ class Testing
private array $actors;

public function __construct(
private string|InitialState $initialState,
private string|InitialState|InitialAction $initialState,
private int $continuingMode,
private null|int|DateInterval|DateTimeInterface $continuingTtl,
private null|string|ContinueState $continuingState,
Expand Down
9 changes: 5 additions & 4 deletions src/Ussd.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Sparors\Ussd\Contracts\Configurator;
use Sparors\Ussd\Contracts\ContinueState;
use Sparors\Ussd\Contracts\ExceptionHandler;
use Sparors\Ussd\Contracts\InitialAction;
use Sparors\Ussd\Contracts\InitialState;
use Sparors\Ussd\Exceptions\NextStateNotFoundException;
use Sparors\Ussd\Tests\PendingTest;
Expand All @@ -33,9 +34,9 @@ class Ussd
private Context $context;
private ?string $storeName;
private int $continuingMode;
private InitialState $initialState;
private Response|Closure $response;
private ?ContinueState $continuingState;
private InitialState|InitialAction $initialState;
private null|int|DateInterval|DateTimeInterface $continuingTtl;
private ExceptionHandler|Closure $exceptionHandler;

Expand Down Expand Up @@ -89,16 +90,16 @@ public function useConfigurator(Configurator|string $configurator): static
return $this;
}

public function useInitialState(string|InitialState $initialState)
public function useInitialState(string|InitialState|InitialAction $initialState)
{
if (is_string($initialState) && class_exists($initialState)) {
$initialState = App::make($initialState);
}

throw_unless(
$initialState instanceof InitialState,
$initialState instanceof InitialState || $initialState instanceof InitialAction,
InvalidArgumentException::class,
"Initial state should implement ".InitialState::class
"Initial state should implement ".InitialState::class." or ".InitialAction::class
);

$this->initialState = $initialState;
Expand Down

0 comments on commit 10e23ec

Please sign in to comment.