This commit is contained in:
philipp lang 2022-02-12 16:44:43 +01:00
parent d0b78d3120
commit 02e14eb723
6 changed files with 34 additions and 8 deletions

View File

@ -60,7 +60,7 @@ class Member extends Model
}
// ---------------------------------- Actions ----------------------------------
public function syncVersion($api): void
public function syncVersion(Api $api): void
{
$version = $api->group($this->group->nami_id)->member($this->nami_id)->version;

View File

@ -3,6 +3,7 @@
namespace App\Payment;
use App\Member\Member;
use App\Pdf\PdfRepository;
use App\Pdf\PdfRepositoryFactory;
use Illuminate\Support\Collection;
@ -11,9 +12,7 @@ class ActionFactory
public function forMember(Member $member): Collection
{
return app(PdfRepositoryFactory::class)->getTypes()->map(function(string $repo) use ($member) {
$repo = app($repo);
return app(PdfRepositoryFactory::class)->getTypes()->map(function(PdfRepository $repo) use ($member): array {
return [
'href' => route('member.singlepdf', ['member' => $member, 'type' => get_class($repo)]),
'label' => $repo->linkLabel(),
@ -24,9 +23,7 @@ class ActionFactory
public function allLinks(): Collection
{
return app(PdfRepositoryFactory::class)->getTypes()->map(function(string $repo) {
$repo = app($repo);
return app(PdfRepositoryFactory::class)->getTypes()->map(function(PdfRepository $repo) {
return [
'link' => [
'href' => route('sendpayment.pdf', ['type' => get_class($repo)]),

View File

@ -4,8 +4,11 @@ namespace App\Payment;
use App\Http\Controllers\Controller;
use App\Pdf\PdfGenerator;
use App\Pdf\PdfRepository;
use App\Pdf\PdfRepositoryFactory;
use Illuminate\Contracts\Support\Responsable;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Inertia\Inertia;
use Inertia\Response as InertiaResponse;
@ -22,6 +25,9 @@ class SendpaymentController extends Controller
]);
}
/**
* @return Response|Responsable
*/
public function send(Request $request)
{
$repo = app(PdfRepositoryFactory::class)->forAll($request->type, 'Post');

View File

@ -4,12 +4,16 @@ namespace App\Pdf;
use App\Http\Controllers\Controller;
use App\Member\Member;
use Illuminate\Contracts\Support\Responsable;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
class MemberPdfController extends Controller
{
/**
* @return Response|Responsable
*/
public function __invoke(Request $request, Member $member)
{
$repo = app(PdfRepositoryFactory::class)->fromSingleRequest($request->type, $member);

View File

@ -10,14 +10,20 @@ use Illuminate\Support\Str;
class PdfRepositoryFactory
{
/**
* @var array<int, class-string<PdfRepository>>
*/
private array $types = [
BillType::class,
RememberType::class,
];
/**
* @return Collection<int, PdfRepository>
*/
public function getTypes(): Collection
{
return collect($this->types);
return collect(array_map(fn ($classString) => new $classString, $this->types));
}
public function fromSingleRequest(string $type, Member $member): ?PdfRepository

View File

@ -7,6 +7,13 @@ use PHPUnit\Framework\Assert as PHPUnit;
trait TestsInertia {
/**
* @param mixed $value
* @param TestResponse $response
* @param ?string $key
*
* @return void
*/
public function assertInertiaHas($value, TestResponse $response, ?string $key = null): void
{
$bindings = json_decode(json_encode($value), true);
@ -23,6 +30,12 @@ trait TestsInertia {
PHPUnit::assertEquals($component, $response->viewData('page')['component']);
}
/**
* @param mixed $should
* @param mixed $is
*
* @return void
*/
public function assertInertiaDeepNest($should, $is): void
{
foreach ($should as $key => $value) {