Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

Commit

Permalink
Request test added
Browse files Browse the repository at this point in the history
  • Loading branch information
prinx committed Jul 29, 2020
1 parent 66a9303 commit 988f2c4
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 44 deletions.
3 changes: 1 addition & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
APP_ENV=dev
APP_URL=
APP_URL=
SMS_ENDPOINT=

SESSION_DRIVER=file
Expand All @@ -20,7 +19,7 @@ APP_DEFAULT_DB_NAME=
USSD_URL=${APP_URL}
USSD_PHONE=
USSD_NETWORK_MNC=
USSD_CODE=""
USSD_CODE=
USSD_CONSOLE_BEHAVIOR=

REQUIRED_PARAM_NAME_MENU_STRING=message
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
colors="true"
>
<testsuites>
<testsuite name="Rejoice">
<directory suffix="Test.php">./tests</directory>
</testsuite>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
Expand Down
39 changes: 39 additions & 0 deletions tests/RejoiceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Tests\Unit;

use function Prinx\Dotenv\env;
use PHPUnit\Framework\TestCase;
use Prinx\Config;
use Prinx\Simulator\Libs\Simulator;

class RejoiceTest extends TestCase
{
public function testRequest()
{
$simulator = new Simulator;
$config = new Config(__DIR__ . '/../config/');

$phoneNumber = $config->get('app.request_param_user_phone_number');
$network = $config->get('app.request_param_user_network');
$sessionId = $config->get('app.request_param_session_id');
$ussdServiceOp = $config->get('app.request_param_request_type');
$menuString = $config->get('app.request_param_user_response');

$simulator->setPayload([
$phoneNumber => env('USSD_PHONE', '+000123456789'),
$network => env('USSD_NETWORK_MNC', '00'),
$sessionId => rand(1000000, 1999999),
$ussdServiceOp => '1',
$menuString => env('USSD_CODE', '*380*57#'),
]);

$simulator->setEndpoint(env('APP_URL', 'http://localhost/rejoice/public/index.php'));
$response = $simulator->callUssd();
$data = json_decode($response->data('data'), true);

$this->assertTrue(is_array($data), 'Test USSD request successful');
$this->assertTrue("2" == $data[$ussdServiceOp]);
$this->assertTrue($simulator->getPayload()[$sessionId] == $data[$sessionId]);
}
}
43 changes: 1 addition & 42 deletions tests/Unit/ExampleUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,11 @@
namespace Tests\Unit;

use PHPUnit\Framework\TestCase;
use Prinx\Arr;

/**
* @todo The tests need works
*/
class EnvTest extends TestCase
class ExampleTest extends TestCase
{
public function testExample()
{
$config = $this->loadConfig();

$this->assertEquals(Arr::multiKeyGet('app.paginate_forward_display', $config), 'More');
$this->assertEquals(Arr::multiKeyGet('app.paginate_forward_display', $config), 'More');
$this->assertTrue(1 === 1);
}

public function testParseEnv()
{
$this->env = $this->parseEnv();
$this->assertTrue('dev' === $this->env['APP_ENV']);
}

public function parseEnv()
{

}

public function loadConfig()
{
$directory = new \DirectoryIterator(realpath(__DIR__ . '/../../config/'));

$iterator = new \IteratorIterator($directory);
$files = [];

foreach ($iterator as $info) {
$filename = $info->getFileName();

if ('.' === $filename || '..' === $filename) {
continue;
}

$name = substr($filename, 0, strlen($filename) - strlen('.php'));

$files[$name] = require $info->getPathname();
}

return $files;
}
}

0 comments on commit 988f2c4

Please sign in to comment.