Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/features export-ignore
/.github export-ignore

/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/behat.yml.dist export-ignore
/behat.dist.php export-ignore
36 changes: 26 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,34 @@ on:
release:
types: [created]
schedule:
-
cron: "0 1 * * 6" # Run at 1am every Saturday
- cron: "0 1 * * 6" # Run at 1am every Saturday

jobs:
tests:
runs-on: ubuntu-20.04
name: "PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}"
runs-on: ubuntu-latest
name: "PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, Behat ${{ matrix.behat }}, ${{ matrix.dependencies }} deps"
strategy:
fail-fast: false
matrix:
php: ["8.1", "8.2", "8.3"]
symfony: ["^5.4", "^6.4", "7.0"]
symfony: ["^5.4", "^6.4", "^7.4"]
behat: ["^3.8"]
dependencies: ["lowest", "highest"]
exclude:
- php: "8.1"
symfony: "7.0"
- symfony: "^7.4"
php: "8.1"
include:
- php: "8.3"
symfony: "^7.4"
behat: "4.x-dev"
dependencies: "highest"
- php: "8.4"
symfony: "^8.0"
behat: "4.x-dev"
dependencies: "highest"

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -34,14 +44,20 @@ jobs:
- name: Restrict Symfony version
if: matrix.symfony != ''
run: |
composer global require --no-progress --no-scripts --no-plugins "symfony/flex"
composer global config --no-plugins allow-plugins.symfony/flex true
composer global require --no-progress --no-scripts --no-plugins "symfony/flex:^1.11"
composer config extra.symfony.require "${{ matrix.symfony }}"
composer config minimum-stability "dev"
composer config prefer-stable true

- name: Restrict Behat version
run: composer require --no-update "behat/behat:${{ matrix.behat }}"

- name: Install dependencies
run: composer update
run: composer update ${{ matrix.dependencies == 'lowest' && '--prefer-lowest --prefer-stable' || '' }}

- name: Run analysis
if: matrix.behat != '4.x-dev'
run: composer validate --strict

- name: Run tests
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2016-2021 Łukasz Chruściel
Copyright (c) 2016-present Łukasz Chruściel

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
18 changes: 18 additions & 0 deletions behat.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

use Behat\Config\Config;
use Behat\Config\Profile;
use Behat\Config\Suite;
use FriendsOfBehat\TestContext\Context\TestContext;

