Skip to content

Commit

Permalink
remove parentheses on invocations
Browse files Browse the repository at this point in the history
  • Loading branch information
loic425 committed Dec 9, 2024
1 parent 8d5a59c commit 837272b
Showing 1 changed file with 44 additions and 32 deletions.
76 changes: 44 additions & 32 deletions user_guide/configuration/suites.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,47 @@ really powerful and ``behat.yml`` makes them that much more powerful:
use Behat\Config\Profile;
use Behat\Config\Suite;
$profile = (new Profile('default'))
$profile = new Profile('default')
->withSuite(
(new Suite('core_features'))
new Suite('core_features')
->withPaths('%paths.base%/features/core')
->withContexts(CoreDomainContext::class)
)
->withSuite(
(new Suite('user_features'))
new Suite('user_features')
->withFilter(new RoleFilter('user'))
->withPaths('%paths.base%/features/web')
->withContexts(UserContext::class)
)
->withSuite(
(new Suite('admin_features'))
new Suite('admin_features')
->withFilter(new RoleFilter('admin'))
->withPaths('%paths.base%/features/web')
->withContexts(AdminContext::class)
)
;
return (new Config())
return new Config()
->withProfile($profile)
;
.. note::

On PHP < 8.4, you need to wrap new invocations with parentheses before calling config object methods.

.. code-block:: php
// ...
// $profile = new Profile('default')
$profile = (new Profile('default'))
->withSuite(
// new Suite('core_features')
(new Suite('core_features'))
->withPaths('%paths.base%/features/core')
->withContexts(CoreDomainContext::class)
)
// ...
Suite Paths
-----------

Expand All @@ -62,9 +79,9 @@ configuration:
use Behat\Config\Profile;
use Behat\Config\Suite;
$profile = (new Profile('default'))
$profile = new Profile('default')
->withSuite(
(new Suite('core_features'))
new Suite('core_features')
->withPaths(
'%paths.base%/features',
'%paths.base%/test/features',
Expand All @@ -91,15 +108,15 @@ You could, for example, tell Behat to look into the
use Behat\Config\Profile;
use Behat\Config\Suite;
$profile = (new Profile('default'))
$profile = new Profile('default')
->withSuite(
(new Suite('web_features'))
new Suite('web_features')
->withPaths('%paths.base%/features/web')
->withContexts(WebContext::class)
)
;
return (new Config())
return new Config()
->withProfile($profile)
;
Expand All @@ -117,20 +134,20 @@ You then might want to also describe some API-specific features in
use Behat\Config\Profile;
use Behat\Config\Suite;
$profile = (new Profile('default'))
$profile = new Profile('default')
->withSuite(
(new Suite('web_features'))
new Suite('web_features')
->withPaths('%paths.base%/features/web')
->withContexts(WebContext::class)
)
->withSuite(
(new Suite('api_features'))
new Suite('api_features')
->withPaths('%paths.base%/features/api')
->withContexts(ApiContext::class)
)
;
return (new Config())
return new Config()
->withProfile($profile)
;
Expand Down Expand Up @@ -173,30 +190,25 @@ features with specific tag (or name) in specific contexts:
use Behat\Config\Profile;
use Behat\Config\Suite;
$profile = (new Profile('default'))
$profile = new Profile('default')
->withSuite(
(new Suite('web_features'))
new Suite('web_features')
->withFilter(new TagFilter('@web'))
->withPaths('%paths.base%/features')
->withContexts(WebContext::class)
)
->withSuite(
(new Suite('api_features'))
new Suite('api_features')
->withFilter(new TagFilter('@api'))
->withPaths('%paths.base%/features')
->withContexts(ApiContext::class)
)
;
return (new Config())
return new Config()
->withProfile($profile)
;
.. note::

The ``@`` character is a special and requires the tag to be
put in quotes.

This configuration will tell Behat to run features and scenarios
tagged as ``@web`` in ``WebContext`` and features and scenarios
tagged as ``@api`` in ``ApiContext``. Even if they all are stored
Expand All @@ -216,15 +228,15 @@ filter. That means, you can now have nice actor-based suites:
use Behat\Config\Profile;
use Behat\Config\Suite;
$profile = (new Profile('default'))
$profile = new Profile('default')
->withSuite(
(new Suite('user_features'))
new Suite('user_features')
->withFilter(new RoleFilter('user'))
->withPaths('%paths.base%/features')
->withContexts(UserContext::class)
)
->withSuite(
(new Suite('api_features'))
new Suite('api_features')
->withFilter(new RoleFilter('admin'))
->withPaths('%paths.base%/features')
->withContexts(AdminContext::class)
Expand Down Expand Up @@ -267,11 +279,11 @@ This is achieved by specifying the filter in the gherkin configuration:
use Behat\Config\Filter\TagFilter;
use Behat\Config\Profile;
$profile = (new Profile('default'))
$profile = new Profile('default')
->withFilter(new TagFilter('~@wip'))
;
return (new Config())
return new Config()
->withProfile($profile)
;
Expand Down Expand Up @@ -309,21 +321,21 @@ develop different layers of your application with Behat:
use Behat\Config\Profile;
use Behat\Config\Suite;
$profile = (new Profile('default'))
$profile = new Profile('default')
->withSuite(
(new Suite('domain_features'))
new Suite('domain_features')
->withPaths('%paths.base%/features')
->withContexts(DomainContext::class)
)
->withSuite(
(new Suite('web_features'))
new Suite('web_features')
->withFilter(new TagFilter('@web'))
->withPaths('%paths.base%/features')
->withContexts(WebContext::class)
)
;
return (new Config())
return new Config()
->withProfile($profile)
;
Expand Down

0 comments on commit 837272b

Please sign in to comment.