laravel-nami-api/tests/Unit/BausteinTest.php

42 lines
1.0 KiB
PHP
Raw Normal View History

2022-03-04 01:56:03 +01:00
<?php
namespace Zoomyboy\LaravelNami\Tests\Unit;
use Zoomyboy\LaravelNami\Authentication\Auth;
use Zoomyboy\LaravelNami\Fakes\BausteinFake;
use Zoomyboy\LaravelNami\Nami;
use Zoomyboy\LaravelNami\NamiException;
use Zoomyboy\LaravelNami\Tests\TestCase;
class BausteinTest extends TestCase
{
public function setUp(): void
{
parent::setUp();
2022-03-11 20:20:00 +01:00
2022-03-04 01:56:03 +01:00
Auth::fake();
}
2022-03-11 20:20:00 +01:00
public function testGetAllCourses(): void
2022-03-04 01:56:03 +01:00
{
Auth::success(12345, 'secret');
app(BausteinFake::class)->fetches([['id' => 788, 'descriptor' => 'abc']]);
$courses = Nami::login(12345, 'secret')->courses();
$this->assertCount(1, $courses);
$this->assertEquals(788, $courses->first()->id);
$this->assertEquals('abc', $courses->first()->name);
}
2022-03-11 20:20:00 +01:00
public function testThrowExceptionWhenBausteinFetchingFails(): void
2022-03-04 02:01:00 +01:00
{
$this->expectException(NamiException::class);
Auth::success(12345, 'secret');
app(BausteinFake::class)->failsToFetch();
Nami::login(12345, 'secret')->courses();
}
2022-03-04 01:56:03 +01:00
}