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

#73 - test documentation #75

Merged
merged 56 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
aed87a0
#17 - documentation draft
krzysztofrewak Jun 28, 2024
45e710f
Merge branch 'main' into docs
PiotrFedak Jul 1, 2024
d17d2f0
Marking where you are in the documentation, added img, started to cre…
PiotrFedak Jul 1, 2024
bde6054
Added toggle between php and Gherkin, also small fixes
PiotrFedak Jul 2, 2024
1f0ab67
add documentation for general section
JakubKermes Jul 2, 2024
171fff3
add documentation Authentication.php
JakubKermes Jul 2, 2024
400785c
add rest of the documentation
JakubKermes Jul 3, 2024
4023347
listed out included traits
JakubKermes Jul 3, 2024
eb4fd4e
Added highlighting, fix link error, faq page
PiotrFedak Jul 3, 2024
0157834
Merge branch 'main' into docs
PiotrFedak Jul 3, 2024
6f32d84
node modules to gitignore
PiotrFedak Jul 3, 2024
9ac796d
delete node files that wasn't supposed to be on github
PiotrFedak Jul 3, 2024
394488a
removed function, can be done using Eloquent.php
JakubKermes Jul 3, 2024
7210f1b
copy to clipboard and fixes
PiotrFedak Jul 3, 2024
9f487ca
add missing documentation elements
JakubKermes Jul 3, 2024
fa246db
add test draft
JakubKermes Jul 3, 2024
55954bc
fix documentation sidebar
JakubKermes Jul 3, 2024
06666d6
Convert to cdn
PiotrFedak Jul 3, 2024
e61dfa0
add helpers section
JakubKermes Jul 4, 2024
9f4ff99
text color change
PiotrFedak Jul 4, 2024
068c0cb
Added context classes vs traits
PiotrFedak Jul 5, 2024
31254fe
make test prettier
JakubKermes Jul 5, 2024
07cc45b
Merge branch 'main' into #73-test-documentation
JakubKermes Jul 5, 2024
7d7c28a
fix documentation for http
JakubKermes Jul 5, 2024
ba15318
add missing documentation for view
JakubKermes Jul 5, 2024
2365928
Merge branch 'refs/heads/docs' into #73-test-documentation
JakubKermes Jul 5, 2024
e08cd02
Merge branch 'docs' into #73-test-documentation
JakubKermes Jul 5, 2024
5eb562f
Merge remote-tracking branch 'origin/#73-test-documentation' into #73…
JakubKermes Jul 5, 2024
1a2e3fb
formatting
JakubKermes Jul 5, 2024
fe3620b
Apply suggestions from code review
PiotrFedak Jul 5, 2024
3d25eb2
Merge branch 'docs' into #73-test-documentation
JakubKermes Jul 5, 2024
9e07ed3
format list
JakubKermes Jul 5, 2024
85467cf
Merge remote-tracking branch 'origin/docs' into docs
JakubKermes Jul 5, 2024
7b57c2c
FAQ fix
PiotrFedak Jul 5, 2024
0c7cb01
Merge branch 'docs' of https://github.com/blumilksoftware/blt into docs
PiotrFedak Jul 5, 2024
963cab6
translation, dispatcher and database fix
PiotrFedak Jul 5, 2024
073b689
change namespace styling
JakubKermes Jul 5, 2024
37d3c3e
Merge remote-tracking branch 'origin/docs' into docs
JakubKermes Jul 5, 2024
34eaa59
Merge branch 'refs/heads/docs' into #73-test-documentation
JakubKermes Jul 5, 2024
ebd159d
change namespace styling
JakubKermes Jul 5, 2024
7752da7
toast for clipboard
PiotrFedak Jul 5, 2024
a4632b0
Code review changes. Icon for commands, new line and spelling mistake
PiotrFedak Jul 8, 2024
697a109
Added lines at the end of the file
PiotrFedak Jul 8, 2024
0ae5bcf
custom Higlight
PiotrFedak Jul 8, 2024
2ccc43c
Merge branch 'docs' into #73-test-documentation
JakubKermes Jul 8, 2024
84c7e64
Merge branch 'refs/heads/main' into #73-test-documentation
JakubKermes Jul 9, 2024
a2fdf56
small fixes
JakubKermes Jul 9, 2024
cd97cb6
csf
JakubKermes Jul 9, 2024
f98dffd
suggested changes
JakubKermes Jul 9, 2024
d0a6583
Merge remote-tracking branch 'refs/remotes/origin/main' into #73-test…
JakubKermes Jul 9, 2024
2912a7f
better handling for filenames, add cookies.html
JakubKermes Jul 9, 2024
72f0854
fix coloring code
JakubKermes Jul 9, 2024
c7dad78
clearer looking DocumentationTest.php
JakubKermes Jul 10, 2024
2872a80
add hooks to documentation
JakubKermes Jul 10, 2024
d9730d2
suggested changes
JakubKermes Jul 19, 2024
68154fa
add hooks testing
JakubKermes Jul 27, 2024
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
49 changes: 49 additions & 0 deletions docs/elements/common.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<article-header>Common</article-header>