return (new Config())
->withProfile(
(new Profile('default'))
->withSuite(
(new Suite('default'))
->withPaths(__DIR__ . '/features/attributes')
->withContexts(TestContext::class)
)
);
2 changes: 2 additions & 0 deletions behat.yml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
default:
suites:
default:
paths:
- '%paths.base%/features/annotations'
contexts:
- FriendsOfBehat\TestContext\Context\TestContext
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
],
"require": {
"php": "^8.1",
"behat/behat": "^3.8",
"symfony/dependency-injection": "^5.4 || ^6.4 || ^7.0"
"behat/behat": "^3.8 || ^4.0",
"symfony/dependency-injection": "^5.4 || ^6.4 || ^7.4 || ^8.0"
},
"require-dev": {
"friends-of-behat/test-context": "^1.0"
"friends-of-behat/test-context": "^1.4"
},
"extra": {
"branch-alias": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
Feature: Transforming variadic arguments in step definitions
In order to make Behat steps definitions cleaner and more readable
As a Behat User
I want to have transformed variadic arguments in these

Background:
Given a Behat configuration containing:
"""
default:
extensions:
FriendsOfBehat\VariadicExtension: ~
"""
And a context file "features/bootstrap/FeatureContext.php" containing:
"""
<?php

use Behat\Behat\Context\Context;
use Behat\Hook\BeforeScenario;
use Behat\Step\When;
use Behat\Transformation\Transform;

class FeatureContext implements Context
{
#[Transform('/^(\w+)$/')]
public function transform($string)
{
return strtoupper($string);
}

#[When('/^I pass "(\w+)" and "(\w+)" as arguments$/')]
#[When('I pass :firstArgument, :secondArgument and :thirdArgument')]
public function iPass(...$arguments)
{
printf('Arguments: %s', join(', ', $arguments));
}
}
"""

Scenario: Transforming variadic arguments in step definitions with a regex
Given a feature file "features/variadic_arguments_support.feature" containing:
"""
Feature: Transforming variadic arguments in step definitions

Scenario: Transforming variadic arguments in step definitions
When I pass "foo" and "bar" as arguments
"""
When I run Behat
Then it should pass with "Arguments: FOO, BAR"

Scenario: Transforming variadic arguments in step definitions without regex
Given a feature file "features/variadic_arguments_support.feature" containing:
"""
Feature: Transforming variadic arguments in step definitions

Scenario: Transforming variadic arguments in step definitions
When I pass "one", "two" and "three"
"""
When I run Behat
Then it should pass with "Arguments: ONE, TWO, THREE"
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
Feature: Using variadic arguments in steps definitions with named parameters
In order to make Behat steps definitions cleaner and more readable
As a Behat User
I want to use variadic arguments in these

Background:
Given a Behat configuration containing:
"""
default:
extensions:
FriendsOfBehat\VariadicExtension: ~
"""
And a context file "features/bootstrap/FeatureContext.php" containing:
"""
<?php

use Behat\Behat\Context\Context;
use Behat\Step\When;

class FeatureContext implements Context
{
#[When('I pass :firstArgument and :secondArgument as arguments')]
#[When('I pass :firstArgument, :secondArgument and :thirdArgument as arguments')]
public function iPass(...$arguments)
{
printf('Number of passed arguments: %d', count($arguments));
}

#[When('I pass :firstArgument and :secondArgument as arguments to :subject')]
public function iPassToSubject($subject, ...$arguments)
{
printf('Number of arguments passed to %s: %d', $subject, count($arguments));
}
}
"""

Scenario: Using two variadic arguments as the only ones
Given a feature file "features/variadics_arguments_support.feature" containing:
"""
Feature: Passing arguments

Scenario: Passing two arguments
When I pass "foo" and "bar" as arguments
"""
When I run Behat
Then it should pass with "Number of passed arguments: 2"

Scenario: Using three variadic arguments as the only ones
Given a feature file "features/variadics_arguments_support.feature" containing:
"""
Feature: Passing arguments

Scenario: Passing three arguments
When I pass "foo", "bar" and "baz" as arguments
"""
When I run Behat
Then it should pass with "Number of passed arguments: 3"

Scenario: Using variadic arguments together with regular one
Given a feature file "features/variadics_arguments_support.feature" containing:
"""
Feature: Passing two variadic arguments and one regular argument

Scenario: Passing two variadic arguments and one regular argument
When I pass "foo" and "bar" as arguments to method

"""
When I run Behat
Then it should pass with "Number of arguments passed to method: 2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Feature: Using variadic arguments in Behat steps definitions with not named parameters
In order to make Behat steps definitions cleaner and more readable
As a Behat User
I want to use variadic arguments in these

Background:
Given a Behat configuration containing:
"""
default:
extensions:
FriendsOfBehat\VariadicExtension: ~
"""
And a context file "features/bootstrap/FeatureContext.php" containing:
"""
<?php

use Behat\Behat\Context\Context;
use Behat\Step\When;

class FeatureContext implements Context
{
#[When('/^I pass "(\w+)" and "(\w+)" as arguments$/')]
#[When('/^I pass "(\w+)", "(\w+)" and "(\w+)" as arguments$/')]
public function iPass(...$arguments)
{
printf('Number of passed arguments: %d', count($arguments));
}
}
"""

Scenario: Using two variadic arguments as the only ones
Given a feature file "features/variadic_arguments_support.feature" containing:
"""
Feature: Passing arguments

Scenario: Passing two arguments
When I pass "foo" and "bar" as arguments
"""
When I run Behat
Then it should pass with "Number of passed arguments: 2"

Scenario: Using three variadic arguments as the only ones
Given a feature file "features/variadic_arguments_support.feature" containing:
"""
Feature: Passing arguments

Scenario: Passing three arguments
When I pass "foo", "bar" and "baz" as arguments
"""
When I run Behat
Then it should pass with "Number of passed arguments: 3"
17 changes: 2 additions & 15 deletions src/Argument/VariadicArgumentOrganiser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,18 @@
namespace FriendsOfBehat\VariadicExtension\Argument;

use Behat\Testwork\Argument\ArgumentOrganiser;
use ReflectionFunctionAbstract;

/**
* Decorates a default argument organiser to support a variadic arguments also.
* It will add all unused arguments to the end of argument list.
*/
final class VariadicArgumentOrganiser implements ArgumentOrganiser
{
/**
* @var ArgumentOrganiser
*/
private $decoratedArgumentOrganiser;

/**
* @param ArgumentOrganiser $decoratedArgumentOrganiser
*/
public function __construct(ArgumentOrganiser $decoratedArgumentOrganiser)
public function __construct(private ArgumentOrganiser $decoratedArgumentOrganiser)
{
$this->decoratedArgumentOrganiser = $decoratedArgumentOrganiser;
}

/**
* {@inheritdoc}
*/
public function organiseArguments(ReflectionFunctionAbstract $function, array $arguments): array
public function organiseArguments(\ReflectionFunctionAbstract $function, array $arguments): array
{
$organisedArguments = $this->decoratedArgumentOrganiser->organiseArguments($function, $arguments);

Expand Down
15 changes: 0 additions & 15 deletions src/ServiceContainer/VariadicExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,19 @@

final class VariadicExtension implements Extension
{
/**
* {@inheritdoc}
*/
public function getConfigKey(): string
{
return 'fob_variadic';
}

/**
* {@inheritdoc}
*/
public function initialize(ExtensionManager $extensionManager): void
{
}

/**
* {@inheritdoc}
*/
public function configure(ArrayNodeDefinition $builder): void
{
}

/**
* {@inheritdoc}
*/
public function load(ContainerBuilder $container, array $config): void
{
$definition = new Definition(VariadicArgumentOrganiser::class, [
Expand All @@ -59,9 +47,6 @@ public function load(ContainerBuilder $container, array $config): void
$container->setDefinition('fob_variadic.argument.mixed_organiser', $definition);
}

/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container): void
{
}
Expand Down