Installation:
composer require --dev ezsystems/behatbundle --no-scripts --no-plugins
composer sync-recipes ezsystems/behatbundle --force -v
Ensure your project uses Ibexa DXP (formerly eZ Platform) as a dependency.
Configure behat.yml:
default:
suites:
default:
contexts:
- Ibexa\BehatBundle\Context\FeatureContext
- Ibexa\BehatBundle\Context\ContentContext
- Ibexa\BehatBundle\Context\UiContext
filters:
tags: "@wip"
First Test Case:
Create a feature file (e.g., features/login.feature):
Feature: User login
Scenario: Successful login
Given I am on the login page
When I fill in "email" with "user@example.com"
And I fill in "password" with "password123"
And I press "Login"
Then I should see "Welcome"
Run Tests:
vendor/bin/behat
Test a content creation workflow in Ibexa DXP:
Feature: Create a content item
Scenario: Publish an article
Given I am logged in as "admin"
When I create a content item of type "article"
And I fill in "title" with "My Article"
And I press "Save and Publish"
Then I should see "My Article" in the content list
SiteAccess Management:
Use Ibexa\BehatBundle\Context\SiteContext to switch between siteaccesses:
Given I switch to siteaccess "admin"
Content Operations:
Leverage ContentContext for CRUD operations:
When I create a content item of type "article" under "/1/2"
And I update its field "intro" with "Updated intro"
UI Testing:
Use UiContext for frontend interactions:
When I click on "Edit" link for content item "My Article"
Then I should see "Edit Article" in the title
Authentication:
Test user flows with UserContext:
Given I am logged in as "editor" with password "password"
Custom Contexts: Extend existing contexts (e.g., FeatureContext) for domain-specific logic:
namespace App\Behat\Context;
use Ibexa\BehatBundle\Context\FeatureContext;
class CustomFeatureContext extends FeatureContext
{
public function assertCustomBehavior()
{
// Custom assertions
}
}
Register in behat.yml:
contexts:
- App\Behat\Context\CustomFeatureContext
Data Fixtures: Use Ibexa\BehatBundle\Context\DataContext to load fixtures:
Given I load fixtures from "path/to/fixtures.yml"
API Testing: Combine with HttpContext for API endpoints:
When I send a GET request to "/api/content"
Then the response status code should be 200
Parallel Testing: Configure Behat’s --tags and --group flags for parallel execution:
vendor/bin/behat --tags "@smoke" --group "content"
SiteAccess Configuration:
config/siteaccesses.yml is properly set up. Missing siteaccesses will cause SiteContext failures.vendor/bin/ibexa:siteaccess:list
Context Loading Order:
behat.yml:
contexts:
- Ibexa\BehatBundle\Context\FeatureContext
- Ibexa\BehatBundle\Context\ContentContext # Depends on FeatureContext
Database Transactions:
@noTransaction tag for tests requiring DB persistence:
@noTransaction
Scenario: Test with persistent data
Deprecated Commands:
ezplatform:behat:init are deprecated. Use ibexa:behat:init (v9.0+).Allure Reports:
behat-html-formatter.Enable Verbose Output:
vendor/bin/behat -v
Step Definitions:
Override steps in FeatureContext for debugging:
public function iCreateAContentItemOfType($type, $location = null)
{
try {
return parent::iCreateAContentItemOfType($type, $location);
} catch (\Exception $e) {
throw new \Exception("Failed to create content: " . $e->getMessage());
}
}
Screenshot on Failure:
Configure behat.yml to capture screenshots:
extensions:
Behat\MinkExtension:
screenshots_directory: tests/_output/screenshots
show_cmd: open
Custom Step Definitions:
Extend FeatureContext or create new contexts:
namespace App\Behat\Context;
use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
class HookContext implements Context
{
/**
* @BeforeScenario
*/
public static function beforeScenario(BeforeScenarioScope $scope)
{
// Setup logic (e.g., clear cache)
}
}
Environment-Specific Config:
Use behat.yml environment variables:
default:
extensions:
Behat\MinkExtension:
base_url: "%env(BEHAT_BASE_URL)%"
Custom Fixtures: Load fixtures dynamically:
use Ibexa\BehatBundle\Context\DataContext;
class CustomDataContext extends DataContext
{
public function loadCustomFixtures($path)
{
$this->loadFixturesFromYaml($path);
}
}
Hooks for Setup/Teardown: Use Behat hooks for test lifecycle management:
/**
* @BeforeScenario
*/
public function clearCache()
{
$this->getContainer()->get('ezpublish.cache_manager')->clearAll();
}
SiteAccess Auto-Detection:
The bundle auto-detects siteaccesses from config/siteaccesses.yml. Override with:
Ibexa\BehatBundle\Context\SiteContext:
siteaccess: "custom_siteaccess"
Content Type Limitations: Ensure content types exist in the test environment. Use:
Given I load content type "article" from "config/contenttypes/article.yml"
Locale Handling:
Set default locale in behat.yml:
Ibexa\BehatBundle\Context\LocaleContext:
default_locale: "eng-GB"
How can I help you explore Laravel packages today?