laravel-nami-api/src/Fakes/CourseFake.php

40 lines
1.4 KiB
PHP
Raw Normal View History

2021-11-19 22:58:42 +01:00
<?php
namespace Zoomyboy\LaravelNami\Fakes;
use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Http;
class CourseFake extends Fake {
public function createsSuccessful(int $memberId, int $courseId): void
{
Http::fake(function($request) use ($memberId, $courseId) {
if ($request->url() === "https://nami.dpsg.de/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}") {
return Http::response([
'data' => $courseId,
'responseType' => 'OK',
'success' => true,
], 200);
}
});
}
/**
* @param int $memberId
* @param array<string, mixed> $payload
*/
public function assertCreated(int $memberId, array $payload): void
{
Http::assertSent(function($request) use ($memberId, $payload) {
return $request->url() === "https://nami.dpsg.de/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}"
&& $request->method() === 'POST'
&& data_get($request, 'bausteinId') === $payload['bausteinId']
&& data_get($request, 'veranstalter') === $payload['veranstalter']
// && data_get($request, 'vstgName') === $payload['vstgName']
&& data_get($request, 'vstgTag') === $payload['vstgTag'];
});
}
}