pavlakis / slim-behat-extension
Slim 3 extension for Behat
Installs: 9 630
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 2
Forks: 2
Open Issues: 0
Type:behat-extension
Requires
- php: >=5.4
- behat/behat: ~3.0
- behat/mink-browserkit-driver: ~1.2
- symfony/http-kernel: ^3.0
Requires (Dev)
- behat/mink-extension: ~2.0
- phpspec/phpspec: ~2.1
- slim/slim: ^3.0
- symfony/symfony: ~2.6
This package is auto-updated.
Last update: 2024-10-15 01:54:01 UTC
README
This extension was written based on the Behat Laravel Extension
Can install it with composer through packagist
composer require --dev pavlakis/slim-behat-extension
On your behat.yml file add the extension within the extensions section
Pavlakis\Slim\Behat: ~
The above is the minimum setup as long as you are using Akrabat's Slim 3 Skeleton with the default location for settings.php
at app/settings.php
and behat.yml
inside tests/behat
.
This is the expected directory structure for the default configuration:
- my_app_dir
|___ app
|_______ settings.php
|_______ dependencies.php
|___ tests
|_________ behat
|_____ behat.yml
If behat.yml
is in the root folder, use the following:
default: suites: default: contexts: - FeatureContext extensions: Pavlakis\Slim\Behat: config_file: app/settings.php dependencies_file: app/dependencies.php
Apart from the config (settings.php) all other parameters are optional, however you can also pass:
config_file: ../../app/configs/settings_test.php
dependencies_file: ../../app/dependencies.php
middleware_file: ../../middleware.php
routes_file: ../../routes.php
In your FeatureContext file
- Include the KernelAwareContext interface
- Include the Pavlakis\Slim\Behat\Context\App trait
- Access the Slim 3 app using
$this->app
Feature Context example
Use the logger
to log some text to ensure the extension works.
FeatureContext.php
<?php use Behat\Behat\Tester\Exception\PendingException; use Behat\Behat\Context\Context; use Behat\Gherkin\Node\PyStringNode; use Behat\Gherkin\Node\TableNode; use Pavlakis\Slim\Behat\Context\App; use Pavlakis\Slim\Behat\Context\KernelAwareContext; class FeatureContext implements Context, KernelAwareContext { use App; /** * @Then it works */ public function itWorks() { /** @var \Psr\Log\LoggerInterface $logger */ $logger = $this->app->getContainer()->get('logger'); $logger->info("Slim-behat integration works!"); } /** * @Given I load the slim-behat extension */ public function iLoadTheSlimBehatExtension() { } }
test.feature
Feature: The extension works In order to see this extension works As a developer I need to be see something happening Scenario: The extension works Given I load the slim-behat extension Then it works
Feature Context example using Mink
use Behat\Behat\Context\Context; use Behat\MinkExtension\Context\MinkContext; use Pavlakis\Slim\Behat\Context\App; use Pavlakis\Slim\Behat\Context\KernelAwareContext; /** * Defines application features from the specific context. */ class FeatureContext extends MinkContext implements Context, KernelAwareContext { use App; }
Accessing your dependencies
$this->app->getContainer()