Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#60 - add getuser helper #65

Merged
merged 7 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Features/Traits/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Blumilk\BLT\Features\Traits;

use Behat\Gherkin\Node\TableNode;
use Blumilk\BLT\Helpers\GetUserHelper;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Container\BindingResolutionException;
use PHPUnit\Framework\Assert;
Expand All @@ -21,7 +22,8 @@ trait Authentication
public function userIsAuthenticatedInSessionAs(string $value, string $field): void
{
$auth = $this->getContainer()->make(Guard::class);
$auth->login($this->getUserModel()::query()->where($field, $value)->first());
$user = GetUserHelper::getUser($field, $value);
$auth->login($user);
}

/**
Expand Down
15 changes: 15 additions & 0 deletions src/Helpers/GetUserHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Blumilk\BLT\Helpers;

class GetUserHelper
krzysztofrewak marked this conversation as resolved.
Show resolved Hide resolved
{
public static function getUser(string $field, string $value): object
JakubKermes marked this conversation as resolved.
Show resolved Hide resolved
{
$userClass = RecognizeClassHelper::recognizeObjectClass("User");

return $userClass::query()->where($field, $value)->first();
}
}
Loading