Skip to content

Commit

Permalink
#80 - add codeblocks (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubKermes authored Jul 27, 2024
1 parent c4ef6d5 commit 178b385
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/Features/Traits/Common.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace Blumilk\BLT\Features\Traits;

use Behat\Gherkin\Node\TableNode;
use Blumilk\BLT\Features\Traits\Optional\SpatiePermission;
use Symfony\Component\HttpFoundation\Response;

trait Common
{
use Eloquent;
use SpatiePermission;
use Authentication;
use Http;

/**
* @Given user is in session as admin
* @Given user in session has role :role
*/
public function sessionHasUserWithRole(string $role = "admin"): void
{
$roleArray = [
["name", $role],
];
$roleTable = new TableNode($roleArray);
$this->seedModelInTheDatabase("Role", $roleTable);
$userArray = [
["name", $role],
["email", "[email protected]"],
["password", "password123!@#"],
];
$userTable = new TableNode($userArray);
$this->seedModelInTheDatabase("User", $userTable);

$this->assignRoleTo($role, "User", "[email protected]", "email");

$this->userIsAuthenticatedInSessionAs($role, "name");
}

/**
* @Given admin user is getting OK response from :url
* @Given admin user is getting :status status code response from :url
* @Given user with :role role is getting OK response from :url
* @Given user with :role role is getting :status response from :url
* @Given user with :role role is getting OK response from :url using :method method
* @Given user with :role role is getting :status response from :url using :method method
*/
public function adminUserIsGettingResponse(string $url, string $method = "GET", int $status = Response::HTTP_OK, string $role = "admin"): void
{
$this->sessionHasUserWithRole($role);
$this->aUserIsRequesting($url, $method);
$this->aRequestIsSent();
$this->aResponseShouldHaveStatus($status);
}
}

0 comments on commit 178b385

Please sign in to comment.