Add: Output errors to console when nami error occurs

This commit is contained in:
philipp lang 2022-02-19 22:50:06 +01:00
parent c7ba48134b
commit 43f68b5765
4 changed files with 28 additions and 4 deletions

View File

@ -5,6 +5,7 @@ namespace App\Console\Commands;
use App\Initialize\Initializer;
use Illuminate\Console\Command;
use Zoomyboy\LaravelNami\Nami;
use Zoomyboy\LaravelNami\NamiException;
class NamiInitializeCommand extends Command
{
@ -39,7 +40,12 @@ class NamiInitializeCommand extends Command
*/
public function handle()
{
try {
app(Initializer::class)->run();
} catch (NamiException $e) {
$e->outputToConsole($this);
return 1;
}
return 0;
}

@ -1 +1 @@
Subproject commit 8515b1fc05999c4b91579934b7da287e0d60fb06
Subproject commit 423fb27f51e322b42fa3b2a01b1bafd886f514fe

View File

@ -124,7 +124,7 @@ class StoreTest extends TestCase
$this->login()->loginNami();
$member = Member::factory()->defaults()->inNami(123)->createOne();
$course = Course::factory()->inNami(456)->createOne();
app(CourseFake::class)->doesntCreateWithError(123);
app(CourseFake::class)->createFailed(123);
$response = $this->post("/member/{$member->id}/course", [
'course_id' => $course->id,

View File

@ -3,6 +3,7 @@
namespace Tests\Feature\Initialize;
use App\Activity;
use App\Console\Commands\NamiInitializeCommand;
use App\Country;
use App\Course\Models\Course;
use App\Gender;
@ -18,6 +19,8 @@ use Illuminate\Support\Facades\Http;
use Tests\TestCase;
use Zoomyboy\LaravelNami\Backend\FakeBackend;
use Zoomyboy\LaravelNami\Fakes\GroupFake;
use Zoomyboy\LaravelNami\Fakes\MemberFake;
use Zoomyboy\LaravelNami\Fakes\SearchFake;
class InitializeTest extends TestCase
{
@ -128,7 +131,7 @@ class InitializeTest extends TestCase
$this->initializeProvider();
GeneralSettings::fake(['allowed_nami_accounts' => [123]]);
Artisan::call('nami:initialize');
Artisan::call(NamiInitializeCommand::class);
$this->assertDatabaseHas('regions', [
'name' => 'nrw',
@ -413,6 +416,21 @@ class InitializeTest extends TestCase
$this->assertDatabaseCount('members', $num);
}
public function testRenderErrorInConsoleWhenUsingArtisan(): void
{
$this->withoutExceptionHandling()->login()->loginNami();
$this->initializeProvider(function($backend) {
app(SearchFake::class)->fetchFails($page = 1, $start = 0, 'search error');
});
$this->login();
$command = $this->artisan(NamiInitializeCommand::class);
$command->assertFailed();
$command->expectsOutput('response: {"success":false,"message":"search error"}');
$command->expectsOutput('Search failed');
}
/**
* @param array<string, mixed> $overwrites
* @return array<string, mixed>