update initializer

This commit is contained in:
Philipp Lang 2023-05-05 12:02:58 +02:00
parent 29c2ea738c
commit 6135fbec3f
4 changed files with 18 additions and 28 deletions
app/Initialize/Actions
packages
phpstan.neon
tests/Feature/Initialize

View File

@ -45,7 +45,7 @@ class InitializeAction
private Api $api;
public function handle(int $mglnr, string $password, int $groupId): void
public function handle(): void
{
foreach ($this->initializers as $initializer) {
app($initializer)->handle($this->api);
@ -74,38 +74,33 @@ class InitializeAction
];
}
public function asController(ActionRequest $request, NamiSettings $settings): RedirectResponse
public function asController(ActionRequest $request): RedirectResponse
{
$this->api = Nami::login($request->input('mglnr'), $request->input('password'));
$api = Nami::freshLogin($request->input('mglnr'), $request->input('password'));
if (!$this->api->hasGroup($request->input('group_id'))) {
if (!$api->hasGroup($request->input('group_id'))) {
throw ValidationException::withMessages(['nami' => 'Gruppierung nicht gefunden.']);
}
$settings->mglnr = $request->input('mglnr');
$settings->password = $request->input('password');
$settings->default_group_id = $request->input('group_id');
$settings->save();
$this->handle(
(int) $request->input('mglnr', 0),
(string) $request->input('password', ''),
(int) $request->input('group_id', 0)
);
$this->setApi((int) $request->input('mglnr'), $request->input('password'), (int) $request->input('group_id'));
$this->handle();
return redirect()->route('home')->success('Initialisierung beauftragt. Wir benachrichtigen dich per Mail wenn alles fertig ist.');
}
public function asCommand(Command $command, NamiSettings $settings): void
public function asCommand(Command $command): void
{
$mglnr = (int) $command->option('mglnr');
$password = $command->option('password');
$group = (int) $command->option('group');
$this->api = Nami::login($mglnr, $password);
$this->setApi((int) $command->option('mglnr'), $command->option('password'), (int) $command->option('group'));
$this->handle();
}
private function setApi(int $mglnr, string $password, int $groupId): void
{
$settings = app(NamiSettings::class);
$settings->mglnr = $mglnr;
$settings->password = $password;
$settings->default_group_id = $group;
$settings->default_group_id = $groupId;
$settings->save();
$this->handle((int) $mglnr, (string) $password, (int) $group);
$this->api = $settings->login();
}
}

@ -1 +1 @@
Subproject commit a41b190cc2509ee940967b6c108a557b0a9c5def
Subproject commit 75983ebb4bad205629b57e18915b2f15fa38e835

View File

@ -564,11 +564,6 @@ parameters:
count: 1
path: tests/Feature/Initialize/InitializeActionTest.php
-
message: "#^Call to an undefined method Mockery\\\\ExpectationInterface\\|Mockery\\\\HigherOrderMessage\\:\\:with\\(\\)\\.$#"
count: 1
path: tests/Feature/Initialize/InitializeActionTest.php
-
message: "#^Call to an undefined method Mockery\\\\ExpectationInterface\\|Mockery\\\\HigherOrderMessage\\:\\:once\\(\\)\\.$#"
count: 2

View File

@ -26,7 +26,7 @@ class InitializeActionTest extends TestCase
public function testItSetsSettingsBeforeRunningInitializer(): void
{
$this->withoutExceptionHandling()->login();
InitializeAction::partialMock()->shouldReceive('handle')->with(12345, 'secret', 185)->once()->andReturn(true);
InitializeAction::partialMock()->shouldReceive('handle')->andReturn(true);
Auth::success(12345, 'secret');
app(GroupFake::class)->fetches(null, [185 => ['name' => 'testgroup']]);