Comments (8)
I don't think this will be easy to do, because Behat does not run inside your Symfony application (and the code being tested with Behat might not be a Symfony application at all).
Maybe https://github.com/FriendsOfBehat/SymfonyExtension could have a way to make it work.
from behat.
I poked around the code a bit to find the new calls, but my event listener isn't being called.
<?php
namespace App\EventListener;
use Behat\Testwork\Event\Event;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Behat\Behat\EventDispatcher\Event\StepTested;
final class BehatListener
{
#[AsEventListener(event: StepTested::BEFORE)]
public function onBeforeStepTested(Event $event): void
{
dd($event);
// ...
}
}
The listener seems like it's registered correctly, here's the debug:
"tester.step_tested.before" event
---------------------------------
------- ------------------------------------------------------- ----------
Order Callable Priority
------- ------------------------------------------------------- ----------
#1 App\EventListener\BehatListener::onBeforeStepTested() 0
------- ------------------------------------------------------- ----------
from behat.
I think I need to implement / extend EventDispatchingStepTester in the FeatureContext.
But EventDispatchingBackgroundTester is marked as final, so it can't be extended.
class FeatureContext extends EventDispatchingBackgroundTester implements Context, BackgroundTester
{
So there must be some other way to wire this up! @everzet? I'll make a PR to the docs once this works.
from behat.
Behat events are not dispatched in the event dispatcher of your Symfony app (which is where you register your listener right now).
See https://docs.behat.org/en/latest/user_guide/context/hooks.html for the documentation about hooks in 3.x
from behat.
making the context implement BackgroundTester does not make sense at all.
from behat.
Thanks!
Certainly I'd love to hook it into the Symfony events, and then inject the services I need there. Is there a way to inject the Symfony event dispatcher and dispatch a Symfony event?
I have a custom logger that logs the steps and scenarios, and renders that log via Twig (and needs some other services). I'm open to suggestions on how to implement that, especially inside a bundle so it can be reused.
from behat.
anyway, as this issue was originally asking for documentation and that documentation exists already (see my first comment), I'm closing this issue.
from behat.
Thanks, @stof
from behat.
Related Issues (20)
- SSL certificate problem: unable to get local issuer certificate HOT 3
- Symfony 7 support HOT 1
- [bug] jUnit formatter returns time as int but should use float HOT 1
- [Bug] jUnit formatter produces empty testsuite names, it could use feature file as suite name HOT 5
- Parallelization of tests HOT 4
- SigintController does not check for both pcntl-functions used in execute() HOT 6
- [Bug?] Reruns of Scenario outlines lead to potentially confusing scenario names HOT 2
- Exception thrown when test fails with junit formatter HOT 1
- Add support for Rule keyword (Gherkin 6) HOT 2
- Skip or improve translation process
- how to have a context/class per feature ?
- New release for Symfony 7 HOT 8
- Can't use %paths.base% inside extensions: Failed opening required '%paths.base%' HOT 2
- phar is broken for the 3.14.0 release HOT 4
- Extension for auto naming parameters HOT 2
- Better documentation for `filters` key
- Is behat dead? HOT 7
- Progress vs pretty output -- Progress is WAY slower! HOT 4
- getScenario() has to return a Scenario but returns an ExampleNode so the getTitle() function didn't works as expected HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from behat.