-
Notifications
You must be signed in to change notification settings - Fork 40
Docs ‐ Testing
Isaac Sai edited this page Jan 20, 2024
·
1 revision
If you prefer test driven development or writing test after implement your USSD application. Laravel USSD provides helper utilities to make testing simple.
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Sparors\Ussd\ContinuingMode;
use Sparors\Ussd\Ussd;
use App\Ussd\States\BeginningState;
use App\Ussd\States\ContinuingState;
final class AssestionTest extends TestCase
{
public function test_ussd_application()
{
Ussd::test(BeginningState::class, ContinuingMode::CONFIRM, now()->addMinute(), ContinuingState::class)
->additional(['foo' => 'bar'])
->actingAs('isaac')
->start()
->assertSee('In the Beginning')
->assertContextHas('foo')
->assertContextHas('foo', 'bar')
->assertContextHas('foo', fn ($value) => $value === 'bar')
->assertContextMissing('baz')
->assertRecordMissing('wow')
->timeout(now()->addMinutes(2))
->assertSee('In the Beginning')
->wait(now()->addSeconds(5))
->input('1')
->assertSee('Pick one...')
->assertSee('Foo')
->assertRecordHas('wow')
->input('#')
->assertSee('Pick one...')
->assertSee('Baz')
->actingAs('benjamin')
->assertSee('In the Beginning')
->input('1')
->assertSee('Pick one...')
->actingAs('isaac')
->input('1')
->assertSee('Tadaa...')
->actingAs('benjamin')
->input('1')
->assertRecordHas('wow')
->assertSee('Tadaa...')
->timeout()
->assertSee('In the beginning')
->input('1')
->assertSee('Pick one...')
->actingAs('isaac');
}
}