<article-paragraphs>
<p>
Add <br>
<code class="text-sky-600">Blumilk\BLT\Features\Traits\Common</code> trait to use ready complex functions from Common.
</p>
</article-paragraphs>

<section-header>Authentication Checks and Operations</section-header>
<article-paragraphs>
<p>
The <code>Common</code> trait provides several methods to manage and verify authentication states for
various objects within your Laravel application. These methods ensure that your application's authentication
features are functioning as expected.
</p>
</article-paragraphs>

<article-paragraphs>
<p>
This snippet authenticates a user by a specified value in a given field and logs them into the session.
</p>
</article-paragraphs>
<code-snippet
gherkin="Given user is authenticated in session as '[email protected]' in email field"
php="
/**
* @Given user is in session as admin
* @Given user in session has role :role
*/
public function sessionHasUserWithRole(string $role = 'admin'): void"></code-snippet>

<article-paragraphs>
<p>
This snippet authenticates a user by a specified value in a given field and logs them into the session.
</p>
</article-paragraphs>
<code-snippet
gherkin="Given admin user is getting OK response from '/dashboard'"
php="
/**
* @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"></code-snippet>
104 changes: 104 additions & 0 deletions docs/elements/console.html
Original file line number Diff line number Diff line change
@@ -1 +1,105 @@
<article-header>Console</article-header>

<article-paragraphs>
<p>
Use <br>
<code class="text-sky-600">Blumilk\BLT\Features\Console</code> context <br>
or add <br>
<code class="text-sky-600">Blumilk\BLT\Features\Traits\Console</code> trait to test your application's
console features.
</p>
</article-paragraphs>

<section-header>Console Methods</section-header>
<article-paragraphs>
<p>
The <code>Console</code> trait provides several methods to handle console commands within your Laravel application. These methods help ensure that your application's command-line interface is functioning as expected and can be tested effectively.
</p>
</article-paragraphs>

<article-paragraphs>
<p>
This snippet runs a specified Artisan command. It allows you to test scenarios where specific console commands need to be executed.
<br>
You can specify the command to run and capture its output and exit code.
</p>
</article-paragraphs>
<code-snippet gherkin="Given a command 'blt:init' is ran" php="
/**
* @Given a command :command is ran
* @Given a command :command is ran in console
* @throws BindingResolutionException
*/
public function runArtisanCommand(string $command): void
"></code-snippet>

<article-paragraphs>
<p>
The <code>runCommandWithOptionsAndArguments</code> method runs a specified Artisan command with options and arguments provided in a table. This is useful for testing scenarios where commands require additional parameters.
</p>
</article-paragraphs>

<code-snippet gherkin="Given a command 'make:notification' is ran with:
| argument | NoParamsNotification |
| option | force |" php="
/**
* @Given a command :command is ran with:
* @throws BindingResolutionException
*/
public function runCommandWithOptionsAndArguments(string $command, TableNode $table): void
"></code-snippet>

