Skip to content

Commit

Permalink
Merge pull request #60 from damien-louis/behat
Browse files Browse the repository at this point in the history
Reinstall Behat
  • Loading branch information
damien-louis authored Jan 13, 2024
2 parents 66ab94c + 9992e99 commit 464bb6a
Show file tree
Hide file tree
Showing 6 changed files with 341 additions and 1 deletion.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ php-cs-fixer-apply: ## Execute php-cs-fixer and apply changes
.PHONY: tests
tests: ## Execute tests
$(APP) vendor/bin/simple-phpunit --configuration ./tests/phpunit.xml.dist --colors=always --testdox
$(APP) vendor/bin/behat --config ./tests/behat.yml

##
## —— ✨ Others ——
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"symfony/yaml": "^7.0"
},
"require-dev": {
"friends-of-behat/symfony-extension": "^2.0",
"friendsofphp/php-cs-fixer": "^3.37",
"nunomaduro/phpinsights": "^2.8",
"phpstan/extension-installer": "^1.2",
Expand Down
269 changes: 268 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions tests/Behat/DemoContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace App\Tests\Behat;

use Behat\Behat\Context\Context;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\KernelInterface;

/**
* This context class contains the definitions of the steps used by the demo
* features file. Learn how to get started with Behat and BDD on Behat's website.
*
* @see http://behat.org/en/latest/quick_start.html
*/
final class DemoContext implements Context
{
/** @var KernelInterface */
private $kernel;

/** @var Response|null */
private $response;

public function __construct(KernelInterface $kernel)
{
$this->kernel = $kernel;
}

/**
* @When a demo scenario sends a request to :path
*/
public function aDemoScenarioSendsARequestTo(string $path): void
{
$this->response = $this->kernel->handle(Request::create($path, 'GET'));
}

/**
* @Then the response should be received
*/
public function theResponseShouldBeReceived(): void
{
if ($this->response === null) {
throw new \RuntimeException('No response received');
}
}
}
12 changes: 12 additions & 0 deletions tests/Behat/features/demo.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file contains a user story for demonstration only.
# Learn how to get started with Behat and BDD on Behat's website:
# http://behat.org/en/latest/quick_start.html

Feature:
In order to prove that the Behat Symfony extension is correctly installed
As a user
I want to have a demo scenario

Scenario: It receives a response from Symfony's kernel
When a demo scenario sends a request to "/"
Then the response should be received
11 changes: 11 additions & 0 deletions tests/behat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
default:
suites:
default:
paths:
features: tests/Behat/features
contexts:
- App\Tests\Behat\DemoContext

extensions:
FriendsOfBehat\SymfonyExtension:
bootstrap: 'tests/bootstrap.php'

0 comments on commit 464bb6a

Please sign in to comment.