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

#18 - add session tools #40

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Changes from all 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
101 changes: 101 additions & 0 deletions src/Features/Traits/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,105 @@ public function aSessionFlashesNoErrors(): void
$errors = $this->getContainer()->get("session")->all()["errors"] ?? [];
Assert::assertSameSize([], $errors);
}

/**
* @Given the session has the following data:
*/
public function theSessionHasTheFollowingData(TableNode $table): void
{
$session = $this->getContainer()->get("session");

foreach ($table->getHash() as $row) {
$session->put($row["key"], $row["value"]);
}
}

/**
* @Then the session should have the following data:
*/
public function theSessionShouldHaveTheFollowingData(TableNode $table): void
{
$session = $this->getContainer()->get("session");

foreach ($table->getHash() as $row) {
Assert::assertEquals($row["value"], $session->get($row["key"]));
}
}

/**
* @Given the session is revoked
*/
public function theSessionIsRevoked(): void
{
$this->getContainer()->get("session")->invalidate();
}

/**
* @Given the session has no data
*/
public function theSessionHasNoData(): void
{
$session = $this->getContainer()->get("session");
$session->flush();
}

/**
* @Given the session flashes the following data:
*/
public function theSessionFlashesTheFollowingData(TableNode $table): void
{
$session = $this->getContainer()->get("session");

foreach ($table->getHash() as $row) {
$session->flash($row["key"], $row["value"]);
}
}

/**
* @Then the session should flash the following data:
*/
public function theSessionShouldFlashTheFollowingData(TableNode $table): void
{
$session = $this->getContainer()->get("session");

foreach ($table->getHash() as $row) {
Assert::assertEquals($row["value"], $session->get($row["key"]));
}
}

/**
* @Then the session should have key :key
*/
public function theSessionShouldHaveKey(string $key): void
{
$session = $this->getContainer()->get("session");
Assert::assertTrue($session->has($key));
}

/**
* @Then the session should not have key :key
*/
public function theSessionShouldNotHaveKey(string $key): void
{
$session = $this->getContainer()->get("session");
Assert::assertFalse($session->has($key));
}

/**
* @Then the session should have key :key with value :value
*/
public function theSessionShouldHaveKeyWithValue(string $key, string $value): void
{
$session = $this->getContainer()->get("session");
Assert::assertEquals($value, $session->get($key));
}

/**
* @Given the session forgets the key :key
*/
public function theSessionForgetsKey(string $key): void
{
$session = $this->getContainer()->get("session");
$session->forget($key);
}
}
Loading