<article-paragraphs>
<p>
The <code>seeInConsole</code> method verifies that the console output contains a specified string. This is useful for ensuring that the command's output includes expected messages or results.
</p>
</article-paragraphs>

<code-snippet gherkin="Then console output contains 'created successfully'"
php="
/**
* @Then console output contains :output
* @Then console output should contain :output
*/
public function seeInConsole(string $output): void
"></code-snippet>

<article-paragraphs>
<p>
The <code>consoleOutputIsNotEmpty</code> method verifies that the console output is not empty. This is useful for ensuring that the command produces output.
</p>
</article-paragraphs>

<code-snippet gherkin="Then console output is not empty" php="
/**
* @Then console output is not empty
*/
public function consoleOutputIsNotEmpty(): void
"></code-snippet>

<article-paragraphs>
<p>
The <code>consoleOutputIsEmpty</code> method verifies that the console output is empty. This is useful for ensuring that the command produces no output.
</p>
</article-paragraphs>

<code-snippet gherkin="Then console output is empty" php="
/**
* @Then console output is empty
*/
public function consoleOutputIsEmpty(): void
"></code-snippet>

<article-paragraphs>
<p>
The <code>consoleExitCodeIs</code> method verifies that the console exit code matches the expected code. This is useful for ensuring that the command exits with the correct status.
</p>
</article-paragraphs>

<code-snippet gherkin="Then console exit code is 0" php="
/**
* @Then console exit code is :code
* @Then console exit code should be :code
*/
public function consoleExitCodeIs(int $code): void
"></code-snippet>
106 changes: 106 additions & 0 deletions docs/elements/cookies.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<article-header>Cookies</article-header>
<article-paragraphs>
<p>
Use <br>
<code class="text-sky-600">Blumilk\BLT\Features\Cookies</code> context <br>
or add <br>
<code class="text-sky-600">Blumilk\BLT\Features\Traits\Cookies</code> trait to test your application's cookie features.
</p>
</article-paragraphs>

<section-header>Cookies Methods</section-header>
<article-paragraphs>
<p>
The <code>Cookies</code> trait provides several methods to handle cookie operations within your Laravel application. These methods help ensure that your application's cookies are correctly set up and managed for testing purposes.
</p>
</article-paragraphs>
<article-paragraphs>
<p>
This snippet sets a cookie with a specified name and value. It allows you to simulate setting cookies in your application.
</p>
</article-paragraphs>
<code-snippet
gherkin="When cookie :name with value :value is set"
php="
/**
* @When cookie :name with value :value is set
* @When cookie named :name with value :value is created
* @When cookie :name with value :value is added
*/
public function setCookie(string $name, string $value): void
{
\$cookieFactory = \$this->getContainer()->make(CookieFactory::class);
\$cookieFactory->queue(\$name, \$value);
}"></code-snippet>
<article-paragraphs>
<p>
The <code>assertCookieValue</code> method verifies that a cookie with the specified name has the expected value. This is useful for ensuring that cookies are set correctly in your application.
</p>
</article-paragraphs>
<code-snippet
gherkin="Then cookie :name should have value :value"
php="
/**
* @Then cookie :name should have value :value
*/
public function assertCookieValue(string $name, string $value): void
{
\$cookieValue = \$this->request->cookies->get(\$name);
Assert::assertEquals(\$value, \$cookieValue, 'Cookie \$name does not have the expected value \$value.');
}"></code-snippet>
<article-paragraphs>
<p>
The <code>deleteCookie</code> method removes a cookie with the specified name. This is useful for testing scenarios where you need to clear cookies.
</p>
</article-paragraphs>
<code-snippet
gherkin="When cookie :name is deleted"
php="
/**
* @When cookie :name is deleted
* @When cookie :name is removed
* @When cookie :name is cleared
*/
public function deleteCookie(string \$name): void
{
\$cookieFactory = \$this->getContainer()->make(CookieFactory::class);
\$cookieFactory->queue(\$cookieFactory->forget(\$name));
}"></code-snippet>
<article-paragraphs>
<p>
The <code>assertCookieNotExists</code> method verifies that a cookie with the specified name does not exist. This is useful for ensuring that cookies are properly deleted or not set.
</p>
</article-paragraphs>
<code-snippet
gherkin="Then the cookie :name should be missing"
php="
/**
* @Then the cookie :name should be missing
* @Then the cookie named :name should not be present
*/
public function assertCookieNotExists(string \$name): void
{
\$cookieValue = \$this->request->cookies->get(\$name);
Assert::assertNull(\$cookieValue, 'Cookie \$name should not exist.');
}"></code-snippet>
<article-paragraphs>
<p>
The <code>assertCookiesExist</code> method verifies that multiple cookies with specified names and values are present. This is useful for checking the state of several cookies in your application.
</p>
</article-paragraphs>
<code-snippet
gherkin="Then the following cookies should be present:
| name | value |
| foo | bar |"
php="
/**
* @Then the following cookies should be present:
* @Then the cookies should be set to:
*/
public function assertCookiesExist(TableNode \$table): void
{
foreach (\$table as \$row) {
\$cookieValue = \$this->request->cookies->get(\$row['name']);
Assert::assertEquals(\$row['value'], \$cookieValue, 'Cookie {\$row['name']} does not have the expected value {\$row['value']}.');
}
}"></code-snippet>
56 changes: 56 additions & 0 deletions docs/elements/hooks.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<section-header>Hooks</section-header>

