-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Combine HttpRequest, HttpResponse, Session, Authentication into Routing trait * removal of unnecessary functions * Added accessing routes * Login route * endpoinst from config * csf * uri * Added function for router methods * Naming fix * small fixes * Added a documentation about routing * csf * Fixes from code review Added missing Routing in Overview section Sorted alphabetically Fixes bug with stretching content
- Loading branch information
1 parent
f606fe8
commit f50c831
Showing
8 changed files
with
221 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<article-header>Routing</article-header> | ||
|
||
<article-paragraphs> | ||
<p> | ||
Use <br> | ||
<code class="text-sky-600">Blumilk\BLT\Features\Routing</code> context <br> | ||
or add <br> | ||
<code class="text-sky-600">Blumilk\BLT\Features\Traits\Routing</code> trait to test your application's routing features. | ||
</p> | ||
</article-paragraphs> | ||
|
||
<section-header>Routing Methods</section-header> | ||
<article-paragraphs> | ||
<p> | ||
The <code>Routing</code> trait provides several methods to handle routing operations within your Laravel application. These methods help ensure that your application's routes are correctly set up and functioning for testing purposes. | ||
</p> | ||
</article-paragraphs> | ||
|
||
<article-paragraphs> | ||
<p> | ||
This snippet simulates a user accessing a named route, allowing you to test route access and response handling. | ||
</p> | ||
</article-paragraphs> | ||
<code-snippet | ||
gherkin="Given user is accessing route named :routeName" | ||
php=" | ||
/** | ||
* @Given user is accessing route named :routeName | ||
*/ | ||
public function userIsAccessingRouteNamed(string $routeName): void"></code-snippet> | ||
|
||
<article-paragraphs> | ||
<p> | ||
The <code>routeShouldExist</code> method verifies the existence of a specified route. This is useful for ensuring that routes are correctly registered in your application. | ||
</p> | ||
</article-paragraphs> | ||
|
||
<code-snippet | ||
gherkin="Then the route :routeName should exist" | ||
php=" | ||
/** | ||
* @Then the route :routeName should exist | ||
*/ | ||
public function routeShouldExist(string $routeName, Router $router): void"></code-snippet> | ||
|
||
<article-paragraphs> | ||
<p> | ||
The <code>userShouldBeRedirectedToRouteNamed</code> method checks if the user is redirected to a specified named route. This ensures that route redirections are functioning correctly. | ||
</p> | ||
</article-paragraphs> | ||
|
||
<code-snippet | ||
gherkin="Then the user should be redirected to the route named :routeName" | ||
php=" | ||
/** | ||
* @Then the user should be redirected to the route named :routeName | ||
*/ | ||
public function userShouldBeRedirectedToRouteNamed(string $routeName, Router $router): void"></code-snippet> | ||
|
||
<article-paragraphs> | ||
<p> | ||
The <code>responseShouldContainJsonWithKeyAndValue</code> method ensures that the response contains JSON with a specified key and value, useful for validating API responses. | ||
</p> | ||
</article-paragraphs> | ||
|
||
<code-snippet | ||
gherkin="Then the response should contain JSON with key :key and value :value" | ||
php=" | ||
/** | ||
* @Then the response should contain JSON with key :key and value :value | ||
*/ | ||
public function responseShouldContainJsonWithKeyAndValue(string $key, string $value): void"></code-snippet> | ||
|
||
<article-paragraphs> | ||
<p> | ||
The <code>responseShouldHaveStatusAndContainJson</code> method verifies that the response has a specific status and contains JSON with a specified key and value. | ||
</p> | ||
</article-paragraphs> | ||
|
||
<code-snippet | ||
gherkin="Then the response should have status :status and contain JSON with key :key and value :value" | ||
php=" | ||
/** | ||
* @Then the response should have status :status and contain JSON with key :key and value :value | ||
*/ | ||
public function responseShouldHaveStatusAndContainJson(int $status, string $key, string $value): void"></code-snippet> | ||
|
||
<article-paragraphs> | ||
<p> | ||
The <code>routeShouldExistWithMethods</code> method verifies that a route supports the specified HTTP methods. This is useful for ensuring routes handle different HTTP verbs as expected. | ||
</p> | ||
</article-paragraphs> | ||
|
||
<code-snippet | ||
gherkin="Then the route :routeName should exist with the following methods: | ||
| method | | ||
| GET | | ||
| POST |" | ||
php=" | ||
/** | ||
* @Then the route :routeName should exist with the following methods: | ||
*/ | ||
public function routeShouldExistWithMethods(string $routeName, TableNode $methodsTable): void"></code-snippet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Blumilk\BLT\Features; | ||
|
||
use Behat\Behat\Context\Context; | ||
use Blumilk\BLT\Features\Traits\Routing as RoutingTrait; | ||
|
||
class Routing implements Context | ||
{ | ||
use RoutingTrait; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Blumilk\BLT\Features\Traits; | ||
|
||
use Behat\Gherkin\Node\TableNode; | ||
use Illuminate\Contracts\Routing\Registrar; | ||
use Illuminate\Routing\Router; | ||
use PHPUnit\Framework\Assert; | ||
|
||
trait Routing | ||
{ | ||
use HttpRequest; | ||
use HttpResponse; | ||
use Session; | ||
use Application; | ||
|
||
/** | ||
* @Given user is accessing route named :routeName | ||
*/ | ||
public function userIsAccessingRouteNamed(string $routeName): void | ||
{ | ||
$router = $this->getContainer()->make(Registrar::class); | ||
$route = $router->getRoutes()->getByName($routeName); | ||
$uri = $route ? $route->uri() : "/" . $routeName; | ||
$uri = config("blt.endpoints.$routeName", $uri); | ||
|
||
Assert::assertNotNull($uri, "Route $routeName does not exist."); | ||
$this->aUserIsRequesting($uri); | ||
$this->aRequestIsSent(); | ||
} | ||
|
||
/** | ||
* @Then the route :routeName should exist | ||
*/ | ||
public function routeShouldExist(string $routeName, Router $router): void | ||
{ | ||
$routeExists = $router->has($routeName); | ||
Assert::assertTrue($routeExists, "Route $routeName does not exist."); | ||
} | ||
|
||
/** | ||
* @Then the user should be redirected to the route named :routeName | ||
*/ | ||
public function userShouldBeRedirectedToRouteNamed(string $routeName, Router $router): void | ||
{ | ||
$expectedUri = $router->url()->route($routeName); | ||
$actualUri = $this->response->headers->get("Location"); | ||
Assert::assertEquals($expectedUri, $actualUri, "User was not redirected to the route $routeName."); | ||
} | ||
|
||
/** | ||
* @Then the response should contain JSON with key :key and value :value | ||
*/ | ||
public function responseShouldContainJsonWithKeyAndValue(string $key, string $value): void | ||
{ | ||
$json = json_decode($this->response->getContent(), true); | ||
Assert::assertEquals($value, data_get($json, $key)); | ||
} | ||
|
||
/** | ||
* @Then the response should have status :status and contain JSON with key :key and value :value | ||
*/ | ||
public function responseShouldHaveStatusAndContainJson(int $status, string $key, string $value): void | ||
{ | ||
$this->aResponseStatusCodeShouldBe($status); | ||
$this->responseShouldContainJsonWithKeyAndValue($key, $value); | ||
} | ||
|
||
/** | ||
* @Then the route :routeName should exist with the following methods: | ||
*/ | ||
public function routeShouldExistWithMethods(string $routeName, TableNode $methodsTable): void | ||
{ | ||
$router = $this->getContainer()->make(Router::class); | ||
$route = $router->getRoutes()->getByName($routeName); | ||
Assert::assertNotNull($route, "Route $routeName does not exist."); | ||
|
||
$supportedMethods = $route->methods(); | ||
|
||
foreach ($methodsTable as $row) { | ||
$method = strtoupper($row["method"]); | ||
Assert::assertContains($method, $supportedMethods, "Route $routeName does not support the method $method."); | ||
} | ||
} | ||
} |