<article-paragraphs>
<p>Hooks are special methods that run at specified points in your test suite's lifecycle. They allow you to execute
code before and after certain events, providing a powerful mechanism to manage your test environment and ensure
consistency across your tests.</p>

<section-header>
Reboot after feature
</section-header>
<p>The <code class="text-sky-600">Blumilk\BLT\Features\Hooks\RebootAfterFeature</code> hook is designed to ensure that the system under test is reset to a clean state after each
feature is executed. </p>
<code-block>
/**
* @afterFeature
*/
public static function rebootAfterFeature(): void
{
$bootstrapper = static::getRebootAfterFeatureBootstrapper();
$bootstrapper->boot();
}
</code-block>

<section-header>
Refresh database before scenario
</section-header>
<p>
The <code class="text-sky-600">Blumilk\BLT\Features\Hooks\RefreshDatabaseBeforeScenario</code> hook is designed to reset the database to a known state before each scenario
is executed. This ensures that each test scenario runs with a fresh and consistent database, which is crucial
for maintaining the integrity and reliability of your test results.
</p>
<code-block>
public function refreshDatabaseBeforeScenario(): void
{
$this->refreshDatabase();
}
</code-block>

<p class="font-semibold">To use hooks simply include them in your feature context</p>

<code-block>
use Blumilk\BLT\Features\Hooks\RefreshDatabaseBeforeScenario;

class FeatureContext extends Toolbox implements Context
{
use RefreshDatabaseBeforeScenario;

public function __construct()
{
$bootstrapper = new LaravelBootstrapper();
$bootstrapper->boot();
}
}
</code-block>

</article-paragraphs>
16 changes: 15 additions & 1 deletion docs/elements/http.html
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@
/**
* @Then the response should contain JSON:
*/
public function aResponseShouldContainJson(TableNode $table): void"></code-snippet>
public function aResponseShouldContainJsonFragment(TableNode $table): void"></code-snippet>

<article-paragraphs>
<p>
Expand Down Expand Up @@ -403,6 +403,20 @@
*/
public function aResponseShouldHaveHeaderEqualTo(string $header, string $value): void"></code-snippet>

<article-paragraphs>
<p>
The <code>aResponseShouldHaveStatus</code> method verifies that the response status is equal to desired one. This is
useful for ensuring that the request has desired code.
</p>
</article-paragraphs>

<code-snippet
gherkin="Then the response should have status 200"
php="
/**
* @hen the response should have status :code
*/
public function aResponseShouldHaveStatus(): void"></code-snippet>

<article-paragraphs>
<p>
Expand Down
Loading
Loading